diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c index 33f3ee66942e..61621dc94c11 100644 --- a/lib/libthr/thread/thr_init.c +++ b/lib/libthr/thread/thr_init.c @@ -412,6 +412,8 @@ init_private(void) _thr_umtx_init(&_keytable_lock); _thr_umtx_init(&_thr_atfork_lock); _thr_umtx_init(&_thr_event_lock); + _thr_once_lock = PTHREAD_MUTEX_INITIALIZER; + _thr_once_cv = PTHREAD_COND_INITIALIZER; _thr_spinlock_init(); _thr_list_init(); diff --git a/lib/libthr/thread/thr_once.c b/lib/libthr/thread/thr_once.c index 49257b2557cc..98360f220d66 100644 --- a/lib/libthr/thread/thr_once.c +++ b/lib/libthr/thread/thr_once.c @@ -40,8 +40,8 @@ __weak_reference(_pthread_once, pthread_once); #define ONCE_IN_PROGRESS 0x02 #define ONCE_MASK 0x03 -static pthread_mutex_t once_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_cond_t once_cv = PTHREAD_COND_INITIALIZER; +pthread_mutex_t _thr_once_lock = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t _thr_once_cv = PTHREAD_COND_INITIALIZER; /* * POSIX: @@ -55,10 +55,10 @@ once_cancel_handler(void *arg) { pthread_once_t *once_control = arg; - _pthread_mutex_lock(&once_lock); + _pthread_mutex_lock(&_thr_once_lock); once_control->state = ONCE_NEVER_DONE; - _pthread_mutex_unlock(&once_lock); - _pthread_cond_broadcast(&once_cv); + _pthread_mutex_unlock(&_thr_once_lock); + _pthread_cond_broadcast(&_thr_once_cv); } int @@ -68,26 +68,26 @@ _pthread_once(pthread_once_t *once_control, void (*init_routine) (void)) if (once_control->state == ONCE_DONE) return (0); - _pthread_mutex_lock(&once_lock); + _pthread_mutex_lock(&_thr_once_lock); while (*(volatile int *)&(once_control->state) == ONCE_IN_PROGRESS) - _pthread_cond_wait(&once_cv, &once_lock); + _pthread_cond_wait(&_thr_once_cv, &_thr_once_lock); /* * If previous thread was canceled, then the state still * could be ONCE_NEVER_DONE, we need to check it again. */ if (*(volatile int *)&(once_control->state) == ONCE_NEVER_DONE) { once_control->state = ONCE_IN_PROGRESS; - _pthread_mutex_unlock(&once_lock); + _pthread_mutex_unlock(&_thr_once_lock); _pthread_cleanup_push(once_cancel_handler, once_control); init_routine(); _pthread_cleanup_pop(0); - _pthread_mutex_lock(&once_lock); + _pthread_mutex_lock(&_thr_once_lock); once_control->state = ONCE_DONE; wakeup = 1; } - _pthread_mutex_unlock(&once_lock); + _pthread_mutex_unlock(&_thr_once_lock); if (wakeup) - _pthread_cond_broadcast(&once_cv); + _pthread_cond_broadcast(&_thr_once_cv); return (0); } diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index c922b465d6a8..c6c9d22be8bb 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -649,6 +649,8 @@ extern umtx_t _rwlock_static_lock __hidden; extern umtx_t _keytable_lock __hidden; extern umtx_t _thr_list_lock __hidden; extern umtx_t _thr_event_lock __hidden; +extern pthread_mutex_t _thr_once_lock __hidden; +extern pthread_cond_t _thr_once_cv __hidden; /* * Function prototype definitions.