aboutsummaryrefslogtreecommitdiff
path: root/nptl/pthread_testcancel.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-03-31 15:43:25 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-06-09 15:16:45 -0300
commit2b5174253155bdace1262ea2ab53d11347ecdefd (patch)
tree9992336533dec0f8cd9579e217b7bc7a18d0733e /nptl/pthread_testcancel.c
parent26cfbb7162ad364d53d69f6d482f2d87b5950524 (diff)
downloadglibc-2b5174253155bdace1262ea2ab53d11347ecdefd.zip
glibc-2b5174253155bdace1262ea2ab53d11347ecdefd.tar.gz
glibc-2b5174253155bdace1262ea2ab53d11347ecdefd.tar.bz2
nptl: Move cancel state out of cancelhandling
Now that thread cancellation state is not accessed concurrently anymore, it is possible to move it out the 'cancelhandling'. The code is also simplified: CANCELLATION_P is replaced with a internal pthread_testcancel call and the CANCELSTATE_BIT{MASK} is removed. With this behavior pthread_setcancelstate does not require to act on cancellation if cancel type is asynchronous (is already handled either by pthread_setcanceltype or by the signal handler). Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Diffstat (limited to 'nptl/pthread_testcancel.c')
-rw-r--r--nptl/pthread_testcancel.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/nptl/pthread_testcancel.c b/nptl/pthread_testcancel.c
index a9e941d..9203746 100644
--- a/nptl/pthread_testcancel.c
+++ b/nptl/pthread_testcancel.c
@@ -23,7 +23,16 @@
void
___pthread_testcancel (void)
{
- CANCELLATION_P (THREAD_SELF);
+ struct pthread *self = THREAD_SELF;
+ int cancelhandling = THREAD_GETMEM (self, cancelhandling);
+ if (self->cancelstate == PTHREAD_CANCEL_ENABLE
+ && (cancelhandling & CANCELED_BITMASK)
+ && !(cancelhandling & EXITING_BITMASK)
+ && !(cancelhandling & TERMINATED_BITMASK))
+ {
+ THREAD_SETMEM (self, result, PTHREAD_CANCELED);
+ __do_cancel ();
+ }
}
versioned_symbol (libc, ___pthread_testcancel, pthread_testcancel, GLIBC_2_34);
versioned_symbol (libc, ___pthread_testcancel, __pthread_testcancel,