pthread.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #ifndef _PTHREAD_H
  2. #define _PTHREAD_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define __NEED_time_t
  7. #define __NEED_struct_timespec
  8. #define __NEED_sigset_t
  9. #define __NEED_pthread_t
  10. #define __NEED_size_t
  11. #include <bits/alltypes.h>
  12. struct sched_param;
  13. typedef int pthread_once_t, pthread_key_t, pthread_spinlock_t;
  14. typedef int pthread_mutexattr_t, pthread_condattr_t, pthread_barrierattr_t;
  15. typedef struct {
  16. size_t __guardsize;
  17. size_t __stacksize;
  18. unsigned __detach : 1;
  19. unsigned __pad : 31;
  20. int __attr[6];
  21. } pthread_attr_t;
  22. typedef struct {
  23. int __attr[2];
  24. } pthread_rwlockattr_t;
  25. typedef struct {
  26. int __type;
  27. int __lock;
  28. pthread_t __owner;
  29. int __pad2;
  30. int __waiters;
  31. int __pad;
  32. } pthread_mutex_t;
  33. typedef struct {
  34. int __block;
  35. int __pad[11];
  36. } pthread_cond_t;
  37. typedef struct {
  38. int __wrlock;
  39. int __readers;
  40. int __waiters;
  41. int __owner;
  42. int __pad[4];
  43. } pthread_rwlock_t;
  44. typedef struct {
  45. int __count;
  46. int __limit;
  47. int __left;
  48. int __waiters;
  49. int __barrier[1];
  50. } pthread_barrier_t;
  51. #define PTHREAD_CREATE_JOINABLE 0
  52. #define PTHREAD_CREATE_DETACHED 1
  53. #define PTHREAD_MUTEX_NORMAL 0
  54. #define PTHREAD_MUTEX_DEFAULT 0
  55. #define PTHREAD_MUTEX_RECURSIVE 1
  56. #define PTHREAD_MUTEX_ERRORCHECK 2
  57. #define PTHREAD_MUTEX_STALLED 0
  58. #define PTHREAD_MUTEX_ROBUST 1
  59. #define PTHREAD_PRIO_NONE 0
  60. #define PTHREAD_PRIO_INHERIT 1
  61. #define PTHREAD_PRIO_PROTECT 2
  62. #define PTHREAD_INHERIT_SCHED 0
  63. #define PTHREAD_EXPLICIT_SCHED 1
  64. #define PTHREAD_SCOPE_SYSTEM 0
  65. #define PTHREAD_SCOPE_PROCESS 1
  66. #define PTHREAD_PROCESS_PRIVATE 0
  67. #define PTHREAD_PROCESS_SHARED 1
  68. #define PTHREAD_MUTEX_INITIALIZER {0}
  69. #define PTHREAD_RWLOCK_INITIALIZER {0}
  70. #define PTHREAD_COND_INITIALIZER {0}
  71. #define PTHREAD_ONCE_INIT 0
  72. #define PTHREAD_CANCEL_ENABLE 0
  73. #define PTHREAD_CANCEL_DISABLE 1
  74. #define PTHREAD_CANCEL_DEFERRED 0
  75. #define PTHREAD_CANCEL_ASYNCHRONOUS 1
  76. #define PTHREAD_CANCELLED ((void *)-1)
  77. #define PTHREAD_BARRIER_SERIAL_THREAD (-1)
  78. int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *);
  79. int pthread_detach(pthread_t);
  80. void pthread_exit(void *);
  81. int pthread_join(pthread_t, void **);
  82. pthread_t pthread_self(void);
  83. int pthread_equal(pthread_t, pthread_t);
  84. int pthread_setcancelstate(int, int *);
  85. int pthread_setcanceltype(int, int *);
  86. void pthread_testcancel(void);
  87. int pthread_cancel(pthread_t);
  88. int pthread_once(pthread_once_t *, void (*)(void));
  89. int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *);
  90. int pthread_mutex_lock(pthread_mutex_t *);
  91. int pthread_mutex_unlock(pthread_mutex_t *);
  92. int pthread_mutex_trylock(pthread_mutex_t *);
  93. int pthread_mutex_destroy(pthread_mutex_t *);
  94. int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *);
  95. int pthread_cond_destroy(pthread_cond_t *);
  96. int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
  97. int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *);
  98. int pthread_cond_broadcast(pthread_cond_t *);
  99. int pthread_cond_signal(pthread_cond_t *);
  100. int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *);
  101. int pthread_rwlock_destroy(pthread_rwlock_t *);
  102. int pthread_rwlock_rdlock(pthread_rwlock_t *);
  103. int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
  104. int pthread_rwlock_timedrdlock(pthread_rwlock_t *, const struct timespec *);
  105. int pthread_rwlock_wrlock(pthread_rwlock_t *);
  106. int pthread_rwlock_trywrlock(pthread_rwlock_t *);
  107. int pthread_rwlock_timedwrlock(pthread_rwlock_t *, const struct timespec *);
  108. int pthread_rwlock_unlock(pthread_rwlock_t *);
  109. int pthread_spin_init(pthread_spinlock_t *, int);
  110. int pthread_spin_destroy(pthread_spinlock_t *);
  111. int pthread_spin_lock(pthread_spinlock_t *);
  112. int pthread_spin_trylock(pthread_spinlock_t *);
  113. int pthread_spin_unlock(pthread_spinlock_t *);
  114. int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned);
  115. int pthread_barrier_destroy(pthread_barrier_t *);
  116. int pthread_barrier_wait(pthread_barrier_t *);
  117. int pthread_key_create(pthread_key_t *, void (*)(void *));
  118. int pthread_key_delete(pthread_key_t);
  119. void *pthread_getspecific(pthread_key_t);
  120. int pthread_setspecific(pthread_key_t, const void *);
  121. int pthread_attr_init(pthread_attr_t *);
  122. int pthread_attr_destroy(pthread_attr_t *);
  123. int pthread_attr_getguardsize(pthread_attr_t *, size_t *);
  124. int pthread_attr_setguardsize(pthread_attr_t *, size_t);
  125. int pthread_attr_getstacksize(pthread_attr_t *, size_t *);
  126. int pthread_attr_setstacksize(pthread_attr_t *, size_t);
  127. int pthread_attr_getdetachstate(pthread_attr_t *, int *);
  128. int pthread_attr_setdetachstate(pthread_attr_t *, int);
  129. int pthread_attr_getstack(pthread_attr_t *, void **, size_t *);
  130. int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
  131. int pthread_attr_getscope(pthread_attr_t *, int *);
  132. int pthread_attr_setscope(pthread_attr_t *, int);
  133. int pthread_attr_getschedpolicy(pthread_attr_t *, int *);
  134. int pthread_attr_setschedpolicy(pthread_attr_t *, int);
  135. int pthread_attr_getschedparam(pthread_attr_t *, struct sched_param *);
  136. int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *);
  137. int pthread_attr_getinheritsched(pthread_attr_t *, int *);
  138. int pthread_attr_setinheritsched(pthread_attr_t *, int);
  139. int pthread_mutexattr_destroy(pthread_mutexattr_t *);
  140. int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *, int *);
  141. int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *, int *);
  142. int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *);
  143. int pthread_mutexattr_getrobust(const pthread_mutexattr_t *, int *);
  144. int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *);
  145. int pthread_mutexattr_init(pthread_mutexattr_t *);
  146. int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
  147. int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
  148. int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
  149. int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
  150. int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
  151. int pthread_barrierattr_destroy(pthread_barrierattr_t *);
  152. int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *);
  153. int pthread_barrierattr_init(pthread_barrierattr_t *);
  154. int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
  155. #include <bits/pthread.h>
  156. int __setjmp(void *);
  157. void __pthread_register_cancel(struct __ptcb *);
  158. void __pthread_unregister_cancel(struct __ptcb *);
  159. void __pthread_unwind_next(struct __ptcb *);
  160. #define pthread_cleanup_push(f, x) \
  161. do { struct __ptcb __cb; void (*__f)(void *) = (f); void *__x = (x); \
  162. if (__setjmp(__cb.__jb)) __f(__x), __pthread_unwind_next(&__cb); \
  163. __pthread_register_cancel(&__cb); {
  164. #define pthread_cleanup_pop(r) ; } \
  165. __pthread_unregister_cancel(&__cb); \
  166. if (r) __f(__x); } while (0)
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. #endif