6 /* Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2008, 2009, 2011
7 * 2014 Free Software Foundation, Inc.
9 * This library is free software; you can redistribute it and/or
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.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
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
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #include "libguile/__scm.h"
28 #include "libguile/root.h"
29 #include "libguile/threads.h"
33 SCM_API
void scm_async_tick (void);
34 SCM_API
void scm_switch (void);
35 SCM_API SCM
scm_async (SCM thunk
);
36 SCM_API SCM
scm_async_mark (SCM a
);
37 SCM_API SCM
scm_system_async_mark (SCM a
);
38 SCM_API SCM
scm_system_async_mark_for_thread (SCM a
, SCM thread
);
39 SCM_INTERNAL
void scm_i_queue_async_cell (SCM cell
, scm_i_thread
*);
40 SCM_INTERNAL
int scm_i_setup_sleep (scm_i_thread
*,
41 SCM obj
, scm_i_pthread_mutex_t
*m
,
43 SCM_INTERNAL
void scm_i_reset_sleep (scm_i_thread
*);
44 SCM_API SCM
scm_run_asyncs (SCM list_of_a
);
45 SCM_API SCM
scm_noop (SCM args
);
46 SCM_API SCM
scm_call_with_blocked_asyncs (SCM proc
);
47 SCM_API SCM
scm_call_with_unblocked_asyncs (SCM proc
);
48 SCM_API
void *scm_c_call_with_blocked_asyncs (void *(*p
) (void *d
), void *d
);
49 SCM_API
void *scm_c_call_with_unblocked_asyncs (void *(*p
) (void *d
), void *d
);
50 SCM_API
void scm_dynwind_block_asyncs (void);
51 SCM_API
void scm_dynwind_unblock_asyncs (void);
53 /* Critical sections */
55 /* XXX - every critical section needs to be examined whether the
56 requirements for SCM_CRITICAL_SECTION_START/END are fulfilled. See
60 /* Defined in threads.c. */
61 SCM_INTERNAL scm_i_pthread_mutex_t scm_i_critical_section_mutex
;
63 SCM_API
void scm_critical_section_start (void);
64 SCM_API
void scm_critical_section_end (void);
66 #ifdef BUILDING_LIBGUILE
68 # define SCM_CRITICAL_SECTION_START \
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++; \
74 # define SCM_CRITICAL_SECTION_END \
76 SCM_I_CURRENT_THREAD->critical_section_level--; \
77 SCM_I_CURRENT_THREAD->block_asyncs--; \
78 scm_i_pthread_mutex_unlock (&scm_i_critical_section_mutex); \
82 # define scm_i_pthread_mutex_lock_block_asyncs(m) \
85 SCM_I_CURRENT_THREAD->block_asyncs++; \
86 scm_i_pthread_mutex_lock (m); \
90 # define scm_i_pthread_mutex_unlock_unblock_asyncs(m) \
93 scm_i_pthread_mutex_unlock (m); \
94 SCM_I_CURRENT_THREAD->block_asyncs--; \
98 #else /* !BUILDING_LIBGUILE */
100 # define SCM_CRITICAL_SECTION_START scm_critical_section_start ()
101 # define SCM_CRITICAL_SECTION_END scm_critical_section_end ()
103 #endif /* !BUILDING_LIBGUILE */
105 SCM_INTERNAL
void scm_init_async (void);
107 #endif /* SCM_ASYNC_H */