aboutsummaryrefslogtreecommitdiff
path: root/nptl/pthread_setcanceltype.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-03-31 17:24:39 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-06-09 15:16:45 -0300
commit8c1c0aae2079039a629b15098d78f3d11aabefb4 (patch)
tree72a4a714ee7310810a0d2a5778e6b5c40f18fa85 /nptl/pthread_setcanceltype.c
parent2b5174253155bdace1262ea2ab53d11347ecdefd (diff)
downloadglibc-8c1c0aae2079039a629b15098d78f3d11aabefb4.zip
glibc-8c1c0aae2079039a629b15098d78f3d11aabefb4.tar.gz
glibc-8c1c0aae2079039a629b15098d78f3d11aabefb4.tar.bz2
nptl: Move cancel type out of cancelhandling
Now that the thread cancellation type is not accessed concurrently anymore, it is possible to move it out the cancelhandling. By removing the cancel state out of the internal thread cancel handling state there is no need to check if cancelled bit was set in CAS operation. It allows simplifing the cancellation wrappers and the CANCEL_CANCELED_AND_ASYNCHRONOUS is removed. Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Diffstat (limited to 'nptl/pthread_setcanceltype.c')
-rw-r--r--nptl/pthread_setcanceltype.c42
1 files changed, 5 insertions, 37 deletions
diff --git a/nptl/pthread_setcanceltype.c b/nptl/pthread_setcanceltype.c
index ae5df1d..e7b24ae 100644
--- a/nptl/pthread_setcanceltype.c
+++ b/nptl/pthread_setcanceltype.c
@@ -29,43 +29,11 @@ __pthread_setcanceltype (int type, int *oldtype)
volatile struct pthread *self = THREAD_SELF;
- int oldval = THREAD_GETMEM (self, cancelhandling);
- while (1)
- {
- int newval = (type == PTHREAD_CANCEL_ASYNCHRONOUS
- ? oldval | CANCELTYPE_BITMASK
- : oldval & ~CANCELTYPE_BITMASK);
-
- /* Store the old value. */
- if (oldtype != NULL)
- *oldtype = ((oldval & CANCELTYPE_BITMASK)
- ? PTHREAD_CANCEL_ASYNCHRONOUS : PTHREAD_CANCEL_DEFERRED);
-
- /* Avoid doing unnecessary work. The atomic operation can
- potentially be expensive if the memory has to be locked and
- remote cache lines have to be invalidated. */
- if (oldval == newval)
- break;
-
- /* Update the cancel handling word. This has to be done
- atomically since other bits could be modified as well. */
- int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
- oldval);
- if (__glibc_likely (curval == oldval))
- {
- if (self->cancelstate == PTHREAD_CANCEL_ENABLE
- && CANCEL_CANCELED_AND_ASYNCHRONOUS (newval))
- {
- THREAD_SETMEM (self, result, PTHREAD_CANCELED);
- __do_cancel ();
- }
-
- break;
- }
-
- /* Prepare for the next round. */
- oldval = curval;
- }
+ if (oldtype != NULL)
+ *oldtype = self->canceltype;
+ self->canceltype = type;
+ if (type == PTHREAD_CANCEL_ASYNCHRONOUS)
+ __pthread_testcancel ();
return 0;
}