summaryrefslogtreecommitdiff
path: root/pthread_setspecific.c
diff options
context:
space:
mode:
Diffstat (limited to 'pthread_setspecific.c')
-rw-r--r--pthread_setspecific.c55
1 files changed, 27 insertions, 28 deletions
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)