qLibc
|
Token Bucket implementation. More...
Go to the source code of this file.
Functions | |
void | qtokenbucket_init (qtokenbucket_t *bucket, int init_tokens, int max_tokens, int tokens_per_sec) |
Initialize the token bucket. | |
bool | qtokenbucket_consume (qtokenbucket_t *bucket, int tokens) |
Consume tokens from the bucket. | |
long | qtokenbucket_waittime (qtokenbucket_t *bucket, int tokens) |
Get the estimate time until given number of token is ready. | |
Token Bucket implementation.
Current implementation is not thread-safe.
More information about token-bucket: http://en.wikipedia.org/wiki/Token_bucket
Definition in file qtokenbucket.c.
void qtokenbucket_init | ( | qtokenbucket_t * | bucket, |
int | init_tokens, | ||
int | max_tokens, | ||
int | tokens_per_sec | ||
) |
Initialize the token bucket.
init_tokens | the initial number of tokens. |
max_tokens | maximum number of tokens in the bucket. |
tokens_per_sec | number of tokens to fill per a second. |
Definition at line 76 of file qtokenbucket.c.
bool qtokenbucket_consume | ( | qtokenbucket_t * | bucket, |
int | tokens | ||
) |
Consume tokens from the bucket.
bucket | tockenbucket object. |
tokens | number of tokens to request. |
Definition at line 93 of file qtokenbucket.c.
long qtokenbucket_waittime | ( | qtokenbucket_t * | bucket, |
int | tokens | ||
) |
Get the estimate time until given number of token is ready.
tokens | number of tokens |
Definition at line 109 of file qtokenbucket.c.