mailing list of musl libc
 help / color / mirror / code / Atom feed
72abde8e42117d673ae4eb1f0c688860215e6b7d blob 833 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
 
#include "pthread_impl.h"

static void undo(void *control)
{
	a_store(control, 0);
	__wake(control, 1, 0);
}

int __pthread_once(pthread_once_t *control, void (*init)(void))
{
	static int waiters;

	/* Return immediately if init finished before */
	if (*control == 2) return 0;

	/* 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(control, 0, 1)) {
	case 0:
		pthread_cleanup_push(undo, control);
		init();
		pthread_cleanup_pop(0);

		a_store(control, 2);
		if (waiters) __wake(control, -1, 0);
		return 0;
	case 1:
		__wait(control, &waiters, 1, 0);
		continue;
	case 2:
		return 0;
	}
}

weak_alias(__pthread_once, pthread_once);
debug log:

solving a678597 ...
found a678597 in https://inbox.vuxu.org/musl/1406886931.4830.92.camel@eris.loria.fr/ ||
	https://inbox.vuxu.org/musl/1407144603.8274.248.camel@eris.loria.fr/
found e01f6d4 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 e01f6d481cef5ef607675a76954d2864379782d0	src/thread/pthread_once.c

applying [1/2] https://inbox.vuxu.org/musl/1406886931.4830.92.camel@eris.loria.fr/
diff --git a/src/thread/pthread_once.c b/src/thread/pthread_once.c\r
index e01f6d4..a678597 100644\r

Checking patch src/thread/pthread_once.c...
Applied patch src/thread/pthread_once.c cleanly.

skipping https://inbox.vuxu.org/musl/1407144603.8274.248.camel@eris.loria.fr/ for a678597
index at:
100644 72abde8e42117d673ae4eb1f0c688860215e6b7d	src/thread/pthread_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).