From 754f3aa44519029df6ce3b6a68e12b69171dbf14 Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Thu, 20 Sep 2018 21:28:40 +0800 Subject: [PATCH] common/Finisher: only queue empty only wake up waiter. Signed-off-by: Jianpeng Ma --- src/common/Finisher.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/Finisher.h b/src/common/Finisher.h index 4b6d2d3c8a1..94607ea21a6 100644 --- a/src/common/Finisher.h +++ b/src/common/Finisher.h @@ -193,18 +193,22 @@ public: ContextQueue(Mutex& mut, Cond& con) : mutex(mut), cond(con) {} void queue(list& ls) { + bool empty = false; { std::scoped_lock l(q_mutex); if (q.empty()) { q.swap(ls); + empty = true; } else { q.insert(q.end(), ls.begin(), ls.end()); } } - mutex.Lock(); - cond.SignalOne(); - mutex.Unlock(); + if (empty) { + mutex.Lock(); + cond.SignalOne(); + mutex.Unlock(); + } ls.clear(); } -- 2.39.5