X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fthread%2Fpthread_key_create.c;h=d112094122b316d161a6fd17f1c08d12d0b58e05;hb=bf14ef193b4203aa9a8b173faeeea06d98397f65;hp=da1fb1162d955c03b2716b0a84ed0bfad7f33d26;hpb=ba74a42cee90c9a4425188a021b6ad8ba80b9468;p=musl diff --git a/src/thread/pthread_key_create.c b/src/thread/pthread_key_create.c index da1fb116..d1120941 100644 --- a/src/thread/pthread_key_create.c +++ b/src/thread/pthread_key_create.c @@ -22,7 +22,6 @@ weak_alias(dummy_0, __tl_unlock); 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 @@ -32,16 +31,17 @@ int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) /* Purely a sentinel value since null means slot is free. */ if (!dtor) dtor = nodtor; - pthread_rwlock_wrlock(&key_lock); + __pthread_rwlock_wrlock(&key_lock); + pthread_key_t j = next_key; do { if (!keys[j]) { keys[next_key = *k = j] = dtor; - pthread_rwlock_unlock(&key_lock); + __pthread_rwlock_unlock(&key_lock); return 0; } } while ((j=(j+1)%PTHREAD_KEYS_MAX) != next_key); - pthread_rwlock_unlock(&key_lock); + __pthread_rwlock_unlock(&key_lock); return EAGAIN; } @@ -51,15 +51,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); + + __pthread_rwlock_unlock(&key_lock); + __restore_sigs(&set); return 0; } @@ -69,19 +71,19 @@ void __pthread_tsd_run_dtors() pthread_t self = __pthread_self(); int i, j; for (j=0; self->tsd_used && jtsd_used = 0; for (i=0; itsd[i]; void (*dtor)(void *) = keys[i]; self->tsd[i] = 0; if (val && dtor && dtor != nodtor) { - pthread_rwlock_unlock(&key_lock); + __pthread_rwlock_unlock(&key_lock); dtor(val); - pthread_rwlock_rdlock(&key_lock); + __pthread_rwlock_rdlock(&key_lock); } } - pthread_rwlock_unlock(&key_lock); + __pthread_rwlock_unlock(&key_lock); } }