pthreadtypes.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Linuxthreads - a simple clone()-based implementation of Posix */
  2. /* threads for Linux. */
  3. /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
  4. /* */
  5. /* This program is free software; you can redistribute it and/or */
  6. /* modify it under the terms of the GNU Library General Public License */
  7. /* as published by the Free Software Foundation; either version 2 */
  8. /* of the License, or (at your option) any later version. */
  9. /* */
  10. /* This program 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 */
  13. /* GNU Library General Public License for more details. */
  14. #if !defined _BITS_TYPES_H && !defined _PTHREAD_H
  15. # error "Never include <bits/pthreadtypes.h> directly; use <sys/types.h> instead."
  16. #endif
  17. #ifndef _BITS_PTHREADTYPES_H
  18. #define _BITS_PTHREADTYPES_H 1
  19. #define __need_schedparam
  20. #include <bits/sched.h>
  21. /* Fast locks (not abstract because mutexes and conditions aren't abstract). */
  22. struct _pthread_fastlock
  23. {
  24. long int __status; /* "Free" or "taken" or head of waiting list */
  25. int __spinlock; /* Used by compare_and_swap emulation. Also,
  26. adaptive SMP lock stores spin count here. */
  27. };
  28. #ifndef _PTHREAD_DESCR_DEFINED
  29. /* Thread descriptors */
  30. typedef struct _pthread_descr_struct *_pthread_descr;
  31. # define _PTHREAD_DESCR_DEFINED
  32. #endif
  33. /* Attributes for threads. */
  34. typedef struct __pthread_attr_s
  35. {
  36. int __detachstate;
  37. int __schedpolicy;
  38. struct __sched_param __schedparam;
  39. int __inheritsched;
  40. int __scope;
  41. size_t __guardsize;
  42. int __stackaddr_set;
  43. void *__stackaddr;
  44. size_t __stacksize;
  45. } pthread_attr_t;
  46. /* Conditions (not abstract because of PTHREAD_COND_INITIALIZER */
  47. #ifdef __GLIBC_HAVE_LONG_LONG
  48. __extension__ typedef long long __pthread_cond_align_t;
  49. #else
  50. typedef long __pthread_cond_align_t;
  51. #endif
  52. typedef struct
  53. {
  54. struct _pthread_fastlock __c_lock; /* Protect against concurrent access */
  55. _pthread_descr __c_waiting; /* Threads waiting on this condition */
  56. char __padding[48 - sizeof (struct _pthread_fastlock)
  57. - sizeof (_pthread_descr) - sizeof (__pthread_cond_align_t)];
  58. __pthread_cond_align_t __align;
  59. } pthread_cond_t;
  60. /* Attribute for conditionally variables. */
  61. typedef struct
  62. {
  63. int __dummy;
  64. } pthread_condattr_t;
  65. /* Keys for thread-specific data */
  66. typedef unsigned int pthread_key_t;
  67. /* Mutexes (not abstract because of PTHREAD_MUTEX_INITIALIZER). */
  68. /* (The layout is unnatural to maintain binary compatibility
  69. with earlier releases of LinuxThreads.) */
  70. typedef struct
  71. {
  72. int __m_reserved; /* Reserved for future use */
  73. int __m_count; /* Depth of recursive locking */
  74. _pthread_descr __m_owner; /* Owner thread (if recursive or errcheck) */
  75. int __m_kind; /* Mutex kind: fast, recursive or errcheck */
  76. struct _pthread_fastlock __m_lock; /* Underlying fast lock */
  77. } pthread_mutex_t;
  78. /* Attribute for mutex. */
  79. typedef struct
  80. {
  81. int __mutexkind;
  82. } pthread_mutexattr_t;
  83. /* Once-only execution */
  84. typedef int pthread_once_t;
  85. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  86. /* Read-write locks. */
  87. typedef struct _pthread_rwlock_t
  88. {
  89. struct _pthread_fastlock __rw_lock; /* Lock to guarantee mutual exclusion */
  90. int __rw_readers; /* Number of readers */
  91. _pthread_descr __rw_writer; /* Identity of writer, or NULL if none */
  92. _pthread_descr __rw_read_waiting; /* Threads waiting for reading */
  93. _pthread_descr __rw_write_waiting; /* Threads waiting for writing */
  94. int __rw_kind; /* Reader/Writer preference selection */
  95. int __rw_pshared; /* Shared between processes or not */
  96. } pthread_rwlock_t;
  97. /* Attribute for read-write locks. */
  98. typedef struct
  99. {
  100. int __lockkind;
  101. int __pshared;
  102. } pthread_rwlockattr_t;
  103. #endif
  104. #ifdef __USE_XOPEN2K
  105. /* POSIX spinlock data type. */
  106. typedef __volatile__ int pthread_spinlock_t;
  107. /* POSIX barrier. */
  108. typedef struct {
  109. struct _pthread_fastlock __ba_lock; /* Lock to guarantee mutual exclusion */
  110. int __ba_required; /* Threads needed for completion */
  111. int __ba_present; /* Threads waiting */
  112. _pthread_descr __ba_waiting; /* Queue of waiting threads */
  113. } pthread_barrier_t;
  114. /* barrier attribute */
  115. typedef struct {
  116. int __pshared;
  117. } pthread_barrierattr_t;
  118. #endif
  119. /* Thread identifiers */
  120. typedef unsigned long int pthread_t;
  121. #endif /* bits/pthreadtypes.h */