1 #include "pthread_impl.h"
3 static void undo(void *control)
9 int __pthread_once(pthread_once_t *control, void (*init)(void))
13 /* Return immediately if init finished before, but ensure that
14 * effects of the init routine are visible to the caller. */
20 /* Try to enter initializing state. Three possibilities:
21 * 0 - we're the first or the other cancelled; run init
22 * 1 - another thread is running init; wait
23 * 2 - another thread finished running init; just return */
25 for (;;) switch (a_cas(control, 0, 1)) {
27 pthread_cleanup_push(undo, control);
29 pthread_cleanup_pop(0);
32 if (waiters) __wake(control, -1, 1);
35 __wait(control, &waiters, 1, 1);
42 weak_alias(__pthread_once, pthread_once);