From c97f2ceb3c9f59713b05e4f5cd4a2ad8e731e57c Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Wed, 23 Dec 2015 14:41:59 +0800 Subject: [PATCH] Throttler: Add reset support Signed-off-by: Haomai Wang --- src/common/Throttle.cc | 11 +++++++++++ src/common/Throttle.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/common/Throttle.cc b/src/common/Throttle.cc index 69d98da418c5e..7ba623252e268 100644 --- a/src/common/Throttle.cc +++ b/src/common/Throttle.cc @@ -235,6 +235,17 @@ int64_t Throttle::put(int64_t c) return count.read(); } +void Throttle::reset() +{ + Mutex::Locker l(lock); + if (!cond.empty()) + cond.front()->SignalOne(); + count.set(0); + if (logger) { + logger->set(l_throttle_val, 0); + } +} + bool BackoffThrottle::set_params( double _low_threshhold, double _high_threshhold, diff --git a/src/common/Throttle.h b/src/common/Throttle.h index cafe0d9a1160a..b920d195de6f9 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -105,6 +105,11 @@ public: * @returns number of requests being hold after this */ int64_t put(int64_t c = 1); + /** + * reset the zero to the stock + */ + void reset(); + bool should_wait(int64_t c) const { return _should_wait(c); } -- 2.39.5