Explicitly refer to the std::chrono namespace to avoid conflicts with the folly:...
[folly.git] / folly / TokenBucket.h
index 7ddf8fc23345359764f2a60dc98a84380fb3a8ed..2abbfe379e71dabd50c7258945fdf82f61fd6ba4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
 #include <chrono>
 
 #include <folly/Likely.h>
-#include <folly/detail/CacheLocality.h>
+#include <folly/concurrency/CacheLocality.h>
 
 namespace folly {
 
@@ -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<std::chrono::duration<double>>(
+               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<std::chrono::duration<double>>(
-               ClockT::timeSinceEpoch())
-        .count();
-  }
-
  private:
   template <typename TCallback>
   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_;
@@ -385,4 +385,4 @@ class ParameterizedTokenBucket {
 
 using TokenBucket = ParameterizedTokenBucket<>;
 using DynamicTokenBucket = ParameterizedDynamicTokenBucket<>;
-}
+} // namespace folly