threads.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef _THREADS_H
  2. #define _THREADS_H
  3. #include <features.h>
  4. #include <time.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. typedef unsigned long thrd_t;
  8. #else
  9. typedef struct __pthread *thrd_t;
  10. #define thread_local _Thread_local
  11. #endif
  12. typedef int once_flag;
  13. typedef unsigned tss_t;
  14. typedef int (*thrd_start_t)(void *);
  15. typedef void (*tss_dtor_t)(void *);
  16. #define __NEED_cnd_t
  17. #define __NEED_mtx_t
  18. #include <bits/alltypes.h>
  19. #define TSS_DTOR_ITERATIONS 4
  20. enum {
  21. thrd_success = 0,
  22. thrd_busy = 1,
  23. thrd_error = 2,
  24. thrd_nomem = 3,
  25. thrd_timedout = 4,
  26. };
  27. enum {
  28. mtx_plain = 0,
  29. mtx_recursive = 1,
  30. mtx_timed = 2,
  31. };
  32. #define ONCE_FLAG_INIT 0
  33. int thrd_create(thrd_t *, thrd_start_t, void *);
  34. _Noreturn void thrd_exit(int);
  35. int thrd_detach(thrd_t);
  36. int thrd_join(thrd_t, int *);
  37. int thrd_sleep(const struct timespec *, struct timespec *);
  38. void thrd_yield(void);
  39. thrd_t thrd_current(void);
  40. int thrd_equal(thrd_t, thrd_t);
  41. #ifndef __cplusplus
  42. #define thrd_equal(A, B) ((A) == (B))
  43. #endif
  44. void call_once(once_flag *, void (*)(void));
  45. int mtx_init(mtx_t *, int);
  46. void mtx_destroy(mtx_t *);
  47. int mtx_lock(mtx_t *);
  48. int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict);
  49. int mtx_trylock(mtx_t *);
  50. int mtx_unlock(mtx_t *);
  51. int cnd_init(cnd_t *);
  52. void cnd_destroy(cnd_t *);
  53. int cnd_broadcast(cnd_t *);
  54. int cnd_signal(cnd_t *);
  55. int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *__restrict);
  56. int cnd_wait(cnd_t *, mtx_t *);
  57. int tss_create(tss_t *, tss_dtor_t);
  58. void tss_delete(tss_t);
  59. int tss_set(tss_t, void *);
  60. void *tss_get(tss_t);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif