From d645574fd49d19da9513d19f78648de2c9bc670a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 13 May 2020 14:30:25 +0200 Subject: [PATCH] MINOR: soft-stop: let the first stopper only signal other threads When the first thread stops and wakes others up, it's possible some of them will also start to wake others in parallel. Let's make give this notification task to the very first one instead since it's enough and can reduce the amount of needless (though harmless) wakeup calls. --- src/haproxy.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index c3b7be6491..2675bf7157 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2835,11 +2835,12 @@ void run_poll_loop() int i; if (stopping) { - _HA_ATOMIC_OR(&stopping_thread_mask, tid_bit); - /* notify all threads that stopping was just set */ - for (i = 0; i < global.nbthread; i++) - if (((all_threads_mask & ~stopping_thread_mask) >> i) & 1) - wake_thread(i); + if (_HA_ATOMIC_OR(&stopping_thread_mask, tid_bit) == tid_bit) { + /* notify all threads that stopping was just set */ + for (i = 0; i < global.nbthread; i++) + if ((all_threads_mask >> i) & 1) + wake_thread(i); + } } /* stop when there's nothing left to do */ -- 2.39.5