From 94d2416049fd158471da45380df829ffce203671 Mon Sep 17 00:00:00 2001 From: Thomas Pfaff Date: Mon, 1 Dec 2003 22:10:57 +0000 Subject: * thread.cc (pthread_rwlock::add_reader): Remove mx parameter for List_insert call. (pthread::prepare): Ensure race safeness when adding function pointers to atfork lists by using List_insert. * thread.h (List_insert): Use InterlockedCompareExchangePointer to ensure race safeness without using a mutex. (List_remove): Use InterlockedCompareExchangePointer to ensure race safeness with List_insert. (List::insert): Remove mx parameter for List_insert call. --- winsup/cygwin/thread.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'winsup/cygwin/thread.h') diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index 5dd9857fb..0cba6cd48 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -224,14 +224,13 @@ verifyable_object_state verifyable_object_isvalid (void const *, long); verifyable_object_state verifyable_object_isvalid (void const *, long, void *); template inline void -List_insert (fast_mutex &mx, list_node *&head, list_node *node) +List_insert (list_node *&head, list_node *node) { if (!node) return; - mx.lock (); - node->next = head; - head = node; - mx.unlock (); + do + node->next = head; + while (InterlockedCompareExchangePointer (&head, node, node->next) != node->next); } template inline void @@ -240,16 +239,17 @@ List_remove (fast_mutex &mx, list_node *&head, list_node *node) if (!node) return; mx.lock (); - if (node == head) - head = head->next; - else if (head) + if (head) { - list_node *cur = head; - - while (cur->next && node != cur->next) - cur = cur->next; - if (node == cur->next) - cur->next = cur->next->next; + if (InterlockedCompareExchangePointer (&head, node->next, node) != node) + { + list_node *cur = head; + + while (cur->next && node != cur->next) + cur = cur->next; + if (node == cur->next) + cur->next = cur->next->next; + } } mx.unlock (); } @@ -274,7 +274,7 @@ template class List void insert (list_node *node) { - List_insert (mx, head, node); + List_insert (head, node); } void remove (list_node *node) -- cgit v1.2.3