pthreadtypes.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_size_t
  20. #include <stddef.h>
  21. #define __need_schedparam
  22. #include <bits/sched.h>
  23. #define __SIZEOF_PTHREAD_CONDATTR_T 4
  24. /* Fast locks (not abstract because mutexes and conditions aren't abstract). */
  25. struct _pthread_fastlock
  26. {
  27. long int __status; /* "Free" or "taken" or head of waiting list */
  28. int __spinlock; /* Used by compare_and_swap emulation. Also,
  29. adaptive SMP lock stores spin count here. */
  30. };
  31. #ifndef _PTHREAD_DESCR_DEFINED
  32. /* Thread descriptors */
  33. typedef struct _pthread_descr_struct *_pthread_descr;
  34. # define _PTHREAD_DESCR_DEFINED
  35. #endif
  36. /* Attributes for threads. */
  37. typedef struct __pthread_attr_s
  38. {
  39. int __detachstate;
  40. int __schedpolicy;
  41. struct __sched_param __schedparam;
  42. int __inheritsched;
  43. int __scope;
  44. size_t __guardsize;
  45. int __stackaddr_set;
  46. void *__stackaddr;
  47. size_t __stacksize;
  48. } pthread_attr_t;
  49. /* Conditions (not abstract because of PTHREAD_COND_INITIALIZER */
  50. typedef struct
  51. {
  52. struct _pthread_fastlock __c_lock; /* Protect against concurrent access */
  53. _pthread_descr __c_waiting; /* Threads waiting on this condition */
  54. } pthread_cond_t;
  55. typedef union
  56. {
  57. char __size[__SIZEOF_PTHREAD_CONDATTR_T];
  58. int __align;
  59. } pthread_condattr_t;
  60. /* Keys for thread-specific data */
  61. typedef unsigned int pthread_key_t;
  62. /* Mutexes (not abstract because of PTHREAD_MUTEX_INITIALIZER). */
  63. /* (The layout is unnatural to maintain binary compatibility
  64. with earlier releases of LinuxThreads.) */
  65. typedef struct
  66. {
  67. int __m_reserved; /* Reserved for future use */
  68. int __m_count; /* Depth of recursive locking */
  69. _pthread_descr __m_owner; /* Owner thread (if recursive or errcheck) */
  70. int __m_kind; /* Mutex kind: fast, recursive or errcheck */
  71. struct _pthread_fastlock __m_lock; /* Underlying fast lock */
  72. } pthread_mutex_t;
  73. /* Attribute for mutex. */
  74. typedef struct
  75. {
  76. int __mutexkind;
  77. } pthread_mutexattr_t;
  78. /* Once-only execution */
  79. typedef int pthread_once_t;
  80. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  81. /* Read-write locks. */
  82. typedef struct _pthread_rwlock_t
  83. {
  84. struct _pthread_fastlock __rw_lock; /* Lock to guarantee mutual exclusion */
  85. int __rw_readers; /* Number of readers */
  86. _pthread_descr __rw_writer; /* Identity of writer, or NULL if none */
  87. _pthread_descr __rw_read_waiting; /* Threads waiting for reading */
  88. _pthread_descr __rw_write_waiting; /* Threads waiting for writing */
  89. int __rw_kind; /* Reader/Writer preference selection */
  90. int __rw_pshared; /* Shared between processes or not */
  91. } pthread_rwlock_t;
  92. /* Attribute for read-write locks. */
  93. typedef struct
  94. {
  95. int __lockkind;
  96. int __pshared;
  97. } pthread_rwlockattr_t;
  98. #endif
  99. #ifdef __USE_XOPEN2K
  100. /* POSIX spinlock data type. */
  101. typedef volatile int pthread_spinlock_t;
  102. /* POSIX barrier. */
  103. typedef struct {
  104. struct _pthread_fastlock __ba_lock; /* Lock to guarantee mutual exclusion */
  105. int __ba_required; /* Threads needed for completion */
  106. int __ba_present; /* Threads waiting */
  107. _pthread_descr __ba_waiting; /* Queue of waiting threads */
  108. } pthread_barrier_t;
  109. /* barrier attribute */
  110. typedef struct {
  111. int __pshared;
  112. } pthread_barrierattr_t;
  113. #endif
  114. /* Thread identifiers */
  115. typedef unsigned long int pthread_t;
  116. #endif /* bits/pthreadtypes.h */