From 1564916ab9ef4e2ce673cd5fb3123c067e4a787d Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 16 Feb 2003 09:18:53 +0000 Subject: Update. 2003-02-16 Ulrich Drepper * 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. --- nptl/libc-cancellation.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'nptl/libc-cancellation.c') 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 , 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; -- cgit v1.2.3