diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-04-13 12:03:29 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-04-13 16:31:47 -0400 |
commit | 003e6595bf355fd13f85eb31e7850cec086ecd07 (patch) | |
tree | 863d49e61461037271d128f285e19b4a0fa096c4 /src/common/token_bucket.c | |
parent | 2307bef7a2403a48d57e3e352d8befcd8c9f482e (diff) | |
download | tor-003e6595bf355fd13f85eb31e7850cec086ecd07.tar.gz tor-003e6595bf355fd13f85eb31e7850cec086ecd07.zip |
Refactor "timestamp" not to be its own type coupled to token buffers
Really, the uint32_t is only an optimization; any kind of unit
should work fine. Some users might want to use time_t or
monotime_coarse_t or something like that.
Diffstat (limited to 'src/common/token_bucket.c')
-rw-r--r-- | src/common/token_bucket.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/common/token_bucket.c b/src/common/token_bucket.c index 8be377599b..7c81264e25 100644 --- a/src/common/token_bucket.c +++ b/src/common/token_bucket.c @@ -48,12 +48,9 @@ token_bucket_cfg_init(token_bucket_cfg_t *cfg, */ void token_bucket_raw_reset(token_bucket_raw_t *bucket, - token_bucket_timestamp_t *stamp, - const token_bucket_cfg_t *cfg, - uint32_t now) + const token_bucket_cfg_t *cfg) { bucket->bucket = cfg->burst; - stamp->last_refilled_at = now; } /** @@ -165,10 +162,9 @@ void token_bucket_rw_reset(token_bucket_rw_t *bucket, uint32_t now_ts) { - token_bucket_raw_reset(&bucket->read_bucket, &bucket->stamp, - &bucket->cfg, now_ts); - token_bucket_raw_reset(&bucket->write_bucket, &bucket->stamp, - &bucket->cfg, now_ts); + token_bucket_raw_reset(&bucket->read_bucket, &bucket->cfg); + token_bucket_raw_reset(&bucket->write_bucket, &bucket->cfg); + bucket->last_refilled_at_timestamp = now_ts; } /** @@ -180,9 +176,10 @@ token_bucket_rw_reset(token_bucket_rw_t *bucket, */ int token_bucket_rw_refill(token_bucket_rw_t *bucket, - uint32_t now_ts) + uint32_t now_ts) { - const uint32_t elapsed_ticks = (now_ts - bucket->stamp.last_refilled_at); + const uint32_t elapsed_ticks = + (now_ts - bucket->last_refilled_at_timestamp); if (elapsed_ticks > UINT32_MAX-(300*1000)) { /* Either about 48 days have passed since the last refill, or the * monotonic clock has somehow moved backwards. (We're looking at you, @@ -208,7 +205,7 @@ token_bucket_rw_refill(token_bucket_rw_t *bucket, &bucket->cfg, elapsed_steps)) flags |= TB_WRITE; - bucket->stamp.last_refilled_at = now_ts; + bucket->last_refilled_at_timestamp = now_ts; return flags; } |