cmogstored 1.8.1 - use default system stack size
[cmogstored.git] / yield.c
blobaffc50f4036f591d743ffd510f372b6282b9391a
1 /*
2 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
4 */
5 #include "cmogstored.h"
6 #ifndef HAVE_PTHREAD_YIELD
7 # define pthread_yield() (void)sched_yield()
8 #endif
11 * pthread_yield may migrate us to the same CPU as the task we're waiting
12 * on, so just keep yielding for every CPU we have as this throttles
13 * our ability to spam SIGURG. This means the threads we're trying to
14 * gracefully kill off can finish their work and check their mog_do_quit
15 * flag sooner
17 * We only use this as a last resort when normal wakeups/notifications
18 * are not usable (e.g. recovering from out-of-resource problems)
20 void mog_yield(void)
22 static unsigned long nproc_all;
23 unsigned long i;
25 if (!nproc_all)
26 nproc_all = num_processors(NPROC_ALL) * 2;
27 for (i = 0; i < nproc_all; i++)
28 pthread_yield();