pthreadtypes.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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 _BITS_PTHREADTYPES_H
  16. #define _BITS_PTHREADTYPES_H 1
  17. #include <bits/wordsize.h>
  18. #if __WORDSIZE == 64
  19. # define __SIZEOF_PTHREAD_ATTR_T 56
  20. # define __SIZEOF_PTHREAD_MUTEX_T 40
  21. # define __SIZEOF_PTHREAD_MUTEXATTR_T 4
  22. # define __SIZEOF_PTHREAD_COND_T 48
  23. # define __SIZEOF_PTHREAD_CONDATTR_T 4
  24. # define __SIZEOF_PTHREAD_RWLOCK_T 56
  25. # define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
  26. # define __SIZEOF_PTHREAD_BARRIER_T 32
  27. # define __SIZEOF_PTHREAD_BARRIERATTR_T 4
  28. #else
  29. # define __SIZEOF_PTHREAD_ATTR_T 36
  30. # define __SIZEOF_PTHREAD_MUTEX_T 24
  31. # define __SIZEOF_PTHREAD_MUTEXATTR_T 4
  32. # define __SIZEOF_PTHREAD_COND_T 48
  33. # define __SIZEOF_PTHREAD_CONDATTR_T 4
  34. # define __SIZEOF_PTHREAD_RWLOCK_T 32
  35. # define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
  36. # define __SIZEOF_PTHREAD_BARRIER_T 20
  37. # define __SIZEOF_PTHREAD_BARRIERATTR_T 4
  38. #endif
  39. /* Thread identifiers. The structure of the attribute type is not
  40. exposed on purpose. */
  41. typedef unsigned long int pthread_t;
  42. typedef union
  43. {
  44. char __size[__SIZEOF_PTHREAD_ATTR_T];
  45. long int __align;
  46. } pthread_attr_t;
  47. #if __WORDSIZE == 64
  48. typedef struct __pthread_internal_list
  49. {
  50. struct __pthread_internal_list *__prev;
  51. struct __pthread_internal_list *__next;
  52. } __pthread_list_t;
  53. #else
  54. typedef struct __pthread_internal_slist
  55. {
  56. struct __pthread_internal_slist *__next;
  57. } __pthread_slist_t;
  58. #endif
  59. /* Data structures for mutex handling. The structure of the attribute
  60. type is not exposed on purpose. */
  61. typedef union
  62. {
  63. struct __pthread_mutex_s
  64. {
  65. int __lock;
  66. unsigned int __count;
  67. int __owner;
  68. #if __WORDSIZE == 64
  69. unsigned int __nusers;
  70. #endif
  71. /* KIND must stay at this position in the structure to maintain
  72. binary compatibility. */
  73. int __kind;
  74. #if __WORDSIZE == 64
  75. int __spins;
  76. __pthread_list_t __list;
  77. # define __PTHREAD_MUTEX_HAVE_PREV 1
  78. #else
  79. unsigned int __nusers;
  80. __extension__ union
  81. {
  82. int __spins;
  83. __pthread_slist_t __list;
  84. };
  85. #endif
  86. } __data;
  87. char __size[__SIZEOF_PTHREAD_MUTEX_T];
  88. long int __align;
  89. } pthread_mutex_t;
  90. typedef union
  91. {
  92. char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
  93. int __align;
  94. } pthread_mutexattr_t;
  95. /* Data structure for conditional variable handling. The structure of
  96. the attribute type is not exposed on purpose. */
  97. typedef union
  98. {
  99. struct
  100. {
  101. int __lock;
  102. unsigned int __futex;
  103. __extension__ unsigned long long int __total_seq;
  104. __extension__ unsigned long long int __wakeup_seq;
  105. __extension__ unsigned long long int __woken_seq;
  106. void *__mutex;
  107. unsigned int __nwaiters;
  108. unsigned int __broadcast_seq;
  109. } __data;
  110. char __size[__SIZEOF_PTHREAD_COND_T];
  111. __extension__ long long int __align;
  112. } pthread_cond_t;
  113. typedef union
  114. {
  115. char __size[__SIZEOF_PTHREAD_CONDATTR_T];
  116. int __align;
  117. } pthread_condattr_t;
  118. /* Keys for thread-specific data */
  119. typedef unsigned int pthread_key_t;
  120. /* Once-only execution */
  121. typedef int pthread_once_t;
  122. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  123. /* Data structure for read-write lock variable handling. The
  124. structure of the attribute type is not exposed on purpose. */
  125. typedef union
  126. {
  127. # if __WORDSIZE == 64
  128. struct
  129. {
  130. int __lock;
  131. unsigned int __nr_readers;
  132. unsigned int __readers_wakeup;
  133. unsigned int __writer_wakeup;
  134. unsigned int __nr_readers_queued;
  135. unsigned int __nr_writers_queued;
  136. int __writer;
  137. int __shared;
  138. unsigned long int __pad1;
  139. unsigned long int __pad2;
  140. /* FLAGS must stay at this position in the structure to maintain
  141. binary compatibility. */
  142. unsigned int __flags;
  143. } __data;
  144. # else
  145. struct
  146. {
  147. int __lock;
  148. unsigned int __nr_readers;
  149. unsigned int __readers_wakeup;
  150. unsigned int __writer_wakeup;
  151. unsigned int __nr_readers_queued;
  152. unsigned int __nr_writers_queued;
  153. /* FLAGS must stay at this position in the structure to maintain
  154. binary compatibility. */
  155. unsigned char __flags;
  156. unsigned char __shared;
  157. unsigned char __pad1;
  158. unsigned char __pad2;
  159. int __writer;
  160. } __data;
  161. # endif
  162. char __size[__SIZEOF_PTHREAD_RWLOCK_T];
  163. long int __align;
  164. } pthread_rwlock_t;
  165. typedef union
  166. {
  167. char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
  168. long int __align;
  169. } pthread_rwlockattr_t;
  170. #endif
  171. #ifdef __USE_XOPEN2K
  172. /* POSIX spinlock data type. */
  173. typedef volatile int pthread_spinlock_t;
  174. /* POSIX barriers data type. The structure of the type is
  175. deliberately not exposed. */
  176. typedef union
  177. {
  178. char __size[__SIZEOF_PTHREAD_BARRIER_T];
  179. long int __align;
  180. } pthread_barrier_t;
  181. typedef union
  182. {
  183. char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
  184. int __align;
  185. } pthread_barrierattr_t;
  186. #endif
  187. #if __WORDSIZE == 32
  188. /* Extra attributes for the cleanup functions. */
  189. # define __cleanup_fct_attribute __attribute__ ((__regparm__ (1)))
  190. #endif
  191. #endif /* bits/pthreadtypes.h */