gthr-rtems.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* RTEMS threads compatibility routines for libgcc2 and libobjc.
  2. by: Rosimildo da Silva( rdasilva@connecttel.com ) */
  3. /* Compile this one with gcc. */
  4. /* Copyright (C) 1997-2022 Free Software Foundation, Inc.
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 3, or (at your option) any later
  9. version.
  10. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. for more details.
  14. Under Section 7 of GPL version 3, you are granted additional
  15. permissions described in the GCC Runtime Library Exception, version
  16. 3.1, as published by the Free Software Foundation.
  17. You should have received a copy of the GNU General Public License and
  18. a copy of the GCC Runtime Library Exception along with this program;
  19. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. <http://www.gnu.org/licenses/>. */
  21. #ifndef GCC_GTHR_RTEMS_H
  22. #define GCC_GTHR_RTEMS_H
  23. #include <sys/lock.h>
  24. #include <pthread.h>
  25. #include <sched.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #define __GTHREADS 1
  30. #define __GTHREADS_CXX0X 1
  31. #define __GTHREAD_HAS_COND 1
  32. typedef pthread_t __gthread_t;
  33. typedef pthread_key_t __gthread_key_t;
  34. typedef pthread_once_t __gthread_once_t;
  35. typedef struct _Mutex_Control __gthread_mutex_t;
  36. typedef struct _Mutex_recursive_Control __gthread_recursive_mutex_t;
  37. typedef struct _Condition_Control __gthread_cond_t;
  38. typedef struct timespec __gthread_time_t;
  39. #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
  40. #define __GTHREAD_MUTEX_INIT _MUTEX_INITIALIZER
  41. #define __GTHREAD_MUTEX_INIT_FUNCTION _Mutex_Initialize
  42. #define __GTHREAD_RECURSIVE_MUTEX_INIT _MUTEX_RECURSIVE_INITIALIZER
  43. #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION _Mutex_recursive_Initialize
  44. #define __GTHREAD_COND_INIT _CONDITION_INITIALIZER
  45. #define __GTHREAD_COND_INIT_FUNCTION _Condition_Initialize
  46. #define __GTHREAD_TIME_INIT {0, 0}
  47. static inline int
  48. __gthread_active_p (void)
  49. {
  50. return 1;
  51. }
  52. static inline int
  53. __gthread_create (__gthread_t *__threadid, void *(*__func) (void *),
  54. void *__args)
  55. {
  56. return pthread_create (__threadid, NULL, __func, __args);
  57. }
  58. static inline int
  59. __gthread_join (__gthread_t __threadid, void **__value_ptr)
  60. {
  61. return pthread_join (__threadid, __value_ptr);
  62. }
  63. static inline int
  64. __gthread_detach (__gthread_t __threadid)
  65. {
  66. return pthread_detach (__threadid);
  67. }
  68. static inline int
  69. __gthread_equal (__gthread_t __t1, __gthread_t __t2)
  70. {
  71. return pthread_equal (__t1, __t2);
  72. }
  73. static inline __gthread_t
  74. __gthread_self (void)
  75. {
  76. return pthread_self ();
  77. }
  78. static inline int
  79. __gthread_yield (void)
  80. {
  81. return sched_yield ();
  82. }
  83. static inline int
  84. __gthread_once (__gthread_once_t *__once, void (*__func) (void))
  85. {
  86. return pthread_once (__once, __func);
  87. }
  88. static inline int
  89. __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
  90. {
  91. return pthread_key_create (__key, __dtor);
  92. }
  93. static inline int
  94. __gthread_key_delete (__gthread_key_t __key)
  95. {
  96. return pthread_key_delete (__key);
  97. }
  98. static inline void *
  99. __gthread_getspecific (__gthread_key_t __key)
  100. {
  101. return pthread_getspecific (__key);
  102. }
  103. static inline int
  104. __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
  105. {
  106. return pthread_setspecific (__key, __ptr);
  107. }
  108. static inline int
  109. __gthread_mutex_lock (__gthread_mutex_t *__mutex)
  110. {
  111. _Mutex_Acquire (__mutex);
  112. return 0;
  113. }
  114. static inline int
  115. __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
  116. {
  117. return _Mutex_Try_acquire (__mutex);
  118. }
  119. static inline int
  120. __gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
  121. const __gthread_time_t *__abs_timeout)
  122. {
  123. return _Mutex_Acquire_timed (__mutex, __abs_timeout);
  124. }
  125. static inline int
  126. __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
  127. {
  128. _Mutex_Release (__mutex);
  129. return 0;
  130. }
  131. static inline int
  132. __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
  133. {
  134. _Mutex_Destroy (__mutex);
  135. return 0;
  136. }
  137. static inline int
  138. __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
  139. {
  140. _Mutex_recursive_Acquire (__mutex);
  141. return 0;
  142. }
  143. static inline int
  144. __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
  145. {
  146. return _Mutex_recursive_Try_acquire (__mutex);
  147. }
  148. static inline int
  149. __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
  150. const __gthread_time_t *__abs_timeout)
  151. {
  152. return _Mutex_recursive_Acquire_timed (__mutex, __abs_timeout);
  153. }
  154. static inline int
  155. __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
  156. {
  157. _Mutex_recursive_Release (__mutex);
  158. return 0;
  159. }
  160. static inline int
  161. __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
  162. {
  163. _Mutex_recursive_Destroy (__mutex);
  164. return 0;
  165. }
  166. static inline int
  167. __gthread_cond_broadcast (__gthread_cond_t *__cond)
  168. {
  169. _Condition_Broadcast (__cond);
  170. return 0;
  171. }
  172. static inline int
  173. __gthread_cond_signal (__gthread_cond_t *__cond)
  174. {
  175. _Condition_Signal (__cond);
  176. return 0;
  177. }
  178. static inline int
  179. __gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
  180. {
  181. _Condition_Wait (__cond, __mutex);
  182. return 0;
  183. }
  184. static inline int
  185. __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
  186. const __gthread_time_t *__abs_timeout)
  187. {
  188. return _Condition_Wait_timed (__cond, __mutex, __abs_timeout);
  189. }
  190. static inline int
  191. __gthread_cond_wait_recursive (__gthread_cond_t *__cond,
  192. __gthread_recursive_mutex_t *__mutex)
  193. {
  194. _Condition_Wait_recursive (__cond, __mutex);
  195. return 0;
  196. }
  197. static inline int
  198. __gthread_cond_destroy (__gthread_cond_t *__cond)
  199. {
  200. _Condition_Destroy (__cond);
  201. return 0;
  202. }
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif /* ! GCC_GTHR_RTEMS_H */