]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nptl/pthread_setcanceltype.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / nptl / pthread_setcanceltype.c
index bb4b24943e9df6aa3fb71fe129d39e8ee05c200f..11eff86bb8edc467b6d9215a79b5e486d56daba8 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -13,9 +13,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
 #include "pthreadP.h"
@@ -27,16 +26,19 @@ __pthread_setcanceltype (type, oldtype)
      int type;
      int *oldtype;
 {
-  volatile struct pthread *self;
-
   if (type < PTHREAD_CANCEL_DEFERRED || type > PTHREAD_CANCEL_ASYNCHRONOUS)
     return EINVAL;
 
-  self = THREAD_SELF;
+#ifndef SIGCANCEL
+  if (type == PTHREAD_CANCEL_ASYNCHRONOUS)
+    return ENOTSUP;
+#endif
+
+  volatile struct pthread *self = THREAD_SELF;
 
+  int oldval = THREAD_GETMEM (self, cancelhandling);
   while (1)
     {
-      int oldval = THREAD_GETMEM (self, cancelhandling);
       int newval = (type == PTHREAD_CANCEL_ASYNCHRONOUS
                    ? oldval | CANCELTYPE_BITMASK
                    : oldval & ~CANCELTYPE_BITMASK);
@@ -54,8 +56,9 @@ __pthread_setcanceltype (type, oldtype)
 
       /* Update the cancel handling word.  This has to be done
         atomically since other bits could be modified as well.  */
-      if (atomic_compare_and_exchange_acq (&self->cancelhandling, newval,
-                                          oldval) == 0)
+      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+                                             oldval);
+      if (__glibc_likely (curval == oldval))
        {
          if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
            {
@@ -65,6 +68,9 @@ __pthread_setcanceltype (type, oldtype)
 
          break;
        }
+
+      /* Prepare for the next round.  */
+      oldval = curval;
     }
 
   return 0;