From 91faeff9492b3b4d014863b424329f138efdb185 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 8 Apr 2015 21:48:21 -0400 Subject: [PATCH 17/22] 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 c2ea7e85dcbca60e6ae09d4ef99d02834d02b2ed) --- 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 026d731..5c68a1f 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 6d03988..b171e27 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.1.0