1/* Single thread optimization, Linux version.
2 Copyright (C) 2019-2022 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#ifndef __ASSEMBLER__
31extern int __libc_multiple_threads;
32libc_hidden_proto (__libc_multiple_threads)
33#endif
34
35#if !defined SINGLE_THREAD_BY_GLOBAL || IS_IN (rtld)
36# define SINGLE_THREAD_P \
37 (THREAD_GETMEM (THREAD_SELF, header.multiple_threads) == 0)
38#else
39# define SINGLE_THREAD_P (__libc_multiple_threads == 0)
40#endif
41
42#define RTLD_SINGLE_THREAD_P SINGLE_THREAD_P
43
44#endif /* _SINGLE_THREAD_H */
45

source code of glibc/sysdeps/unix/sysv/linux/single-thread.h