Click
Loading...
Searching...
No Matches
tokenbucket.hh
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2#ifndef CLICK_TOKENBUCKET_HH
3#define CLICK_TOKENBUCKET_HH
4#include <click/timestamp.hh>
5#include <click/bigint.hh>
6CLICK_DECLS
7
57template <typename P> class TokenRateX;
58
59template <typename P>
60class TokenRateX : public P { public:
61
63 typedef P parameter_type;
64
66 typedef typename P::token_type token_type;
67
69 typedef typename P::time_point_type time_point_type;
70
72 typedef typename make_unsigned<typename P::duration_type>::type ticks_type;
73
74 enum {
75 max_tokens = (token_type) -1
76 };
77
80 assign();
81 }
82
85 explicit TokenRateX(bool unlimited) {
87 }
88
99
102 inline void assign(bool unlimited = false);
103
111
113 bool unlimited() const {
114 return _time_until_full == 0;
115 }
116
118 bool idle() const {
119 return _tokens_per_tick == 0;
120 }
121
126 token_type rate() const;
127
133 return max_tokens / _token_scale;
134 }
135
138 return _tokens_per_tick;
139 }
140
143 return _token_scale;
144 }
145
151 return _time_until_full;
152 }
153
158 return P::now();
159 }
160
165 template <typename U>
167 return P::time_point(time);
168 }
169
177 return P::time_monotonic_difference(a, b);
178 }
179
180
182 typedef time_point_type epoch_type CLICK_DEPRECATED;
183 inline token_type tokens_per_epoch() const CLICK_DEPRECATED;
184 inline ticks_type epochs_until_full() const CLICK_DEPRECATED;
187 private:
188
189 token_type _tokens_per_tick; // 0 iff idle()
190 token_type _token_scale;
191 ticks_type _time_until_full; // 0 iff unlimited()
192
193};
194
195template <typename P>
197{
198 _token_scale = 1;
199 if (unlimited) {
200 _tokens_per_tick = max_tokens;
201 _time_until_full = 0;
202 } else {
203 _tokens_per_tick = 0;
204 _time_until_full = (ticks_type) -1;
205 }
206}
207
208template <typename P>
210{
211 if (capacity == 0) {
212 rate = 0;
213 capacity = max_tokens;
214 }
215
216 token_type frequency = P::frequency();
217 if (rate != 0) {
218 // constrain capacity so _tokens_per_tick fits in 1 limb
219 unsigned long long min_capacity = (rate - 1) / frequency + 1;
220 if (capacity < min_capacity)
221 capacity = min_capacity;
222 }
223 _token_scale = max_tokens / capacity;
224
225 // XXX on non-64 bit types
226 static_assert(sizeof(bigint::limb_type) == sizeof(token_type),
227 "bigint::limb_type should have the same size as token_type.");
228 bigint::limb_type l[2] = { 0, 0 };
229 bigint::limb_type a[2] = { rate, 0 };
230 bigint::multiply_add(l, a, 2, _token_scale);
231 (void) bigint::divide(l, l, 2, frequency);
232 assert(l[1] == 0);
233
234 if (rate != 0) {
235 // constrain _tokens_per_tick to be at least 1
236 _tokens_per_tick = (l[0] != 0 ? l[0] : 1);
237 _time_until_full = (max_tokens - 1) / _tokens_per_tick + 1;
238 } else {
239 _tokens_per_tick = 0;
240 _time_until_full = (ticks_type) -1;
241 }
242}
243
244template <typename P>
245typename P::token_type TokenRateX<P>::rate() const
246{
247 static_assert(sizeof(bigint::limb_type) == sizeof(token_type),
248 "bigint::limb_type should have the same size as token_type.");
249 bigint::limb_type l[2] = { _tokens_per_tick / 2, 0 };
250 bigint::limb_type a[2] = { _tokens_per_tick, 0 };
251 bigint::multiply_add(l, a, 2, P::frequency());
252 (void) bigint::divide(l, l, 2, token_scale());
253 return l[1] ? (token_type) max_tokens : l[0];
254}
255
257template <typename P>
259{
260 return tokens_per_tick();
261}
262
263template <typename P>
265{
266 return time_until_full();
267}
272/* TokenRateConverter safely scales token counts according to an input rate.
273 Template specializations let us make use of a fast int_multiply() when one
274 is available. */
275template<typename rate_type, bool FM> struct TokenRateConverter {
276};
277template<typename rate_type> struct TokenRateConverter<rate_type, true> {
278 static bool cvt(const rate_type &rate, typename rate_type::token_type &t) {
279 typename rate_type::token_type high;
280 int_multiply(t, rate.token_scale(), t, high);
281 if (high)
282 t = rate_type::max_tokens;
283 return !high;
284 }
285};
286template<typename rate_type> struct TokenRateConverter<rate_type, false> {
287 static bool cvt(const rate_type &rate, typename rate_type::token_type &t) {
288 if (t <= rate.capacity()) {
289 t *= rate.token_scale();
290 return true;
291 } else {
292 t = rate_type::max_tokens;
293 return false;
294 }
295 }
296};
327template <typename R>
328class TokenCounterX { public:
329
331 typedef R rate_type;
332
334 typedef typename R::token_type token_type;
335
337 typedef typename R::time_point_type time_point_type;
338
340 typedef typename R::ticks_type ticks_type;
341
342 enum {
343 max_tokens = R::max_tokens
344 };
345
350 : _tokens(0), _time_point() {
351 }
352
358 explicit TokenCounterX(bool full)
359 : _tokens(full ? (token_type) max_tokens : 0), _time_point() {
360 }
361
367 token_type size(const rate_type &rate) const {
368 return _tokens / rate.token_scale();
369 }
370
376 return _tokens;
377 }
378
380 bool empty() const {
381 return _tokens == 0;
382 }
383
385 bool full() const {
386 return _tokens == (token_type) max_tokens;
387 }
388
395 bool contains(const rate_type &rate, token_type t) const {
396 return cvt_type::cvt(rate, t) && contains_fraction(t);
397 }
398
402 return f <= _tokens;
403 }
404
408 void clear() {
409 _tokens = 0;
410 }
411
415 void set_full() {
416 _tokens = max_tokens;
417 }
418
424 void set(const rate_type &rate, token_type t) {
425 (void) cvt_type::cvt(rate, t);
426 _tokens = t;
427 }
428
432 _tokens = f;
433 }
434
445 void adjust(const rate_type &old_rate, const rate_type &new_rate) {
446 if (old_rate.token_scale() != new_rate.token_scale()) {
447 static_assert(sizeof(bigint::limb_type) == sizeof(token_type),
448 "bigint::limb_type should have the same size as token_type.");
449 bigint::limb_type l[2] = { 0, 0 };
450 bigint::limb_type a[2] = { _tokens, 0 };
451 bigint::multiply_add(l, a, 2, new_rate.token_scale());
452 (void) bigint::divide(l, l, 2, old_rate.token_scale());
453 _tokens = l[1] ? (token_type) max_tokens : l[0];
454 }
455 }
456
466 void refill(const rate_type &rate);
467
471 void refill(const rate_type &rate, time_point_type time);
472
476 template <typename U> void refill(const rate_type &rate, U time);
477
485 _time_point = time;
486 }
487
493 return _time_point;
494 }
495
502 void remove(const rate_type &rate, token_type t) {
503 (void) cvt_type::cvt(rate, t);
504 remove_fraction(t);
505 }
506
515 bool remove_if(const rate_type &rate, token_type t) {
516 return cvt_type::cvt(rate, t) && remove_fraction_if(t);
517 }
518
524 _tokens = (f <= _tokens ? _tokens - f : 0);
525 }
526
534 if (f <= _tokens) {
535 _tokens -= f;
536 return true;
537 } else
538 return false;
539 }
540
550 token_type t) const {
551 if (cvt_type::cvt(rate, t))
552 return time_until_contains_fraction(rate, t);
553 else
554 return (ticks_type) -1;
555 }
556
565 token_type f) const {
566 if (f <= _tokens || rate.time_until_full() == 0)
567 return 0;
568 else if (rate.tokens_per_tick() == 0)
569 return (ticks_type) -1;
570 else
571 return (f - _tokens - 1) / rate.tokens_per_tick() + 1;
572 }
573
574
576 inline ticks_type epochs_until_contains(const rate_type &rate, token_type t) const CLICK_DEPRECATED;
577 inline ticks_type epochs_until_contains_fraction(const rate_type &rate, token_type f) const CLICK_DEPRECATED;
580 private:
581
582 token_type _tokens;
583 time_point_type _time_point;
584
585 typedef TokenRateConverter<rate_type, has_fast_int_multiply<token_type>::value> cvt_type;
586
587};
588
589template <typename R>
591{
592 ticks_type diff = rate.time_monotonic_difference(_time_point, time);
593 if (diff >= rate.time_until_full()) {
594 // ignore special case of idle rates -- we assume that
595 // rate.time_monotonic_difference() will never return (ticks_type) -1,
596 // and ensure that ticks_type is unsigned
597 _tokens = max_tokens;
598 } else if (diff > 0) {
599 token_type new_tokens = _tokens + diff * rate.tokens_per_tick();
600 _tokens = (new_tokens < _tokens ? (token_type) max_tokens : new_tokens);
601 }
602 _time_point = time;
603}
604
605template <typename R>
607{
608 refill(rate, rate.now());
609}
610
611template <typename R> template <typename U>
613{
614 refill(rate, rate.time_point(time));
615}
616
618template <typename R>
620{
621 return time_until_contains(rate, t);
622}
623template <typename R>
625{
626 return time_until_contains_fraction(rate, f);
627}
638template <typename T>
640
642 typedef T token_type;
643
645 typedef click_jiffies_t time_point_type;
646
648 typedef click_jiffies_difference_t duration_type;
649
653 return click_jiffies();
654 }
655
656 static time_point_type time_point(time_point_type t) {
657 return t;
658 }
659
667#if CLICK_JIFFIES_MONOTONIC
668 return b - a;
669#else
670 return (likely(a <= b) ? b - a : 0);
671#endif
672 }
673
676 return click_jiffies_less(a, b);
677 }
678
682 static unsigned frequency() {
683 return CLICK_HZ;
684 }
685
690
695
696};
697
705template <typename T>
707
709 typedef T token_type;
710
712 typedef click_uintmax_t time_point_type;
713
715 typedef click_intmax_t duration_type;
716
721 }
722
723 static time_point_type time_point(time_point_type t) {
724 return t;
725 }
726
734 return (likely(a <= b) ? b - a : 0);
735 }
736
739 return (duration_type) (a - b) < 0;
740 }
741
745 static unsigned frequency() {
746 return 1000000;
747 }
748
751 return Timestamp::make_usec(x);
752 }
753
756 return Timestamp::make_usec(x);
757 }
758
759};
760
772template <typename P>
773class TokenBucketX { public:
774
776 typedef P parameter_type;
777
780
783
785 typedef typename rate_type::token_type token_type;
786
788 typedef typename rate_type::time_point_type time_point_type;
789
791 typedef typename rate_type::ticks_type ticks_type;
792
793 enum {
794 max_tokens = rate_type::max_tokens
795 };
796
801 }
802
807 explicit TokenBucketX(bool unlimited)
808 : _rate(unlimited), _bucket(unlimited) {
809 }
810
821 : _rate(rate, capacity), _bucket(rate != 0 && capacity != 0) {
822 }
823
826 void assign(bool unlimited = false) {
827 _rate.assign(unlimited);
828 }
829
843 void assign(token_type rate, token_type capacity) {
844 _rate.assign(rate, capacity);
845 }
846
856 void assign_adjust(token_type rate, token_type capacity) {
857 rate_type old_rate(_rate);
858 _rate.assign(rate, capacity);
859 _bucket.adjust(old_rate, _rate);
860 }
861
863 bool unlimited() const {
864 return _rate.unlimited();
865 }
866
868 bool idle() const {
869 return _rate.idle();
870 }
871
876 token_type rate() const {
877 return _rate.rate();
878 }
879
885 return _rate.capacity();
886 }
887
892 token_type size() const {
893 return _bucket.size(_rate);
894 }
895
901 return _bucket.fraction();
902 }
903
905 bool empty() const {
906 return _bucket.empty();
907 }
908
910 bool full() const {
911 return _bucket.full();
912 }
913
918 bool contains(token_type t) const {
919 return _bucket.contains(_rate, t);
920 }
921
925 return _bucket.contains_fraction(f);
926 }
927
931 void clear() {
932 _bucket.clear();
933 }
934
938 void set_full() {
939 _bucket.set_full();
940 }
941
946 void set(token_type t) {
947 _bucket.set(_rate, t);
948 }
949
953 _bucket.set_fraction(f);
954 }
955
964 void refill() {
965 _bucket.refill(_rate);
966 }
967
970 _bucket.refill(_rate, time);
971 }
972
974 template <typename U> void refill(U time) {
975 _bucket.refill(_rate, time);
976 }
977
984 _bucket.set_time_point(time);
985 }
986
987 time_point_type time_point() {
988 return _bucket.time_point();
989 }
990
997 _bucket.remove(_rate, t);
998 }
999
1008 return _bucket.remove_if(_rate, t);
1009 }
1010
1016 _bucket.remove_fraction(f);
1017 }
1018
1026 return _bucket.remove_fraction_if(f);
1027 }
1028
1034 return _bucket.time_until_contains(_rate, t);
1035 }
1036
1042 return _bucket.time_until_contains_fraction(_rate, f);
1043 }
1044
1045
1047 inline ticks_type epochs_until_contains(const rate_type &rate, token_type t) const CLICK_DEPRECATED;
1048 inline ticks_type epochs_until_contains_fraction(const rate_type &rate, token_type f) const CLICK_DEPRECATED;
1051 private:
1052
1053 rate_type _rate;
1054 counter_type _bucket;
1055
1056};
1057
1059template <typename P>
1061{
1062 return time_until_contains(rate, t);
1063}
1064template <typename P>
1066{
1067 return time_until_contains_fraction(rate, f);
1068}
1079
1087
1095
1096CLICK_ENDDECLS
1097#endif
Simple multiple-precision integer arithmetic.
Represents a moment or interval in time.
Definition timestamp.hh:125
static Timestamp make_jiffies(click_jiffies_t jiffies)
Return a timestamp representing an interval of jiffies.
Definition timestamp.hh:1183
static Timestamp now_steady()
Return the current steady-clock time.
Definition timestamp.hh:986
static Timestamp make_usec(seconds_type sec, uint32_t usec)
Return a timestamp representing sec seconds plus usec microseconds.
Definition timestamp.hh:349
value_type usecval() const
Return this timestamp's interval length in microseconds.
Definition timestamp.hh:281
Microsecond-based token bucket rate limiter.
Helper class for token bucket rate limiter.
Definition tokenbucket.hh:639
T token_type
The type of tokens. Always unsigned.
Definition tokenbucket.hh:642
static Timestamp timestamp(duration_type x)
Return the Timestamp representing a given tick count.
Definition tokenbucket.hh:692
click_jiffies_t time_point_type
The type of a time point. Always unsigned.
Definition tokenbucket.hh:645
static unsigned frequency()
Return the number of time points per period.
Definition tokenbucket.hh:682
static time_point_type now()
Return the current time point.
Definition tokenbucket.hh:652
static bool time_less(time_point_type a, time_point_type b)
Return true if a happened before b.
Definition tokenbucket.hh:675
click_jiffies_difference_t duration_type
The type of a difference between time points. Always signed.
Definition tokenbucket.hh:648
static Timestamp timestamp(time_point_type x)
Return the Timestamp representing a given time point.
Definition tokenbucket.hh:687
static duration_type time_monotonic_difference(time_point_type a, time_point_type b)
Return b - a, assuming that b was measured after a.
Definition tokenbucket.hh:666
Helper class for token bucket rate limiter.
Definition tokenbucket.hh:706
static unsigned frequency()
Return the number of time points per period.
Definition tokenbucket.hh:745
static time_point_type now()
Return the current time point.
Definition tokenbucket.hh:719
static duration_type time_monotonic_difference(time_point_type a, time_point_type b)
Return b - a, assuming that b was measured after a.
Definition tokenbucket.hh:733
click_intmax_t duration_type
The type of a difference between time points. Always signed.
Definition tokenbucket.hh:715
static Timestamp timestamp(time_point_type x)
Return the Timestamp representing a given time point.
Definition tokenbucket.hh:750
click_uintmax_t time_point_type
The type of a time point. Always unsigned.
Definition tokenbucket.hh:712
static bool time_less(time_point_type a, time_point_type b)
Return true if a happened before b.
Definition tokenbucket.hh:738
static Timestamp timestamp(duration_type x)
Return the Timestamp representing a given tick count.
Definition tokenbucket.hh:755
T token_type
The type of tokens. Always unsigned.
Definition tokenbucket.hh:709
Token bucket rate limiter.
Definition tokenbucket.hh:773
token_type rate() const
Return the rate in tokens per period.
Definition tokenbucket.hh:876
bool contains_fraction(token_type f) const
Test if the token bucket is above a fraction of its capacity.
Definition tokenbucket.hh:924
void set_time_point(time_point_type time)
Set the token bucket's internal time point to time.
Definition tokenbucket.hh:983
bool full() const
Test if the token bucket is at full capacity.
Definition tokenbucket.hh:910
ticks_type time_until_contains(token_type t) const
Return the number of ticks until contains(t).
Definition tokenbucket.hh:1033
void set_fraction(token_type f)
Set the token bucket to a fraction of its capacity.
Definition tokenbucket.hh:952
ticks_type time_until_contains_fraction(ticks_type f) const
Return the number of ticks until contains_fraction(f).
Definition tokenbucket.hh:1041
bool empty() const
Test if the token bucket is completely empty.
Definition tokenbucket.hh:905
token_type fraction() const
Return the bucket's fullness fraction.
Definition tokenbucket.hh:900
bool idle() const
Return true iff the token rate is idle.
Definition tokenbucket.hh:868
void assign_adjust(token_type rate, token_type capacity)
Set the token bucket rate and capacity, preserving the token count.
Definition tokenbucket.hh:856
TokenRateX< P > rate_type
The token rate type.
Definition tokenbucket.hh:779
void refill(time_point_type time)
Refill the token bucket for time.
Definition tokenbucket.hh:969
rate_type::ticks_type ticks_type
Unsigned type of differences between time ticks.
Definition tokenbucket.hh:791
TokenBucketX(bool unlimited)
Construct an idle or unlimited token bucket.
Definition tokenbucket.hh:807
bool remove_fraction_if(token_type f)
Remove a fullness fraction from the bucket if it is full enough.
Definition tokenbucket.hh:1025
void refill(U time)
Refill the token bucket for time P::time_point(time).
Definition tokenbucket.hh:974
void assign(bool unlimited=false)
Set the token bucket rate to idle or unlimited.
Definition tokenbucket.hh:826
bool remove_if(token_type t)
Remove t tokens from the bucket if it contains t tokens.
Definition tokenbucket.hh:1007
TokenBucketX()
Construct an idle token bucket.
Definition tokenbucket.hh:800
void clear()
Clear the token bucket.
Definition tokenbucket.hh:931
P parameter_type
The template parameter type.
Definition tokenbucket.hh:776
TokenBucketX(token_type rate, token_type capacity)
Construct a token bucket representing rate.
Definition tokenbucket.hh:820
TokenCounterX< rate_type > counter_type
The token counter type.
Definition tokenbucket.hh:782
void set(token_type t)
Set the token bucket to contain t tokens.
Definition tokenbucket.hh:946
rate_type::time_point_type time_point_type
Type of time ticks.
Definition tokenbucket.hh:788
token_type size() const
Return the number of tokens in the bucket.
Definition tokenbucket.hh:892
token_type capacity() const
Return the capacity in tokens.
Definition tokenbucket.hh:884
void set_full()
Fill the token bucket to capacity.
Definition tokenbucket.hh:938
bool contains(token_type t) const
Test if the token bucket has at least t tokens.
Definition tokenbucket.hh:918
void assign(token_type rate, token_type capacity)
Set the token bucket rate and capacity.
Definition tokenbucket.hh:843
void remove(token_type t)
Remove t tokens from the bucket.
Definition tokenbucket.hh:996
bool unlimited() const
Return true iff the token rate is unlimited.
Definition tokenbucket.hh:863
void remove_fraction(token_type f)
Remove a fullness fraction from the bucket.
Definition tokenbucket.hh:1015
rate_type::token_type token_type
Unsigned type of token counts.
Definition tokenbucket.hh:785
void refill()
Refill the token bucket to time P::now().
Definition tokenbucket.hh:964
Microsecond-based token counter.
Token bucket counter template.
Definition tokenbucket.hh:328
bool contains(const rate_type &rate, token_type t) const
Test if the token counter has at least t tokens.
Definition tokenbucket.hh:395
void remove(const rate_type &rate, token_type t)
Remove t tokens from the counter.
Definition tokenbucket.hh:502
void set_fraction(token_type f)
Set the token counter to a fraction of its capacity.
Definition tokenbucket.hh:431
TokenCounterX(bool full)
Construct a TokenCounter.
Definition tokenbucket.hh:358
token_type fraction() const
Return the counter's fullness fraction.
Definition tokenbucket.hh:375
void clear()
Clear the token counter.
Definition tokenbucket.hh:408
void refill(const rate_type &rate)
Refill the token counter to time rate.now().
Definition tokenbucket.hh:606
void adjust(const rate_type &old_rate, const rate_type &new_rate)
Compensate the counter for a change of rate.
Definition tokenbucket.hh:445
time_point_type time_point()
Return the internal time point.
Definition tokenbucket.hh:492
void set_time_point(time_point_type time)
Set the token counter's internal time point to time.
Definition tokenbucket.hh:484
void refill(const rate_type &rate, U time)
Refill the token counter for time.
Definition tokenbucket.hh:612
TokenCounterX()
Construct an empty TokenCounter.
Definition tokenbucket.hh:349
void refill(const rate_type &rate, time_point_type time)
Refill the token counter for time.
Definition tokenbucket.hh:590
R rate_type
The token rate type.
Definition tokenbucket.hh:331
bool contains_fraction(token_type f) const
Test if the token counter is above a fraction of its capacity.
Definition tokenbucket.hh:401
R::ticks_type ticks_type
Unsigned type of tick counts (differences between time points).
Definition tokenbucket.hh:340
void set_full()
Fill the token counter to capacity.
Definition tokenbucket.hh:415
bool remove_fraction_if(token_type f)
Remove a fullness fraction from the counter if it is full enough.
Definition tokenbucket.hh:533
bool empty() const
Test if the token counter is completely empty.
Definition tokenbucket.hh:380
ticks_type time_until_contains_fraction(const rate_type &rate, token_type f) const
Return the number of ticks until contains_fraction(f).
Definition tokenbucket.hh:564
ticks_type time_until_contains(const rate_type &rate, token_type t) const
Return the number of ticks until contains(rate, t).
Definition tokenbucket.hh:549
bool full() const
Test if the token counter is at full capacity.
Definition tokenbucket.hh:385
void set(const rate_type &rate, token_type t)
Set the token counter to contain t tokens.
Definition tokenbucket.hh:424
token_type size(const rate_type &rate) const
Return the number of tokens in the counter.
Definition tokenbucket.hh:367
void remove_fraction(token_type f)
Remove a fullness fraction from the counter.
Definition tokenbucket.hh:523
bool remove_if(const rate_type &rate, token_type t)
Remove t tokens from the counter if it contains t tokens.
Definition tokenbucket.hh:515
R::token_type token_type
Unsigned type of token counts.
Definition tokenbucket.hh:334
R::time_point_type time_point_type
Type of time points.
Definition tokenbucket.hh:337
Microsecond-based token bucket rate.
Token bucket rate template.
Definition tokenbucket.hh:60
void assign(bool unlimited=false)
Set the token rate to idle or unlimited.
Definition tokenbucket.hh:196
token_type tokens_per_tick() const
Return the number of tokens per tick.
Definition tokenbucket.hh:137
bool unlimited() const
Return true iff the token rate is unlimited.
Definition tokenbucket.hh:113
ticks_type time_until_full() const
Return the number of ticks required to refill a counter to capacity.
Definition tokenbucket.hh:150
P parameter_type
The template parameter type.
Definition tokenbucket.hh:63
bool idle() const
Return true iff the token rate is idle.
Definition tokenbucket.hh:118
P::token_type token_type
Unsigned type of token counts.
Definition tokenbucket.hh:66
token_type rate() const
Return the rate in tokens per period.
Definition tokenbucket.hh:245
P::time_point_type time_point_type
Type of time points.
Definition tokenbucket.hh:69
ticks_type time_monotonic_difference(time_point_type a, time_point_type b) const
Return b - a, assuming that b was measured after a.
Definition tokenbucket.hh:176
TokenRateX(bool unlimited)
Construct an idle or unlimited token rate.
Definition tokenbucket.hh:85
make_unsigned< typenameP::duration_type >::type ticks_type
Unsigned type of tick counts (differences between time points).
Definition tokenbucket.hh:72
time_point_type time_point(U time) const
Return the time point corresponding to the time parameter.
Definition tokenbucket.hh:166
TokenRateX(token_type rate, token_type capacity)
Construct a token rate representing rate.
Definition tokenbucket.hh:96
token_type token_scale() const
Return the ratio of fractional tokens to real tokens.
Definition tokenbucket.hh:142
token_type capacity() const
Return the capacity in tokens.
Definition tokenbucket.hh:132
time_point_type now() const
Return the current time point.
Definition tokenbucket.hh:157
TokenRateX()
Construct an idle token rate.
Definition tokenbucket.hh:79
void int_multiply(T a, T b, T &xlow, T &xhigh)
Multiply a * b, placing the low-order bits of the result in xlow and the high-order bits in xhigh.
Definition integers.hh:395
The Timestamp class represents a moment or interval in time.