gthr-single.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /* Threads compatibility routines for libgcc2 and libobjc. */
  2. /* Compile this one with gcc. */
  3. /* Copyright (C) 1997-2015 Free Software Foundation, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #ifndef GCC_GTHR_SINGLE_H
  21. #define GCC_GTHR_SINGLE_H
  22. /* Just provide compatibility for mutex handling. */
  23. typedef int __gthread_key_t;
  24. typedef int __gthread_once_t;
  25. typedef int __gthread_mutex_t;
  26. typedef int __gthread_recursive_mutex_t;
  27. #define __GTHREAD_ONCE_INIT 0
  28. #define __GTHREAD_MUTEX_INIT 0
  29. #define __GTHREAD_MUTEX_INIT_FUNCTION(mx)
  30. #define __GTHREAD_RECURSIVE_MUTEX_INIT 0
  31. #define UNUSED __attribute__((__unused__))
  32. #ifdef _LIBOBJC
  33. /* Thread local storage for a single thread */
  34. static void *thread_local_storage = NULL;
  35. /* Backend initialization functions */
  36. /* Initialize the threads subsystem. */
  37. static inline int
  38. __gthread_objc_init_thread_system (void)
  39. {
  40. /* No thread support available */
  41. return -1;
  42. }
  43. /* Close the threads subsystem. */
  44. static inline int
  45. __gthread_objc_close_thread_system (void)
  46. {
  47. /* No thread support available */
  48. return -1;
  49. }
  50. /* Backend thread functions */
  51. /* Create a new thread of execution. */
  52. static inline objc_thread_t
  53. __gthread_objc_thread_detach (void (* func)(void *), void * arg UNUSED)
  54. {
  55. /* No thread support available */
  56. return NULL;
  57. }
  58. /* Set the current thread's priority. */
  59. static inline int
  60. __gthread_objc_thread_set_priority (int priority UNUSED)
  61. {
  62. /* No thread support available */
  63. return -1;
  64. }
  65. /* Return the current thread's priority. */
  66. static inline int
  67. __gthread_objc_thread_get_priority (void)
  68. {
  69. return OBJC_THREAD_INTERACTIVE_PRIORITY;
  70. }
  71. /* Yield our process time to another thread. */
  72. static inline void
  73. __gthread_objc_thread_yield (void)
  74. {
  75. return;
  76. }
  77. /* Terminate the current thread. */
  78. static inline int
  79. __gthread_objc_thread_exit (void)
  80. {
  81. /* No thread support available */
  82. /* Should we really exit the program */
  83. /* exit (&__objc_thread_exit_status); */
  84. return -1;
  85. }
  86. /* Returns an integer value which uniquely describes a thread. */
  87. static inline objc_thread_t
  88. __gthread_objc_thread_id (void)
  89. {
  90. /* No thread support, use 1. */
  91. return (objc_thread_t) 1;
  92. }
  93. /* Sets the thread's local storage pointer. */
  94. static inline int
  95. __gthread_objc_thread_set_data (void *value)
  96. {
  97. thread_local_storage = value;
  98. return 0;
  99. }
  100. /* Returns the thread's local storage pointer. */
  101. static inline void *
  102. __gthread_objc_thread_get_data (void)
  103. {
  104. return thread_local_storage;
  105. }
  106. /* Backend mutex functions */
  107. /* Allocate a mutex. */
  108. static inline int
  109. __gthread_objc_mutex_allocate (objc_mutex_t mutex UNUSED)
  110. {
  111. return 0;
  112. }
  113. /* Deallocate a mutex. */
  114. static inline int
  115. __gthread_objc_mutex_deallocate (objc_mutex_t mutex UNUSED)
  116. {
  117. return 0;
  118. }
  119. /* Grab a lock on a mutex. */
  120. static inline int
  121. __gthread_objc_mutex_lock (objc_mutex_t mutex UNUSED)
  122. {
  123. /* There can only be one thread, so we always get the lock */
  124. return 0;
  125. }
  126. /* Try to grab a lock on a mutex. */
  127. static inline int
  128. __gthread_objc_mutex_trylock (objc_mutex_t mutex UNUSED)
  129. {
  130. /* There can only be one thread, so we always get the lock */
  131. return 0;
  132. }
  133. /* Unlock the mutex */
  134. static inline int
  135. __gthread_objc_mutex_unlock (objc_mutex_t mutex UNUSED)
  136. {
  137. return 0;
  138. }
  139. /* Backend condition mutex functions */
  140. /* Allocate a condition. */
  141. static inline int
  142. __gthread_objc_condition_allocate (objc_condition_t condition UNUSED)
  143. {
  144. return 0;
  145. }
  146. /* Deallocate a condition. */
  147. static inline int
  148. __gthread_objc_condition_deallocate (objc_condition_t condition UNUSED)
  149. {
  150. return 0;
  151. }
  152. /* Wait on the condition */
  153. static inline int
  154. __gthread_objc_condition_wait (objc_condition_t condition UNUSED,
  155. objc_mutex_t mutex UNUSED)
  156. {
  157. return 0;
  158. }
  159. /* Wake up all threads waiting on this condition. */
  160. static inline int
  161. __gthread_objc_condition_broadcast (objc_condition_t condition UNUSED)
  162. {
  163. return 0;
  164. }
  165. /* Wake up one thread waiting on this condition. */
  166. static inline int
  167. __gthread_objc_condition_signal (objc_condition_t condition UNUSED)
  168. {
  169. return 0;
  170. }
  171. #else /* _LIBOBJC */
  172. static inline int
  173. __gthread_active_p (void)
  174. {
  175. return 0;
  176. }
  177. static inline int
  178. __gthread_once (__gthread_once_t *__once UNUSED, void (*__func) (void) UNUSED)
  179. {
  180. return 0;
  181. }
  182. static inline int UNUSED
  183. __gthread_key_create (__gthread_key_t *__key UNUSED, void (*__func) (void *) UNUSED)
  184. {
  185. return 0;
  186. }
  187. static int UNUSED
  188. __gthread_key_delete (__gthread_key_t __key UNUSED)
  189. {
  190. return 0;
  191. }
  192. static inline void *
  193. __gthread_getspecific (__gthread_key_t __key UNUSED)
  194. {
  195. return 0;
  196. }
  197. static inline int
  198. __gthread_setspecific (__gthread_key_t __key UNUSED, const void *__v UNUSED)
  199. {
  200. return 0;
  201. }
  202. static inline int
  203. __gthread_mutex_destroy (__gthread_mutex_t *__mutex UNUSED)
  204. {
  205. return 0;
  206. }
  207. static inline int
  208. __gthread_mutex_lock (__gthread_mutex_t *__mutex UNUSED)
  209. {
  210. return 0;
  211. }
  212. static inline int
  213. __gthread_mutex_trylock (__gthread_mutex_t *__mutex UNUSED)
  214. {
  215. return 0;
  216. }
  217. static inline int
  218. __gthread_mutex_unlock (__gthread_mutex_t *__mutex UNUSED)
  219. {
  220. return 0;
  221. }
  222. static inline int
  223. __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
  224. {
  225. return __gthread_mutex_lock (__mutex);
  226. }
  227. static inline int
  228. __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
  229. {
  230. return __gthread_mutex_trylock (__mutex);
  231. }
  232. static inline int
  233. __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
  234. {
  235. return __gthread_mutex_unlock (__mutex);
  236. }
  237. static inline int
  238. __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
  239. {
  240. return __gthread_mutex_destroy (__mutex);
  241. }
  242. #endif /* _LIBOBJC */
  243. #undef UNUSED
  244. #endif /* ! GCC_GTHR_SINGLE_H */