mailing list of musl libc
 help / color / mirror / code / Atom feed
c1f3c28845e21cd1e5eb0d7e91a0623f711f9126 blob 1064 bytes (raw)

 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
30
31
32
33
34
35
36
37
38
39
40
 
#include "pthread_impl.h"
#include <threads.h>

#define pthread_cleanup_push_static(f, x) do { static struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x)

static void undo(void *flg)
{
	once_flag * flag = flg;
	a_store(&flag->__cntrl, 0);
	__wake_priv(&flag->__cntrl, 1);
}

void call_once(once_flag *flag, void (*func)(void))
{
	__THRD_ABI_MARK;

	/* Return immediately if init finished before */
	if (flag->__cntrl == 2) return;

	/* Try to enter initializing state. Three possibilities:
	 *  0 - we're the first or the other cancelled; run init
	 *  1 - another thread is running init; wait
	 *  2 - another thread finished running init; just return */

	for (;;) switch (a_cas(&flag->__cntrl, 0, 1)) {
	case 0:
		_pthread_cleanup_push((void*)&flag->__cb, undo, flag);
		func();
		_pthread_cleanup_pop((void*)&flag->__cb, 0);

		a_store(&flag->__cntrl, 2);
		if (flag->__waiters) __wake(&flag->__cntrl, -1, 0);
		return;
	case 1:
		__wait_priv(&flag->__cntrl, &flag->__waiters, 1);
		continue;
	case 2:
		return;
	}
}
debug log:

solving 1d3540e ...
found 1d3540e in https://inbox.vuxu.org/musl/1408049748.4951.134.camel@eris.loria.fr/ ||
	https://inbox.vuxu.org/musl/1407801532.15134.96.camel@eris.loria.fr/

applying [1/2] https://inbox.vuxu.org/musl/1408049748.4951.134.camel@eris.loria.fr/
diff --git a/src/thread/call_once.c b/src/thread/call_once.c\r
new file mode 100644\r
index 0000000..1d3540e\r

1:7: trailing whitespace.
#include "pthread_impl.h"\r
1:8: trailing whitespace.
#include <threads.h>\r
1:9: trailing whitespace.
\r
1:10: trailing whitespace.
#define pthread_cleanup_push_static(f, x) do { static struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x)\r
1:11: trailing whitespace.
\r
Checking patch src/thread/call_once.c...
Applied patch src/thread/call_once.c cleanly.
warning: squelched 35 whitespace errors
warning: 40 lines add whitespace errors.

skipping https://inbox.vuxu.org/musl/1407801532.15134.96.camel@eris.loria.fr/ for 1d3540e
index at:
100644 c1f3c28845e21cd1e5eb0d7e91a0623f711f9126	src/thread/call_once.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).