diff options
author | davidxu <davidxu@FreeBSD.org> | 2006-02-15 13:41:02 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2006-02-15 13:41:02 +0000 |
commit | 44a8ce5006417a23f9bb7ef8d3d9bbe76365c7df (patch) | |
tree | 66b825423fd67e087f93ceaee6e4110c2945f1e2 /lib/libthr/thread/thr_once.c | |
parent | 0075b7699406c100933a06c14d000848763fee23 (diff) | |
download | FreeBSD-src-44a8ce5006417a23f9bb7ef8d3d9bbe76365c7df.zip FreeBSD-src-44a8ce5006417a23f9bb7ef8d3d9bbe76365c7df.tar.gz |
After fork(), reinitialize internal locks for pthread_once().
Diffstat (limited to 'lib/libthr/thread/thr_once.c')
-rw-r--r-- | lib/libthr/thread/thr_once.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/libthr/thread/thr_once.c b/lib/libthr/thread/thr_once.c index 49257b2..98360f2 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); } |