| 1 | /* Single-thread optimization definitions. Linux version. |
| 2 | Copyright (C) 2017-2020 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of the GNU C Library. |
| 5 | |
| 6 | The GNU C Library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | The GNU C Library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with the GNU C Library; if not, see |
| 18 | <https://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #ifndef _SYSDEP_CANCEL_H |
| 21 | #define _SYSDEP_CANCEL_H |
| 22 | |
| 23 | #include <sysdep.h> |
| 24 | #include <tls.h> |
| 25 | #include <errno.h> |
| 26 | |
| 27 | /* The two functions are in libc.so and not exported. */ |
| 28 | extern int __libc_enable_asynccancel (void) attribute_hidden; |
| 29 | extern void __libc_disable_asynccancel (int oldtype) attribute_hidden; |
| 30 | |
| 31 | /* The two functions are in librt.so and not exported. */ |
| 32 | extern int __librt_enable_asynccancel (void) attribute_hidden; |
| 33 | extern void __librt_disable_asynccancel (int oldtype) attribute_hidden; |
| 34 | |
| 35 | /* The two functions are in libpthread.so and not exported. */ |
| 36 | extern int __pthread_enable_asynccancel (void) attribute_hidden; |
| 37 | extern void __pthread_disable_asynccancel (int oldtype) attribute_hidden; |
| 38 | |
| 39 | /* Set cancellation mode to asynchronous. */ |
| 40 | #define CANCEL_ASYNC() \ |
| 41 | __pthread_enable_asynccancel () |
| 42 | /* Reset to previous cancellation mode. */ |
| 43 | #define CANCEL_RESET(oldtype) \ |
| 44 | __pthread_disable_asynccancel (oldtype) |
| 45 | |
| 46 | #if IS_IN (libc) |
| 47 | /* Same as CANCEL_ASYNC, but for use in libc.so. */ |
| 48 | # define LIBC_CANCEL_ASYNC() \ |
| 49 | __libc_enable_asynccancel () |
| 50 | /* Same as CANCEL_RESET, but for use in libc.so. */ |
| 51 | # define LIBC_CANCEL_RESET(oldtype) \ |
| 52 | __libc_disable_asynccancel (oldtype) |
| 53 | #elif IS_IN (libpthread) |
| 54 | # define LIBC_CANCEL_ASYNC() CANCEL_ASYNC () |
| 55 | # define LIBC_CANCEL_RESET(val) CANCEL_RESET (val) |
| 56 | #elif IS_IN (librt) |
| 57 | # define LIBC_CANCEL_ASYNC() \ |
| 58 | __librt_enable_asynccancel () |
| 59 | # define LIBC_CANCEL_RESET(val) \ |
| 60 | __librt_disable_asynccancel (val) |
| 61 | #else |
| 62 | # define LIBC_CANCEL_ASYNC() 0 /* Just a dummy value. */ |
| 63 | # define LIBC_CANCEL_RESET(val) ((void)(val)) /* Nothing, but evaluate it. */ |
| 64 | #endif |
| 65 | |
| 66 | |
| 67 | #endif |
| 68 | |