[sheepdog] [PATCH v2 2/4] work: protect nr_threads by wi->startup_lock

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Dec 17 15:42:54 CET 2013


Previous protection scheme of wi->nr_thread in work.c was
unclear. This patch let work.c protect wi->nr_thread by
wi->startup_lock.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 lib/work.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/work.c b/lib/work.c
index 84eb727..a71f139 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -293,7 +293,11 @@ static void *worker_routine(void *arg)
 
 		pthread_mutex_lock(&wi->pending_lock);
 		if (wq_need_shrink(wi)) {
+			pthread_mutex_unlock(&wi->pending_lock);
+
+			pthread_mutex_lock(&wi->startup_lock);
 			wi->nr_threads--;
+			pthread_mutex_unlock(&wi->startup_lock);
 
 #ifdef ENABLE_TRACE
 			pthread_mutex_lock(&tid_map_lock);
@@ -301,7 +305,6 @@ static void *worker_routine(void *arg)
 			pthread_mutex_unlock(&tid_map_lock);
 #endif
 
-			pthread_mutex_unlock(&wi->pending_lock);
 			pthread_detach(pthread_self());
 			sd_debug("destroy thread %s %d, %zu", wi->name, tid,
 				 wi->nr_threads);
-- 
1.8.1.2




More information about the sheepdog mailing list