1 | /* Single thread optimization, Linux version. |
2 | Copyright (C) 2019-2021 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #ifndef _SINGLE_THREAD_H |
20 | #define _SINGLE_THREAD_H |
21 | |
22 | /* The default way to check if the process is single thread is by using the |
23 | pthread_t 'multiple_threads' field. However, for some architectures it is |
24 | faster to either use an extra field on TCB or global variables (the TCB |
25 | field is also used on x86 for some single-thread atomic optimizations). |
26 | |
27 | The ABI might define SINGLE_THREAD_BY_GLOBAL to enable the single thread |
28 | check to use global variables instead of the pthread_t field. */ |
29 | |
30 | #ifdef SINGLE_THREAD_BY_GLOBAL |
31 | # if IS_IN (libc) |
32 | extern int __libc_multiple_threads; |
33 | # define SINGLE_THREAD_P \ |
34 | __glibc_likely (__libc_multiple_threads == 0) |
35 | # elif IS_IN (libpthread) |
36 | extern int __pthread_multiple_threads; |
37 | # define SINGLE_THREAD_P \ |
38 | __glibc_likely (__pthread_multiple_threads == 0) |
39 | # elif IS_IN (librt) |
40 | # define SINGLE_THREAD_P \ |
41 | __glibc_likely (THREAD_GETMEM (THREAD_SELF, \ |
42 | header.multiple_threads) == 0) |
43 | # else |
44 | /* For rtld, et cetera. */ |
45 | # define SINGLE_THREAD_P (1) |
46 | # endif |
47 | #else /* SINGLE_THREAD_BY_GLOBAL */ |
48 | # if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt) |
49 | # define SINGLE_THREAD_P \ |
50 | __glibc_likely (THREAD_GETMEM (THREAD_SELF, \ |
51 | header.multiple_threads) == 0) |
52 | # else |
53 | /* For rtld, et cetera. */ |
54 | # define SINGLE_THREAD_P (1) |
55 | # endif |
56 | #endif /* SINGLE_THREAD_BY_GLOBAL */ |
57 | |
58 | #define RTLD_SINGLE_THREAD_P \ |
59 | __glibc_likely (THREAD_GETMEM (THREAD_SELF, \ |
60 | header.multiple_threads) == 0) |
61 | |
62 | #endif /* _SINGLE_THREAD_H */ |
63 | |