From 109f37f3abee0c12626d60763d7e8b5fa68b3381 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 17 Feb 2010 21:47:18 -0800 Subject: [PATCH] workqueue: behave when multiple threads call drain() Use a counter, not a bool. --- src/common/WorkQueue.cc | 4 ++-- src/common/WorkQueue.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/WorkQueue.cc b/src/common/WorkQueue.cc index 62508125a8c90..22b8b75f19fe6 100644 --- a/src/common/WorkQueue.cc +++ b/src/common/WorkQueue.cc @@ -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(); } diff --git a/src/common/WorkQueue.h b/src/common/WorkQueue.h index c24d32e2972f8..bd608a0c7bba2 100644 --- a/src/common/WorkQueue.h +++ b/src/common/WorkQueue.h @@ -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); -- 2.39.5