about summary refs log tree commit diff
path: root/nptl/libc-cancellation.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-02-16 09:18:53 +0000
committerUlrich Drepper <drepper@redhat.com>2003-02-16 09:18:53 +0000
commit1564916ab9ef4e2ce673cd5fb3123c067e4a787d (patch)
tree35849809bf0077f34384aee1183dc8f181ed411a /nptl/libc-cancellation.c
parente9cb48ab58fd8f619f5c7f13c2188161dbdef254 (diff)
downloadglibc-1564916ab9ef4e2ce673cd5fb3123c067e4a787d.tar.gz
glibc-1564916ab9ef4e2ce673cd5fb3123c067e4a787d.tar.xz
glibc-1564916ab9ef4e2ce673cd5fb3123c067e4a787d.zip
Update.
2003-02-16  Ulrich Drepper  <drepper@redhat.com>

	* libc-cancellation.c (__libc_enable_asynccancel): Rwrite to avoid
	going into an endless loop.
	* Makefile (tests): Add tst-cancel9.
	* tst-cancel9.c: New file.

	* pthread_cancel.c (pthread_cancel): Use the result of __pthread_kill.
Diffstat (limited to 'nptl/libc-cancellation.c')
-rw-r--r--nptl/libc-cancellation.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c
index 713ac8ecea..af56891007 100644
--- a/nptl/libc-cancellation.c
+++ b/nptl/libc-cancellation.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -40,20 +40,30 @@ __libc_enable_asynccancel (void)
       oldval = THREAD_GETMEM (self, cancelhandling);
       int newval = oldval | CANCELTYPE_BITMASK;
 
-      if (newval == oldval)
-	break;
-
-      if (atomic_compare_and_exchange_acq (&self->cancelhandling, newval,
-					   oldval) == 0)
+      if (__builtin_expect ((oldval & CANCELED_BITMASK) != 0, 0))
 	{
-	  if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
-	    {
-	      THREAD_SETMEM (self, result, PTHREAD_CANCELED);
-	      __do_cancel ();
-	    }
+	  /* If we are already exiting stop right here.  */
+	  if ((oldval & EXITING_BITMASK) != 0)
+	    break;
+
+	  if (atomic_compare_and_exchange_acq (&self->cancelhandling, newval,
+					       oldval) == 0)
+	    /* Somebody else modified the word, try again.  */
+	    continue;
+
+	  THREAD_SETMEM (self, result, PTHREAD_CANCELED);
 
-	  break;
+	  /* The thread is exiting now.  */
+	  atomic_bit_set (&self->cancelhandling, EXITING_BIT);
+
+	  __do_cancel ();
+
+	  /* NOTREACHED */
 	}
+
+      if (atomic_compare_and_exchange_acq (&self->cancelhandling, newval,
+					   oldval) == 0)
+	break;
     }
 
   return oldval;