From ced43a31d2695fc75668a1d7d7b01ac4132ef196 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 8 Apr 2015 21:48:21 -0400 Subject: [PATCH] Throttle: added pending_error method to SimpleThrottle Allow the client of SimpleThrottle to detect an async error so that it can exit early. Signed-off-by: Jason Dillaman (cherry picked from commit b88b88c5df91325fb713c2031a56bffe421268e0) (cherry picked from commit dbd4e293d7124c89a22148e8fa5f425a995c900c) --- src/common/Throttle.cc | 6 ++++++ src/common/Throttle.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/Throttle.cc b/src/common/Throttle.cc index 026d731e839b5..5c68a1fe4f3a7 100644 --- a/src/common/Throttle.cc +++ b/src/common/Throttle.cc @@ -267,6 +267,12 @@ void SimpleThrottle::end_op(int r) m_cond.Signal(); } +bool SimpleThrottle::pending_error() const +{ + Mutex::Locker l(m_lock); + return (m_ret < 0); +} + int SimpleThrottle::wait_for_ret() { Mutex::Locker l(m_lock); diff --git a/src/common/Throttle.h b/src/common/Throttle.h index 6d039888c633e..b171e27ed00f3 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -76,9 +76,10 @@ public: ~SimpleThrottle(); void start_op(); void end_op(int r); + bool pending_error() const; int wait_for_ret(); private: - Mutex m_lock; + mutable Mutex m_lock; Cond m_cond; uint64_t m_max; uint64_t m_current; -- 2.39.5