threads.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #define thrd_equal(A, B) ((A) == (B))
  42. void call_once(once_flag *, void (*)(void));
  43. int mtx_init(mtx_t *, int);
  44. void mtx_destroy(mtx_t *);
  45. int mtx_lock(mtx_t *);
  46. int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict);
  47. int mtx_trylock(mtx_t *);
  48. int mtx_unlock(mtx_t *);
  49. int cnd_init(cnd_t *);
  50. void cnd_destroy(cnd_t *);
  51. int cnd_broadcast(cnd_t *);
  52. int cnd_signal(cnd_t *);
  53. int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *__restrict);
  54. int cnd_wait(cnd_t *, mtx_t *);
  55. int tss_create(tss_t *, tss_dtor_t);
  56. void tss_delete(tss_t key);
  57. int tss_set(tss_t, void *);
  58. void *tss_get(tss_t);
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif