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