]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
throttle: add non-blocking get_or_fail method
authorGreg Farnum <gregf@hq.newdream.net>
Tue, 31 Aug 2010 18:38:35 +0000 (11:38 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Tue, 14 Sep 2010 20:42:44 +0000 (13:42 -0700)
src/common/Throttle.h

index e940937b9ea0870c3826d62e6681cac7a490b620..cd772dd8b29ac906e25a0e8b719f131a73be3512 100644 (file)
@@ -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);