X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FTokenBucket.h;fp=folly%2FTokenBucket.h;h=ce6a0551c71f2bc468d98f4f7590418cad2db3dd;hp=7ddf8fc23345359764f2a60dc98a84380fb3a8ed;hb=f490576e697794b1a803fc280700a4364f5d3b24;hpb=bc32ffeaae78373e5fe057a82e6d00edc2672737 diff --git a/folly/TokenBucket.h b/folly/TokenBucket.h index 7ddf8fc2..ce6a0551 100644 --- a/folly/TokenBucket.h +++ b/folly/TokenBucket.h @@ -104,6 +104,15 @@ class ParameterizedDynamicTokenBucket { zeroTime_ = zeroTime; } + /** + * Returns the current time in seconds since Epoch. + */ + static double defaultClockNow() noexcept(noexcept(ClockT::timeSinceEpoch())) { + return std::chrono::duration_cast>( + ClockT::timeSinceEpoch()) + .count(); + } + /** * Attempts to consume some number of tokens. Tokens are first added to the * bucket based on the time elapsed since the last attempt to consume tokens. @@ -191,15 +200,6 @@ class ParameterizedDynamicTokenBucket { return std::min((nowInSeconds - this->zeroTime_) * rate, burstSize); } - /** - * Returns the current time in seconds since Epoch. - */ - static double defaultClockNow() noexcept(noexcept(ClockT::timeSinceEpoch())) { - return std::chrono::duration_cast>( - ClockT::timeSinceEpoch()) - .count(); - } - private: template bool consumeImpl( @@ -268,6 +268,13 @@ class ParameterizedTokenBucket { ParameterizedTokenBucket& operator=( const ParameterizedTokenBucket& other) noexcept = default; + /** + * Returns the current time in seconds since Epoch. + */ + static double defaultClockNow() noexcept(noexcept(Impl::defaultClockNow())) { + return Impl::defaultClockNow(); + } + /** * Change rate and burst size. * @@ -370,13 +377,6 @@ class ParameterizedTokenBucket { return burstSize_; } - /** - * Returns the current time in seconds since Epoch. - */ - static double defaultClockNow() noexcept(noexcept(Impl::defaultClockNow())) { - return Impl::defaultClockNow(); - } - private: Impl tokenBucket_; double rate_;