From 0f1bdb6b131fffc27baa570b9e8cbc985c4b46f4 Mon Sep 17 00:00:00 2001 From: chenttuuvv Date: Wed, 22 Jul 2015 21:10:03 +0800 Subject: [PATCH] threadpool: send signal only when queue is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/libuv/libuv/pull/460 Reviewed-By: Ben Noordhuis Reviewed-By: Saúl Ibarra Corretgé --- src/threadpool.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/threadpool.c b/src/threadpool.c index debaf5ca..dd0abd9a 100644 --- a/src/threadpool.c +++ b/src/threadpool.c @@ -101,9 +101,12 @@ static void worker(void* arg) { static void post(QUEUE* q) { + int empty_queue; uv_mutex_lock(&mutex); + empty_queue = QUEUE_EMPTY(&wq); QUEUE_INSERT_TAIL(&wq, q); - uv_cond_signal(&cond); + if (empty_queue) + uv_cond_signal(&cond); uv_mutex_unlock(&mutex); }