diff options
author | Thomas Pfaff <tpfaff@gmx.net> | 2003-12-02 01:10:57 +0300 |
---|---|---|
committer | Thomas Pfaff <tpfaff@gmx.net> | 2003-12-02 01:10:57 +0300 |
commit | 94d2416049fd158471da45380df829ffce203671 (patch) | |
tree | 21c164059860c586b4a8a72c8d0ecf42f6d40695 /winsup/cygwin/thread.h | |
parent | bd16a3a8a8a1b0f2971e6bac6c896320f02208c2 (diff) |
* 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.
Diffstat (limited to 'winsup/cygwin/thread.h')
-rw-r--r-- | winsup/cygwin/thread.h | 30 |
1 files changed, 15 insertions, 15 deletions
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 <class list_node> 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 <class list_node> 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_node> class List void insert (list_node *node) { - List_insert (mx, head, node); + List_insert (head, node); } void remove (list_node *node) |