Commit f490576e authored by David Callahan's avatar David Callahan Committed by Facebook Github Bot

Fix CLANG compilation: folly/TokenBucket.h

Summary:
In the next revision of clang, compilation generates multiple erroes of the form

   folly/TokenBucket.h:127:29: error: exception specification is not available until end of  class definition
         double nowInSeconds = defaultClockNow()) {

which are eliminated by reordering the method declaration for defaultClockNow()

Refer https://llvm.org/bugs/show_bug.cgi?id=30860

Reviewed By: philippu, yfeldblum

Differential Revision: D4107443

fbshipit-source-id: ce64f2ae7983e533c2fcb5cb043dbdd3da5c00f7
parent bc32ffea
...@@ -104,6 +104,15 @@ class ParameterizedDynamicTokenBucket { ...@@ -104,6 +104,15 @@ class ParameterizedDynamicTokenBucket {
zeroTime_ = zeroTime; zeroTime_ = zeroTime;
} }
/**
* Returns the current time in seconds since Epoch.
*/
static double defaultClockNow() noexcept(noexcept(ClockT::timeSinceEpoch())) {
return std::chrono::duration_cast<std::chrono::duration<double>>(
ClockT::timeSinceEpoch())
.count();
}
/** /**
* Attempts to consume some number of tokens. Tokens are first added to the * 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. * bucket based on the time elapsed since the last attempt to consume tokens.
...@@ -191,15 +200,6 @@ class ParameterizedDynamicTokenBucket { ...@@ -191,15 +200,6 @@ class ParameterizedDynamicTokenBucket {
return std::min((nowInSeconds - this->zeroTime_) * rate, burstSize); 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<std::chrono::duration<double>>(
ClockT::timeSinceEpoch())
.count();
}
private: private:
template <typename TCallback> template <typename TCallback>
bool consumeImpl( bool consumeImpl(
...@@ -268,6 +268,13 @@ class ParameterizedTokenBucket { ...@@ -268,6 +268,13 @@ class ParameterizedTokenBucket {
ParameterizedTokenBucket& operator=( ParameterizedTokenBucket& operator=(
const ParameterizedTokenBucket& other) noexcept = default; 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. * Change rate and burst size.
* *
...@@ -370,13 +377,6 @@ class ParameterizedTokenBucket { ...@@ -370,13 +377,6 @@ class ParameterizedTokenBucket {
return burstSize_; return burstSize_;
} }
/**
* Returns the current time in seconds since Epoch.
*/
static double defaultClockNow() noexcept(noexcept(Impl::defaultClockNow())) {
return Impl::defaultClockNow();
}
private: private:
Impl tokenBucket_; Impl tokenBucket_;
double rate_; double rate_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment