pthreadtypes.h 4.4 KB

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