pthread-threads.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef SCM_PTHREADS_THREADS_H
  2. #define SCM_PTHREADS_THREADS_H
  3. /* Copyright 2002,2005-2006,2011,2018
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. /* The pthreads-threads implementation. This is a direct mapping.
  18. */
  19. #include <pthread.h>
  20. #include <sched.h>
  21. /* Threads
  22. */
  23. #define scm_i_pthread_t pthread_t
  24. #define scm_i_pthread_self pthread_self
  25. #define scm_i_pthread_create pthread_create
  26. #define scm_i_pthread_detach pthread_detach
  27. #define scm_i_pthread_exit pthread_exit
  28. #define scm_i_pthread_cancel pthread_cancel
  29. #define scm_i_pthread_cleanup_push pthread_cleanup_push
  30. #define scm_i_pthread_cleanup_pop pthread_cleanup_pop
  31. #define scm_i_sched_yield sched_yield
  32. /* Signals
  33. */
  34. #define scm_i_pthread_sigmask pthread_sigmask
  35. /* Mutexes
  36. */
  37. #if SCM_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER
  38. # define SCM_I_PTHREAD_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
  39. #else
  40. # define SCM_I_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
  41. #endif
  42. #define scm_i_pthread_mutex_t pthread_mutex_t
  43. #define scm_i_pthread_mutex_init pthread_mutex_init
  44. #define scm_i_pthread_mutex_destroy pthread_mutex_destroy
  45. #define scm_i_pthread_mutex_trylock pthread_mutex_trylock
  46. #define scm_i_pthread_mutex_lock pthread_mutex_lock
  47. #define scm_i_pthread_mutex_unlock pthread_mutex_unlock
  48. extern pthread_mutexattr_t scm_i_pthread_mutexattr_recursive[1];
  49. /* Condition variables
  50. */
  51. #define SCM_I_PTHREAD_COND_INITIALIZER PTHREAD_COND_INITIALIZER
  52. #define scm_i_pthread_cond_t pthread_cond_t
  53. #define scm_i_pthread_cond_init pthread_cond_init
  54. #define scm_i_pthread_cond_destroy pthread_cond_destroy
  55. #define scm_i_pthread_cond_signal pthread_cond_signal
  56. #define scm_i_pthread_cond_broadcast pthread_cond_broadcast
  57. #define scm_i_pthread_cond_wait pthread_cond_wait
  58. #define scm_i_pthread_cond_timedwait pthread_cond_timedwait
  59. /* Onces
  60. */
  61. #define scm_i_pthread_once_t pthread_once_t
  62. #define scm_i_pthread_once pthread_once
  63. #if SCM_NEED_BRACES_ON_PTHREAD_ONCE_INIT
  64. #define SCM_I_PTHREAD_ONCE_INIT { PTHREAD_ONCE_INIT }
  65. #else
  66. #define SCM_I_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
  67. #endif
  68. /* Thread specific storage
  69. */
  70. #define scm_i_pthread_key_t pthread_key_t
  71. #define scm_i_pthread_key_create pthread_key_create
  72. #define scm_i_pthread_setspecific pthread_setspecific
  73. #define scm_i_pthread_getspecific pthread_getspecific
  74. /* Convenience functions
  75. */
  76. #define scm_i_scm_pthread_mutex_lock scm_pthread_mutex_lock
  77. #define scm_i_dynwind_pthread_mutex_lock scm_dynwind_pthread_mutex_lock
  78. #define scm_i_scm_pthread_cond_wait scm_pthread_cond_wait
  79. #define scm_i_scm_pthread_cond_timedwait scm_pthread_cond_timedwait
  80. #endif /* SCM_PTHREADS_THREADS_H */