This will enable SimpleMessenger to send keepalives to clients while blocked in the policy throttler. Signed-off-by: Jim Schutt <jaschut@xxxxxxxxxx> --- src/common/Throttle.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-) diff --git a/src/common/Throttle.h b/src/common/Throttle.h index 8fd2625..5a028cc 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -27,6 +27,9 @@ private: ((c < max && count + c > max) || // normally stay under max (c >= max && count > max)); // except for large c } + + /* Returns true if it had to block/wait, false otherwise. + */ bool _wait(int64_t c) { bool waited = false; if (_should_wait(c)) { @@ -44,6 +47,28 @@ private: return waited; } + /* Returns true if it timed out while blocked/waiting, + * false otherwise. + */ + bool _timed_wait(utime_t interval, int64_t c) { + if (_should_wait(c)) { + utime_t timeout_at = g_clock.now() + interval; + waiting += c; + do { + if (cond.WaitUntil(lock, timeout_at)) { + waiting -= c; + return true; + } + } while (_should_wait(c)); + waiting -= c; + + // wake up the next guy + if (waiting) + cond.SignalOne(); + } + return false; + } + public: int64_t get_current() { Mutex::Locker l(lock); @@ -79,6 +104,21 @@ public: count += c; } + /* Returns true if it got the requested amount within + * the specified interval, false otherwise. + */ + bool timed_get(utime_t interval, int64_t c = 1, int64_t m = 0) { + assert(c >= 0); + Mutex::Locker l(lock); + if (m) { + assert(m > 0); + _reset_max(m); + } + if (_timed_wait(interval, c)) return false; + count += c; + return true; + } + /* Returns true if it successfully got the requested amount, * or false if it would block. */ -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html