threads.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*-
  2. * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. */
  26. #ifndef _THREADS_H_
  27. #define _THREADS_H_
  28. #include <machine/_threads.h>
  29. #include <time.h>
  30. typedef void (*tss_dtor_t)(void *);
  31. typedef int (*thrd_start_t)(void *);
  32. enum {
  33. mtx_plain = 0x1,
  34. mtx_recursive = 0x2,
  35. mtx_timed = 0x4
  36. };
  37. enum {
  38. thrd_busy = 1,
  39. thrd_error = 2,
  40. thrd_nomem = 3,
  41. thrd_success = 4,
  42. thrd_timedout = 5
  43. };
  44. #if !defined(__cplusplus) || __cplusplus < 201103L
  45. #define thread_local _Thread_local
  46. #endif
  47. __BEGIN_DECLS
  48. void call_once(once_flag *, void (*)(void));
  49. int cnd_broadcast(cnd_t *);
  50. void cnd_destroy(cnd_t *);
  51. int cnd_init(cnd_t *);
  52. int cnd_signal(cnd_t *);
  53. int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict __mtx,
  54. const struct timespec *__restrict)
  55. __requires_exclusive(*__mtx);
  56. int cnd_wait(cnd_t *, mtx_t *__mtx)
  57. __requires_exclusive(*__mtx);
  58. void mtx_destroy(mtx_t *__mtx)
  59. __requires_unlocked(*__mtx);
  60. int mtx_init(mtx_t *__mtx, int)
  61. __requires_unlocked(*__mtx);
  62. int mtx_lock(mtx_t *__mtx)
  63. __locks_exclusive(*__mtx);
  64. int mtx_timedlock(mtx_t *__restrict __mtx,
  65. const struct timespec *__restrict)
  66. __trylocks_exclusive(thrd_success, *__mtx);
  67. int mtx_trylock(mtx_t *__mtx)
  68. __trylocks_exclusive(thrd_success, *__mtx);
  69. int mtx_unlock(mtx_t *__mtx)
  70. __unlocks(*__mtx);
  71. int thrd_create(thrd_t *, thrd_start_t, void *);
  72. thrd_t thrd_current(void);
  73. int thrd_detach(thrd_t);
  74. int thrd_equal(thrd_t, thrd_t);
  75. _Noreturn void
  76. thrd_exit(int);
  77. int thrd_join(thrd_t, int *);
  78. int thrd_sleep(const struct timespec *, struct timespec *);
  79. void thrd_yield(void);
  80. int tss_create(tss_t *, tss_dtor_t);
  81. void tss_delete(tss_t);
  82. void * tss_get(tss_t);
  83. int tss_set(tss_t, void *);
  84. __END_DECLS
  85. #endif /* !_THREADS_H_ */