]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
throtle: add asserts on max and change parameters where appropriate
authorGreg Farnum <gregf@hq.newdream.net>
Mon, 7 Jun 2010 12:55:05 +0000 (05:55 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Mon, 7 Jun 2010 12:55:05 +0000 (05:55 -0700)
src/common/Throttle.h

index 440ef6239975c72f5fccd63532f7980e2727050f..98ebe310b8ea1981a8761fc1b653bd33bfb8d276 100644 (file)
@@ -11,7 +11,9 @@ class Throttle {
   
 public:
   Throttle(int64_t m = 0) : count(0), max(m), waiting(0),
-                         lock("Throttle::lock") {}
+                         lock("Throttle::lock") {
+    assert(m >= 0);
+}
 
 private:
   void _reset_max(int64_t m) {
@@ -52,27 +54,34 @@ public:
 
   bool wait(int64_t m = 0) {
     Mutex::Locker l(lock);
-    if (m)
+    if (m) {
+      assert(m > 0);
       _reset_max(m);
+    }
     return _wait(0);
   }
 
   int64_t take(int64_t c = 1) {
+    assert(c > 0);
     Mutex::Locker l(lock);
     count += c;
     return count;
   }
 
   bool get(int64_t c = 1, int64_t m = 0) {
+    assert(c > 0);
     Mutex::Locker l(lock);
-    if (m)
+    if (m) {
+      assert(m > 0);
       _reset_max(m);
+    }
     bool waited = _wait(c);
     count += c;
     return waited;
   }
 
   int64_t put(int64_t c = 1) {
+    assert(c > 0);
     Mutex::Locker l(lock);
     cond.SignalOne();
     count -= c;