pthread.h 6.7 KB

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