async.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* classes: h_files */
  2. #ifndef SCM_ASYNC_H
  3. #define SCM_ASYNC_H
  4. /* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2004, 2005, 2006, 2008, 2009, 2011 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. #include "libguile/__scm.h"
  22. #include "libguile/root.h"
  23. #include "libguile/threads.h"
  24. SCM_API void scm_async_tick (void);
  25. SCM_API void scm_switch (void);
  26. SCM_API SCM scm_async (SCM thunk);
  27. SCM_API SCM scm_async_mark (SCM a);
  28. SCM_API SCM scm_system_async_mark (SCM a);
  29. SCM_API SCM scm_system_async_mark_for_thread (SCM a, SCM thread);
  30. SCM_INTERNAL void scm_i_queue_async_cell (SCM cell, scm_i_thread *);
  31. SCM_INTERNAL int scm_i_setup_sleep (scm_i_thread *,
  32. SCM obj, scm_i_pthread_mutex_t *m,
  33. int fd);
  34. SCM_INTERNAL void scm_i_reset_sleep (scm_i_thread *);
  35. SCM_API SCM scm_run_asyncs (SCM list_of_a);
  36. SCM_API SCM scm_noop (SCM args);
  37. SCM_API SCM scm_call_with_blocked_asyncs (SCM proc);
  38. SCM_API SCM scm_call_with_unblocked_asyncs (SCM proc);
  39. void *scm_c_call_with_blocked_asyncs (void *(*p) (void *d), void *d);
  40. void *scm_c_call_with_unblocked_asyncs (void *(*p) (void *d), void *d);
  41. void scm_dynwind_block_asyncs (void);
  42. void scm_dynwind_unblock_asyncs (void);
  43. /* Critical sections */
  44. /* XXX - every critical section needs to be examined whether the
  45. requirements for SCM_CRITICAL_SECTION_START/END are fulfilled. See
  46. the manual.
  47. */
  48. /* Defined in threads.c. */
  49. SCM_INTERNAL scm_i_pthread_mutex_t scm_i_critical_section_mutex;
  50. SCM_API void scm_critical_section_start (void);
  51. SCM_API void scm_critical_section_end (void);
  52. #ifdef BUILDING_LIBGUILE
  53. # define SCM_CRITICAL_SECTION_START \
  54. do { \
  55. scm_i_pthread_mutex_lock (&scm_i_critical_section_mutex); \
  56. SCM_I_CURRENT_THREAD->block_asyncs++; \
  57. SCM_I_CURRENT_THREAD->critical_section_level++; \
  58. } while (0)
  59. # define SCM_CRITICAL_SECTION_END \
  60. do { \
  61. SCM_I_CURRENT_THREAD->critical_section_level--; \
  62. SCM_I_CURRENT_THREAD->block_asyncs--; \
  63. scm_i_pthread_mutex_unlock (&scm_i_critical_section_mutex); \
  64. scm_async_tick (); \
  65. } while (0)
  66. # define scm_i_pthread_mutex_lock_block_asyncs(m) \
  67. do \
  68. { \
  69. SCM_I_CURRENT_THREAD->block_asyncs++; \
  70. scm_i_pthread_mutex_lock (m); \
  71. } \
  72. while (0)
  73. # define scm_i_pthread_mutex_unlock_unblock_asyncs(m) \
  74. do \
  75. { \
  76. scm_i_pthread_mutex_unlock (m); \
  77. SCM_I_CURRENT_THREAD->block_asyncs--; \
  78. } \
  79. while (0)
  80. #else /* !BUILDING_LIBGUILE */
  81. # define SCM_CRITICAL_SECTION_START scm_critical_section_start ()
  82. # define SCM_CRITICAL_SECTION_END scm_critical_section_end ()
  83. #endif /* !BUILDING_LIBGUILE */
  84. SCM_INTERNAL void scm_init_async (void);
  85. #endif /* SCM_ASYNC_H */
  86. /*
  87. Local Variables:
  88. c-file-style: "gnu"
  89. End:
  90. */