diff options
author | Greg Farnum <gregf@hq.newdream.net> | 2010-08-31 11:38:35 -0700 |
---|---|---|
committer | Greg Farnum <gregf@hq.newdream.net> | 2010-09-14 13:42:44 -0700 |
commit | 7aae37cafcd7e6c8e08badeb04882eab8c69120e (patch) | |
tree | c2c52c34432168c73fb624ca57bd150afe609a1f /src/common | |
parent | 409bc411f0c21db2c47d45b8044aa89d66e7b02d (diff) | |
download | ceph-7aae37cafcd7e6c8e08badeb04882eab8c69120e.tar.gz |
throttle: add non-blocking get_or_fail method
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Throttle.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/common/Throttle.h b/src/common/Throttle.h index e940937b9ea..cd772dd8b29 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -69,7 +69,7 @@ public: } bool get(int64_t c = 1, int64_t m = 0) { - assert(c > 0); + assert(c >= 0); Mutex::Locker l(lock); if (m) { assert(m > 0); @@ -80,6 +80,17 @@ public: return waited; } + /* Returns true if it successfully got the requested amount, + * or false if it would block. + */ + bool get_or_fail(int64_t c = 1) { + assert (c >= 0); + Mutex::Locker l(lock); + if (_should_wait(c)) return false; + count += c; + return true; + } + int64_t put(int64_t c = 1) { assert(c >= 0); Mutex::Locker l(lock); |