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