async.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #else /* !BUILDING_LIBGUILE */
  67. # define SCM_CRITICAL_SECTION_START scm_critical_section_start ()
  68. # define SCM_CRITICAL_SECTION_END scm_critical_section_end ()
  69. #endif /* !BUILDING_LIBGUILE */
  70. SCM_INTERNAL void scm_init_async (void);
  71. #endif /* SCM_ASYNC_H */
  72. /*
  73. Local Variables:
  74. c-file-style: "gnu"
  75. End:
  76. */