struct_mutex.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Default mutex implementation struct definitions.
  2. Copyright (C) 2019-2026 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. #ifndef _THREAD_MUTEX_INTERNAL_H
  16. #define _THREAD_MUTEX_INTERNAL_H 1
  17. /* Generic struct for both POSIX and C11 mutexes. New ports are expected
  18. to use the default layout, however architecture can redefine it to
  19. add arch-specific extension. The struct have a size of 32 bytes on LP32
  20. and 40 bytes on LP64 architectures. */
  21. struct __pthread_mutex_s
  22. {
  23. int __lock __LOCK_ALIGNMENT;
  24. unsigned int __count;
  25. int __owner;
  26. #if __WORDSIZE == 64
  27. unsigned int __nusers;
  28. #endif
  29. /* KIND must stay at this position in the structure to maintain
  30. binary compatibility with static initializers.
  31. Concurrency notes:
  32. The __kind of a mutex is initialized either by the static
  33. PTHREAD_MUTEX_INITIALIZER or by a call to pthread_mutex_init.
  34. After a mutex has been initialized, the __kind of a mutex is usually not
  35. changed. BUT it can be set to -1 in pthread_mutex_destroy. */
  36. int __kind;
  37. #if __WORDSIZE != 64
  38. unsigned int __nusers;
  39. #endif
  40. #if __WORDSIZE == 64
  41. int __spins;
  42. __pthread_list_t __list;
  43. # define __PTHREAD_MUTEX_HAVE_PREV 1
  44. #else
  45. __extension__ union
  46. {
  47. int __spins;
  48. __pthread_slist_t __list;
  49. };
  50. # define __PTHREAD_MUTEX_HAVE_PREV 0
  51. #endif
  52. };
  53. #if __PTHREAD_MUTEX_HAVE_PREV == 1
  54. # define __PTHREAD_MUTEX_INITIALIZER(__kind) \
  55. 0, 0, 0, 0, __kind, 0, { 0, 0 }
  56. #else
  57. # define __PTHREAD_MUTEX_INITIALIZER(__kind) \
  58. 0, 0, 0, __kind, 0, { 0 }
  59. #endif
  60. #endif