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
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;
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;
}