pthreadtypes.h 4.5 KB

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