cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob 3a0b66dec6cbb0297e2297c753cc84b152b6aa8c 862 bytes (raw)
$ git show empty-header-values:yield.c	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
/*
 * Copyright (C) 2013, Eric Wong <normalperson@yhbt.net>
 * License: GPLv3 or later (see COPYING for details)
 */
#include "cmogstored.h"
#ifndef HAVE_PTHREAD_YIELD
#  define pthread_yield() (void)sched_yield()
#endif

/*
 * pthread_yield may migrate us to the same CPU as the task we're waiting
 * on, so just keep yielding for every CPU we have as this throttles
 * our ability to spam SIGURG.  This means the threads we're trying to
 * gracefully kill off can finish their work and check their mog_do_quit
 * flag sooner
 *
 * We only use this as a last resort when normal wakeups/notifications
 * are not usable (e.g. recovering from out-of-resource problems)
 */
void mog_yield(void)
{
	static unsigned long nproc_all;
	unsigned long i;

	if (!nproc_all)
		nproc_all = num_processors(NPROC_ALL) * 2;
	for (i = 0; i < nproc_all; i++)
		pthread_yield();
}

git clone https://yhbt.net/cmogstored.git