Changeset View
Changeset View
Standalone View
Standalone View
lib/libthr/thread/thr_once.c
Show All 29 Lines | |||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "namespace.h" | #include "namespace.h" | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include "un-namespace.h" | #include "un-namespace.h" | ||||
#include "thr_private.h" | #include "thr_private.h" | ||||
__weak_reference(_pthread_once, pthread_once); | __weak_reference(_thr_once, pthread_once); | ||||
__weak_reference(_thr_once, _pthread_once); | |||||
#define ONCE_NEVER_DONE PTHREAD_NEEDS_INIT | #define ONCE_NEVER_DONE PTHREAD_NEEDS_INIT | ||||
#define ONCE_DONE PTHREAD_DONE_INIT | #define ONCE_DONE PTHREAD_DONE_INIT | ||||
#define ONCE_IN_PROGRESS 0x02 | #define ONCE_IN_PROGRESS 0x02 | ||||
#define ONCE_WAIT 0x03 | #define ONCE_WAIT 0x03 | ||||
/* | /* | ||||
* POSIX: | * POSIX: | ||||
Show All 11 Lines | once_cancel_handler(void *arg) | ||||
if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS, | if (atomic_cmpset_rel_int(&once_control->state, ONCE_IN_PROGRESS, | ||||
ONCE_NEVER_DONE)) | ONCE_NEVER_DONE)) | ||||
return; | return; | ||||
atomic_store_rel_int(&once_control->state, ONCE_NEVER_DONE); | atomic_store_rel_int(&once_control->state, ONCE_NEVER_DONE); | ||||
_thr_umtx_wake(&once_control->state, INT_MAX, 0); | _thr_umtx_wake(&once_control->state, INT_MAX, 0); | ||||
} | } | ||||
int | int | ||||
_pthread_once(pthread_once_t *once_control, void (*init_routine) (void)) | _thr_once(pthread_once_t *once_control, void (*init_routine)(void)) | ||||
{ | { | ||||
struct pthread *curthread; | struct pthread *curthread; | ||||
int state; | int state; | ||||
_thr_check_init(); | _thr_check_init(); | ||||
for (;;) { | for (;;) { | ||||
state = once_control->state; | state = once_control->state; | ||||
Show All 31 Lines |