async.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* classes: h_files */
  2. #ifndef SCM_ASYNC_H
  3. #define SCM_ASYNC_H
  4. /* Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2008, 2009, 2011
  5. * 2014 Free Software Foundation, Inc.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. #include "libguile/__scm.h"
  23. #include "libguile/root.h"
  24. #include "libguile/threads.h"
  25. SCM_API void scm_async_tick (void);
  26. SCM_API void scm_switch (void);
  27. SCM_API SCM scm_async (SCM thunk);
  28. SCM_API SCM scm_async_mark (SCM a);
  29. SCM_API SCM scm_system_async_mark (SCM a);
  30. SCM_API SCM scm_system_async_mark_for_thread (SCM a, SCM thread);
  31. SCM_INTERNAL void scm_i_queue_async_cell (SCM cell, scm_i_thread *);
  32. SCM_INTERNAL int scm_i_setup_sleep (scm_i_thread *,
  33. SCM obj, scm_i_pthread_mutex_t *m,
  34. int fd);
  35. SCM_INTERNAL void scm_i_reset_sleep (scm_i_thread *);
  36. SCM_API SCM scm_run_asyncs (SCM list_of_a);
  37. SCM_API SCM scm_noop (SCM args);
  38. SCM_API SCM scm_call_with_blocked_asyncs (SCM proc);
  39. SCM_API SCM scm_call_with_unblocked_asyncs (SCM proc);
  40. SCM_API void *scm_c_call_with_blocked_asyncs (void *(*p) (void *d), void *d);
  41. SCM_API void *scm_c_call_with_unblocked_asyncs (void *(*p) (void *d), void *d);
  42. SCM_API void scm_dynwind_block_asyncs (void);
  43. SCM_API void scm_dynwind_unblock_asyncs (void);
  44. /* Critical sections */
  45. /* XXX - every critical section needs to be examined whether the
  46. requirements for SCM_CRITICAL_SECTION_START/END are fulfilled. See
  47. the manual.
  48. */
  49. /* Defined in threads.c. */
  50. SCM_INTERNAL scm_i_pthread_mutex_t scm_i_critical_section_mutex;
  51. SCM_API void scm_critical_section_start (void);
  52. SCM_API void scm_critical_section_end (void);
  53. #ifdef BUILDING_LIBGUILE
  54. # define SCM_CRITICAL_SECTION_START \
  55. do { \
  56. scm_i_pthread_mutex_lock (&scm_i_critical_section_mutex); \
  57. SCM_I_CURRENT_THREAD->block_asyncs++; \
  58. SCM_I_CURRENT_THREAD->critical_section_level++; \
  59. } while (0)
  60. # define SCM_CRITICAL_SECTION_END \
  61. do { \
  62. SCM_I_CURRENT_THREAD->critical_section_level--; \
  63. SCM_I_CURRENT_THREAD->block_asyncs--; \
  64. scm_i_pthread_mutex_unlock (&scm_i_critical_section_mutex); \
  65. scm_async_tick (); \
  66. } while (0)
  67. # define scm_i_pthread_mutex_lock_block_asyncs(m) \
  68. do \
  69. { \
  70. SCM_I_CURRENT_THREAD->block_asyncs++; \
  71. scm_i_pthread_mutex_lock (m); \
  72. } \
  73. while (0)
  74. # define scm_i_pthread_mutex_unlock_unblock_asyncs(m) \
  75. do \
  76. { \
  77. scm_i_pthread_mutex_unlock (m); \
  78. SCM_I_CURRENT_THREAD->block_asyncs--; \
  79. } \
  80. while (0)
  81. #else /* !BUILDING_LIBGUILE */
  82. # define SCM_CRITICAL_SECTION_START scm_critical_section_start ()
  83. # define SCM_CRITICAL_SECTION_END scm_critical_section_end ()
  84. #endif /* !BUILDING_LIBGUILE */
  85. SCM_INTERNAL void scm_init_async (void);
  86. #endif /* SCM_ASYNC_H */
  87. /*
  88. Local Variables:
  89. c-file-style: "gnu"
  90. End:
  91. */