From db171f2f9435b98f05f33fcbc0dcf0c5cc1cb917 Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 24 Mar 2011 23:33:14 +0000 Subject: First pass of robust mutexes --- pthread_setspecific.c | 55 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'pthread_setspecific.c') diff --git a/pthread_setspecific.c b/pthread_setspecific.c index b16270e..0f29e70 100644 --- a/pthread_setspecific.c +++ b/pthread_setspecific.c @@ -109,6 +109,9 @@ pthread_setspecific (pthread_key_t key, const void *value) { if (self.p != NULL && key->destructor != NULL && value != NULL) { + ptw32_mcs_local_node_t keyLock; + ptw32_mcs_local_node_t threadLock; + ptw32_thread_t * sp = (ptw32_thread_t *) self.p; /* * Only require associations if we have to * call user destroy routine. @@ -120,39 +123,35 @@ pthread_setspecific (pthread_key_t key, const void *value) */ ThreadKeyAssoc *assoc; - if (pthread_mutex_lock(&(key->keyLock)) == 0) - { - ptw32_thread_t * sp = (ptw32_thread_t *) self.p; - - (void) pthread_mutex_lock(&(sp->threadLock)); + ptw32_mcs_lock_acquire(&(key->keyLock), &keyLock); + ptw32_mcs_lock_acquire(&(sp->threadLock), &threadLock); - assoc = (ThreadKeyAssoc *) sp->keys; - /* - * Locate existing association - */ - while (assoc != NULL) - { - if (assoc->key == key) - { - /* - * Association already exists - */ - break; - } - assoc = assoc->nextKey; - } - - /* - * create an association if not found - */ - if (assoc == NULL) + assoc = (ThreadKeyAssoc *) sp->keys; + /* + * Locate existing association + */ + while (assoc != NULL) + { + if (assoc->key == key) { - result = ptw32_tkAssocCreate (sp, key); + /* + * Association already exists + */ + break; } + assoc = assoc->nextKey; + } - (void) pthread_mutex_unlock(&(sp->threadLock)); + /* + * create an association if not found + */ + if (assoc == NULL) + { + result = ptw32_tkAssocCreate (sp, key); } - (void) pthread_mutex_unlock(&(key->keyLock)); + + ptw32_mcs_lock_release(&threadLock); + ptw32_mcs_lock_release(&keyLock); } if (result == 0) -- cgit v1.2.3