From: Willy Tarreau Date: Wed, 13 May 2020 12:30:25 +0000 (+0200) Subject: MINOR: soft-stop: let the first stopper only signal other threads X-Git-Tag: v2.2-dev8~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d645574;p=thirdparty%2Fhaproxy.git 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. --- 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 */