1 | /* Single-thread optimization definitions. Linux version. |
2 | Copyright (C) 2017-2019 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 | <http://www.gnu.org/licenses/>. */ |
19 | |
20 | #include <sysdep.h> |
21 | #include <tls.h> |
22 | #include <nptl/pthreadP.h> |
23 | |
24 | /* The default way to check if the process is single thread is by using the |
25 | pthread_t 'multiple_threads' field. However for some architectures it |
26 | is faster to either use an extra field on TCB or global varibles |
27 | (the TCB field is also used on x86 for some single-thread atomic |
28 | optimizations). |
29 | |
30 | The ABI might define SINGLE_THREAD_BY_GLOBAL to enable the single |
31 | thread check to use global variables instead of the pthread_t |
32 | field. */ |
33 | |
34 | #ifdef SINGLE_THREAD_BY_GLOBAL |
35 | # if IS_IN (libc) |
36 | extern int __libc_multiple_threads; |
37 | # define SINGLE_THREAD_P \ |
38 | __glibc_likely (__libc_multiple_threads == 0) |
39 | # elif IS_IN (libpthread) |
40 | extern int __pthread_multiple_threads; |
41 | # define SINGLE_THREAD_P \ |
42 | __glibc_likely (__pthread_multiple_threads == 0) |
43 | # elif IS_IN (librt) |
44 | # define SINGLE_THREAD_P \ |
45 | __glibc_likely (THREAD_GETMEM (THREAD_SELF, \ |
46 | header.multiple_threads) == 0) |
47 | # else |
48 | /* For rtld, et cetera. */ |
49 | # define SINGLE_THREAD_P (1) |
50 | # endif |
51 | #else /* SINGLE_THREAD_BY_GLOBAL */ |
52 | # if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt) |
53 | # define SINGLE_THREAD_P \ |
54 | __glibc_likely (THREAD_GETMEM (THREAD_SELF, \ |
55 | header.multiple_threads) == 0) |
56 | # else |
57 | /* For rtld, et cetera. */ |
58 | # define SINGLE_THREAD_P (1) |
59 | # endif |
60 | #endif /* SINGLE_THREAD_BY_GLOBAL */ |
61 | |
62 | #define RTLD_SINGLE_THREAD_P \ |
63 | __glibc_likely (THREAD_GETMEM (THREAD_SELF, \ |
64 | header.multiple_threads) == 0) |
65 | |