zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

single-thread.h (1699B) - Raw


      1 /* Single thread optimization, Linux version.
      2    Copyright (C) 2019-2025 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 #ifndef __ASSEMBLER__
     23 # include <sys/single_threaded.h>
     24 #endif
     25 
     26 /* The default way to check if the process is single thread is by using the
     27    pthread_t 'multiple_threads' field.  However, for some architectures it is
     28    faster to either use an extra field on TCB or global variables (the TCB
     29    field is also used on x86 for some single-thread atomic optimizations).
     30 
     31    The ABI might define SINGLE_THREAD_BY_GLOBAL to enable the single thread
     32    check to use global variables instead of the pthread_t field.  */
     33 
     34 #if !defined SINGLE_THREAD_BY_GLOBAL || IS_IN (rtld)
     35 # define SINGLE_THREAD_P \
     36   (THREAD_GETMEM (THREAD_SELF, header.multiple_threads) == 0)
     37 #else
     38 # define SINGLE_THREAD_P (__libc_single_threaded_internal != 0)
     39 #endif
     40 
     41 #define RTLD_SINGLE_THREAD_P SINGLE_THREAD_P
     42 
     43 #endif /* _SINGLE_THREAD_H  */