]>
Commit | Line | Data |
---|---|---|
dff8da6b | 1 | /* Copyright (C) 2002-2024 Free Software Foundation, Inc. |
76a50749 | 2 | This file is part of the GNU C Library. |
76a50749 UD |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
76a50749 | 17 | |
6efd4814 | 18 | #include <stdlib.h> |
76a50749 | 19 | #include "pthreadP.h" |
c4c53e0f | 20 | #include <shlib-compat.h> |
76a50749 UD |
21 | |
22 | void | |
6efd4814 | 23 | __cleanup_fct_attribute |
c4c53e0f | 24 | ___pthread_register_cancel_defer (__pthread_unwind_buf_t *buf) |
76a50749 | 25 | { |
6efd4814 | 26 | struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf; |
76a50749 UD |
27 | struct pthread *self = THREAD_SELF; |
28 | ||
6efd4814 UD |
29 | /* Store old info. */ |
30 | ibuf->priv.data.prev = THREAD_GETMEM (self, cleanup_jmp_buf); | |
31 | ibuf->priv.data.cleanup = THREAD_GETMEM (self, cleanup); | |
76a50749 | 32 | |
40465600 AZ |
33 | int cancelhandling = atomic_load_relaxed (&self->cancelhandling); |
34 | if (__glibc_unlikely (cancelhandling & CANCELTYPE_BITMASK)) | |
35 | { | |
36 | int newval; | |
37 | do | |
38 | { | |
39 | newval = cancelhandling & ~CANCELTYPE_BITMASK; | |
40 | } | |
41 | while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling, | |
42 | &cancelhandling, | |
43 | newval)); | |
44 | } | |
45 | ||
46 | ibuf->priv.data.canceltype = (cancelhandling & CANCELTYPE_BITMASK | |
47 | ? PTHREAD_CANCEL_ASYNCHRONOUS | |
48 | : PTHREAD_CANCEL_DEFERRED); | |
76a50749 | 49 | |
6efd4814 | 50 | /* Store the new cleanup handler info. */ |
49b65043 | 51 | THREAD_SETMEM (self, cleanup_jmp_buf, (struct pthread_unwind_buf *) buf); |
76a50749 | 52 | } |
c4c53e0f FW |
53 | versioned_symbol (libc, ___pthread_register_cancel_defer, |
54 | __pthread_register_cancel_defer, GLIBC_2_34); | |
76a50749 | 55 | |
c4c53e0f FW |
56 | #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_34) |
57 | compat_symbol (libpthread, ___pthread_register_cancel_defer, | |
58 | __pthread_register_cancel_defer, GLIBC_2_3_3); | |
59 | #endif | |
b22d701b | 60 | |
76a50749 | 61 | void |
6efd4814 | 62 | __cleanup_fct_attribute |
c4c53e0f | 63 | ___pthread_unregister_cancel_restore (__pthread_unwind_buf_t *buf) |
76a50749 UD |
64 | { |
65 | struct pthread *self = THREAD_SELF; | |
6efd4814 | 66 | struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf; |
76a50749 | 67 | |
6efd4814 | 68 | THREAD_SETMEM (self, cleanup_jmp_buf, ibuf->priv.data.prev); |
76a50749 | 69 | |
40465600 AZ |
70 | if (ibuf->priv.data.canceltype == PTHREAD_CANCEL_DEFERRED) |
71 | return; | |
72 | ||
73 | int cancelhandling = atomic_load_relaxed (&self->cancelhandling); | |
f27e5e21 | 74 | if ((cancelhandling & CANCELTYPE_BITMASK) == 0) |
40465600 AZ |
75 | { |
76 | int newval; | |
77 | do | |
78 | { | |
79 | newval = cancelhandling | CANCELTYPE_BITMASK; | |
80 | } | |
81 | while (!atomic_compare_exchange_weak_acquire (&self->cancelhandling, | |
82 | &cancelhandling, newval)); | |
83 | ||
84 | if (cancel_enabled_and_canceled (cancelhandling)) | |
85 | { | |
86 | self->result = PTHREAD_CANCELED; | |
87 | __do_cancel (); | |
88 | } | |
89 | } | |
76a50749 | 90 | } |
c4c53e0f FW |
91 | versioned_symbol (libc, ___pthread_unregister_cancel_restore, |
92 | __pthread_unregister_cancel_restore, GLIBC_2_34); | |
93 | ||
94 | #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_3_3, GLIBC_2_34) | |
95 | compat_symbol (libpthread, ___pthread_unregister_cancel_restore, | |
96 | __pthread_unregister_cancel_restore, GLIBC_2_3_3); | |
97 | #endif |