X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fthread%2Fpthread_key_create.c;h=39770c7a3c8299bcaf0353717a6a6bf74a3fd8d7;hb=d055e6a45a17673b8dd3ec16e786bb2fe1700dd5;hp=dc20cc3f3b54d647ebf299bdf189ed61fd38482f;hpb=639bcf251e549f634da9a3e7ef8528eb2ec12505;p=musl diff --git a/src/thread/pthread_key_create.c b/src/thread/pthread_key_create.c index dc20cc3f..39770c7a 100644 --- a/src/thread/pthread_key_create.c +++ b/src/thread/pthread_key_create.c @@ -1,4 +1,5 @@ #include "pthread_impl.h" +#include "fork_impl.h" volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX; void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 }; @@ -20,9 +21,15 @@ static void dummy_0(void) weak_alias(dummy_0, __tl_lock); weak_alias(dummy_0, __tl_unlock); +void __pthread_key_atfork(int who) +{ + if (who<0) __pthread_rwlock_rdlock(&key_lock); + else if (!who) __pthread_rwlock_unlock(&key_lock); + else key_lock = (pthread_rwlock_t)PTHREAD_RWLOCK_INITIALIZER; +} + int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) { - pthread_key_t j = next_key; pthread_t self = __pthread_self(); /* This can only happen in the main thread before @@ -33,6 +40,7 @@ int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) if (!dtor) dtor = nodtor; __pthread_rwlock_wrlock(&key_lock); + pthread_key_t j = next_key; do { if (!keys[j]) { keys[next_key = *k = j] = dtor; @@ -51,15 +59,17 @@ int __pthread_key_delete(pthread_key_t k) pthread_t self = __pthread_self(), td=self; __block_app_sigs(&set); + __pthread_rwlock_wrlock(&key_lock); + __tl_lock(); do td->tsd[k] = 0; while ((td=td->next)!=self); __tl_unlock(); - __restore_sigs(&set); - __pthread_rwlock_wrlock(&key_lock); keys[k] = 0; + __pthread_rwlock_unlock(&key_lock); + __restore_sigs(&set); return 0; }