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.
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 */