]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
workqueue: behave when multiple threads call drain()
authorSage Weil <sage@newdream.net>
Thu, 18 Feb 2010 05:47:18 +0000 (21:47 -0800)
committerSage Weil <sage@newdream.net>
Thu, 18 Feb 2010 05:47:18 +0000 (21:47 -0800)
Use a counter, not a bool.

src/common/WorkQueue.cc
src/common/WorkQueue.h

index 62508125a8c905e27b8e14e92cb34ee4007eab0b..22b8b75f19fe689f07c328539d5f7125b3a0a798 100644 (file)
@@ -125,10 +125,10 @@ void ThreadPool::drain(_WorkQueue *wq)
 {
   dout(10) << "drain" << dendl;
   _lock.Lock();
-  _draining = true;
+  _draining++;
   while (processing || (wq != NULL && !wq->_empty()))
     _wait_cond.Wait(_lock);
-  _draining = false;
+  _draining--;
   _lock.Unlock();
 }
 
index c24d32e2972f8f4470f5154ab47eac113e035184..bd608a0c7bba2cd65369f5402f0728bc05e01aee 100644 (file)
@@ -23,7 +23,8 @@ class ThreadPool {
   string name;
   Mutex _lock;
   Cond _cond;
-  bool _stop, _pause, _draining;
+  bool _stop, _pause;
+  int _draining;
   Cond _wait_cond;
 
   struct _WorkQueue {
@@ -124,7 +125,8 @@ public:
     name(nm),
     _lock((new string(name + "::lock"))->c_str()),  // deliberately leak this
     _stop(false),
-    _pause(false), _draining(false),
+    _pause(false),
+    _draining(0),
     last_work_queue(0),
     processing(0) {
     set_num_threads(n);