null-threads.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 <errno.h>
  31. /* Threads
  32. */
  33. #define scm_i_pthread_t int
  34. #define scm_i_pthread_self() 0
  35. #define scm_i_pthread_create(t,a,f,d) (*(t)=0, (void)(f), ENOSYS)
  36. #define scm_i_pthread_detach(t) do { } while (0)
  37. #define scm_i_pthread_exit(v) exit (EXIT_SUCCESS)
  38. #define scm_i_pthread_cancel(t) 0
  39. #define scm_i_pthread_cleanup_push(t,v) 0
  40. #define scm_i_pthread_cleanup_pop(e) 0
  41. #define scm_i_sched_yield() 0
  42. /* Signals
  43. */
  44. #define scm_i_pthread_sigmask sigprocmask
  45. /* Mutexes
  46. */
  47. #define SCM_I_PTHREAD_MUTEX_INITIALIZER 0
  48. #define scm_i_pthread_mutex_t int
  49. #define scm_i_pthread_mutex_init(m,a) (*(m) = 0)
  50. #define scm_i_pthread_mutex_destroy(m) do { (void)(m); } while(0)
  51. #define scm_i_pthread_mutex_trylock(m) ((*(m))++)
  52. #define scm_i_pthread_mutex_lock(m) ((*(m))++)
  53. #define scm_i_pthread_mutex_unlock(m) ((*(m))--)
  54. #define scm_i_pthread_mutexattr_recursive 0
  55. /* Condition variables
  56. */
  57. #define SCM_I_PTHREAD_COND_INITIALIZER 0
  58. #define scm_i_pthread_cond_t int
  59. #define scm_i_pthread_cond_init(c,a) (*(c) = 0)
  60. #define scm_i_pthread_cond_destroy(c) do { (void)(c); } while(0)
  61. #define scm_i_pthread_cond_signal(c) (*(c) = 1)
  62. #define scm_i_pthread_cond_broadcast(c) (*(c) = 1)
  63. #define scm_i_pthread_cond_wait(c,m) (abort(), 0)
  64. #define scm_i_pthread_cond_timedwait(c,m,t) (abort(), 0)
  65. /* Onces
  66. */
  67. #define scm_i_pthread_once_t int
  68. #define SCM_I_PTHREAD_ONCE_INIT 0
  69. #define scm_i_pthread_once(o,f) do { \
  70. if(!*(o)) { *(o)=1; f (); } \
  71. } while(0)
  72. /* Thread specific storage
  73. */
  74. typedef struct scm_i_pthread_key_t {
  75. struct scm_i_pthread_key_t *next;
  76. void *value;
  77. void (*destr_func) (void *);
  78. } scm_i_pthread_key_t;
  79. SCM_API int scm_i_pthread_key_create (scm_i_pthread_key_t *key,
  80. void (*destr_func) (void *));
  81. #define scm_i_pthread_setspecific(k,p) ((k).value = (p))
  82. #define scm_i_pthread_getspecific(k) ((k).value)
  83. /* Convenience functions
  84. */
  85. #define scm_i_scm_pthread_mutex_lock scm_i_pthread_mutex_lock
  86. #define scm_i_dynwind_pthread_mutex_lock scm_i_pthread_mutex_lock
  87. #define scm_i_scm_pthread_cond_wait scm_i_pthread_cond_wait
  88. #define scm_i_scm_pthread_cond_timedwait scm_i_pthread_cond_timedwait
  89. #endif /* SCM_NULL_THREADS_H */
  90. /*
  91. Local Variables:
  92. c-file-style: "gnu"
  93. End:
  94. */