sysdep-cancel.h 2.3 KB

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