pthreadtypes.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. typedef struct
  48. {
  49. struct _pthread_fastlock __c_lock; /* Protect against concurrent access */
  50. _pthread_descr __c_waiting; /* Threads waiting on this condition */
  51. } pthread_cond_t;
  52. /* Attribute for conditionally variables. */
  53. typedef struct
  54. {
  55. int __dummy;
  56. } pthread_condattr_t;
  57. /* Keys for thread-specific data */
  58. typedef unsigned int pthread_key_t;
  59. /* Mutexes (not abstract because of PTHREAD_MUTEX_INITIALIZER). */
  60. /* (The layout is unnatural to maintain binary compatibility
  61. with earlier releases of LinuxThreads.) */
  62. typedef struct
  63. {
  64. int __m_reserved; /* Reserved for future use */
  65. int __m_count; /* Depth of recursive locking */
  66. _pthread_descr __m_owner; /* Owner thread (if recursive or errcheck) */
  67. int __m_kind; /* Mutex kind: fast, recursive or errcheck */
  68. struct _pthread_fastlock __m_lock; /* Underlying fast lock */
  69. } pthread_mutex_t;
  70. /* Attribute for mutex. */
  71. typedef struct
  72. {
  73. int __mutexkind;
  74. } pthread_mutexattr_t;
  75. /* Once-only execution */
  76. typedef int pthread_once_t;
  77. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  78. /* Read-write locks. */
  79. typedef struct _pthread_rwlock_t
  80. {
  81. struct _pthread_fastlock __rw_lock; /* Lock to guarantee mutual exclusion */
  82. int __rw_readers; /* Number of readers */
  83. _pthread_descr __rw_writer; /* Identity of writer, or NULL if none */
  84. _pthread_descr __rw_read_waiting; /* Threads waiting for reading */
  85. _pthread_descr __rw_write_waiting; /* Threads waiting for writing */
  86. int __rw_kind; /* Reader/Writer preference selection */
  87. int __rw_pshared; /* Shared between processes or not */
  88. } pthread_rwlock_t;
  89. /* Attribute for read-write locks. */
  90. typedef struct
  91. {
  92. int __lockkind;
  93. int __pshared;
  94. } pthread_rwlockattr_t;
  95. #endif
  96. #ifdef __USE_XOPEN2K
  97. /* POSIX spinlock data type. */
  98. typedef volatile int pthread_spinlock_t;
  99. /* POSIX barrier. */
  100. typedef struct {
  101. struct _pthread_fastlock __ba_lock; /* Lock to guarantee mutual exclusion */
  102. int __ba_required; /* Threads needed for completion */
  103. int __ba_present; /* Threads waiting */
  104. _pthread_descr __ba_waiting; /* Queue of waiting threads */
  105. } pthread_barrier_t;
  106. /* barrier attribute */
  107. typedef struct {
  108. int __pshared;
  109. } pthread_barrierattr_t;
  110. #endif
  111. /* Thread identifiers */
  112. typedef unsigned long int pthread_t;
  113. #endif /* bits/pthreadtypes.h */