null-threads.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* classes: h_files */
  2. #ifndef SCM_NULL_THREADS_H
  3. #define SCM_NULL_THREADS_H
  4. /* Copyright (C) 2005, 2006, 2010 Free Software Foundation, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * as published by the Free Software Foundation; either version 3 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. */
  21. /* The null-threads implementation. We provide the subset of the
  22. standard pthread API that is used by Guile, but no new threads can
  23. be created.
  24. This file merely exits so that Guile can be compiled and run
  25. without using pthreads. Improving performance via optimizations
  26. that are possible in a single-threaded program is not a primary
  27. goal.
  28. */
  29. #include <stdlib.h>
  30. #include <signal.h>
  31. #include <errno.h>
  32. /* Threads
  33. */
  34. typedef int scm_i_pthread_t;
  35. typedef void scm_i_pthread_attr_t;
  36. static inline scm_i_pthread_t
  37. scm_i_pthread_self (void)
  38. {
  39. return 0;
  40. }
  41. static inline int
  42. scm_i_pthread_create (scm_i_pthread_t *t, const scm_i_pthread_attr_t *attr,
  43. void* (*f) (void*), void *arg)
  44. {
  45. return ENOSYS;
  46. }
  47. static inline int
  48. scm_i_pthread_detach (scm_i_pthread_t t)
  49. {
  50. return 0;
  51. }
  52. static inline void
  53. scm_i_pthread_exit (void *retval)
  54. {
  55. exit (EXIT_SUCCESS);
  56. }
  57. static inline int
  58. scm_i_pthread_cancel (scm_i_pthread_t t)
  59. {
  60. return 0;
  61. }
  62. static inline int
  63. scm_i_sched_yield (void)
  64. {
  65. return 0;
  66. }
  67. /* Signals
  68. */
  69. static inline int
  70. scm_i_pthread_sigmask (int how, const sigset_t *set, sigset_t *oldset)
  71. {
  72. return sigprocmask (how, set, oldset);
  73. }
  74. /* Mutexes
  75. */
  76. typedef enum {
  77. SCM_I_PTHREAD_MUTEX_INITIALIZER = 0,
  78. SCM_I_PTHREAD_MUTEX_LOCKED = 1
  79. } scm_i_pthread_mutex_t;
  80. typedef int scm_i_pthread_mutexattr_t;
  81. static inline int
  82. scm_i_pthread_mutex_init (scm_i_pthread_mutex_t *m,
  83. scm_i_pthread_mutexattr_t *attr)
  84. {
  85. *m = SCM_I_PTHREAD_MUTEX_INITIALIZER;
  86. return 0;
  87. }
  88. static inline int
  89. scm_i_pthread_mutex_destroy (scm_i_pthread_mutex_t *m)
  90. {
  91. return 0;
  92. }
  93. static inline int
  94. scm_i_pthread_mutex_trylock(scm_i_pthread_mutex_t *m)
  95. {
  96. if (*m == SCM_I_PTHREAD_MUTEX_LOCKED)
  97. return EDEADLK;
  98. *m = SCM_I_PTHREAD_MUTEX_LOCKED;
  99. return 0;
  100. }
  101. static inline int
  102. scm_i_pthread_mutex_lock (scm_i_pthread_mutex_t *m)
  103. {
  104. *m = SCM_I_PTHREAD_MUTEX_LOCKED;
  105. return 0;
  106. }
  107. static inline int
  108. scm_i_pthread_mutex_unlock (scm_i_pthread_mutex_t *m)
  109. {
  110. *m = SCM_I_PTHREAD_MUTEX_INITIALIZER;
  111. return 0;
  112. }
  113. #define scm_i_pthread_mutexattr_recursive 0
  114. /* Condition variables
  115. */
  116. typedef enum {
  117. SCM_I_PTHREAD_COND_INITIALIZER = 0
  118. } scm_i_pthread_cond_t;
  119. typedef int scm_i_pthread_condattr_t;
  120. static inline int
  121. scm_i_pthread_cond_init (scm_i_pthread_cond_t *c,
  122. scm_i_pthread_condattr_t *attr)
  123. {
  124. *c = SCM_I_PTHREAD_COND_INITIALIZER;
  125. return 0;
  126. }
  127. static inline int
  128. scm_i_pthread_cond_destroy (scm_i_pthread_cond_t *c)
  129. {
  130. return 0;
  131. }
  132. static inline int
  133. scm_i_pthread_cond_signal (scm_i_pthread_cond_t *c)
  134. {
  135. return 0;
  136. }
  137. static inline int
  138. scm_i_pthread_cond_broadcast (scm_i_pthread_cond_t *c)
  139. {
  140. return 0;
  141. }
  142. static inline int
  143. scm_i_pthread_cond_wait (scm_i_pthread_cond_t *c, scm_i_pthread_mutex_t *m)
  144. {
  145. abort ();
  146. return 0;
  147. }
  148. static inline int
  149. scm_i_pthread_cond_timedwait (scm_i_pthread_cond_t *c, scm_i_pthread_mutex_t *m,
  150. const scm_t_timespec *t)
  151. {
  152. abort();
  153. return 0;
  154. }
  155. /* Onces
  156. */
  157. typedef enum {
  158. SCM_I_PTHREAD_ONCE_INIT = 0,
  159. SCM_I_PTHREAD_ONCE_ALREADY = 1
  160. } scm_i_pthread_once_t;
  161. static inline int
  162. scm_i_pthread_once (scm_i_pthread_once_t *o, void(*init)(void))
  163. {
  164. if (*o == SCM_I_PTHREAD_ONCE_INIT)
  165. {
  166. *o = SCM_I_PTHREAD_ONCE_ALREADY;
  167. init ();
  168. }
  169. return 0;
  170. }
  171. /* Thread specific storage
  172. */
  173. typedef struct scm_i_pthread_key_t {
  174. struct scm_i_pthread_key_t *next;
  175. void *value;
  176. void (*destr_func) (void *);
  177. } scm_i_pthread_key_t;
  178. SCM_API int scm_i_pthread_key_create (scm_i_pthread_key_t *key,
  179. void (*destr_func) (void *));
  180. #define scm_i_pthread_setspecific(k,p) ((k).value = (p))
  181. #define scm_i_pthread_getspecific(k) ((k).value)
  182. /* Convenience functions
  183. */
  184. #define scm_i_scm_pthread_mutex_lock scm_i_pthread_mutex_lock
  185. #define scm_i_dynwind_pthread_mutex_lock scm_i_pthread_mutex_lock
  186. #define scm_i_scm_pthread_cond_wait scm_i_pthread_cond_wait
  187. #define scm_i_scm_pthread_cond_timedwait scm_i_pthread_cond_timedwait
  188. #endif /* SCM_NULL_THREADS_H */
  189. /*
  190. Local Variables:
  191. c-file-style: "gnu"
  192. End:
  193. */