Add `SCM_INTERNAL' macro, use it.
[bpt/guile.git] / libguile / coop-pthreads.h
CommitLineData
d97eb496
MV
1/* classes: h_files */
2
3#ifndef SCM_COOP_PTHREADS_H
4#define SCM_COOP_PTHREADS_H
5
102dbb6f 6/* Copyright (C) 2002, 2006, 2008 Free Software Foundation, Inc.
d97eb496 7 *
73be1d9e
MV
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
d97eb496 12 *
73be1d9e 13 * This library is distributed in the hope that it will be useful,
d97eb496 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
d97eb496 17 *
73be1d9e
MV
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
92205699 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
73be1d9e 21 */
d97eb496
MV
22
23\f
24
0019d6a1
MV
25/* The coop-pthreads implementation. We use pthreads for the basic
26 multi threading stuff, but rig it so that only one thread is ever
27 active inside Guile.
d97eb496
MV
28*/
29
30#include <pthread.h>
31
76734914
MD
32#include "libguile/iselect.h"
33
9be8bb45
MD
34#if (SCM_ENABLE_DEPRECATED == 1)
35
36/* Thread local data support --- generic C API */
37
38typedef pthread_key_t scm_t_key;
39
40#define scm_key_create pthread_key_create
41#define scm_setspecific pthread_setspecific
42#define scm_getspecific pthread_getspecific
43#define scm_key_delete pthread_key_delete
44
45#endif /* SCM_ENABLE_DEPRECATED == 1 */
46
d97eb496
MV
47/* Since only one thread can be active anyway, we don't need to do
48 anything special around critical sections. In fact, that's the
49 reason we do only support cooperative threading: Guile's critical
50 regions have not been completely identified yet. (I think.) */
51
52#define SCM_CRITICAL_SECTION_START
53#define SCM_CRITICAL_SECTION_END
54
0019d6a1 55#define SCM_I_THREAD_SWITCH_COUNT 50
d97eb496 56
d97eb496
MV
57#define SCM_THREAD_SWITCHING_CODE \
58do { \
0019d6a1
MV
59 scm_i_switch_counter--; \
60 if (scm_i_switch_counter == 0) \
d97eb496 61 { \
0019d6a1 62 scm_i_switch_counter = SCM_I_THREAD_SWITCH_COUNT; \
d97eb496
MV
63 scm_yield(); \
64 } \
65} while (0)
66
0019d6a1 67SCM_API int scm_i_switch_counter;
d97eb496 68
0019d6a1
MV
69#define SCM_THREAD_LOCAL_DATA (scm_i_copt_thread_data)
70#define SCM_SET_THREAD_LOCAL_DATA(ptr) (scm_i_copt_set_thread_data (ptr))
d97eb496 71
0019d6a1 72SCM_API void *scm_i_copt_thread_data;
102dbb6f 73SCM_INTERNAL void scm_i_copt_set_thread_data (void *data);
d97eb496
MV
74
75#endif /* SCM_COOP_PTHREAD_H */
76
77/*
78 Local Variables:
79 c-file-style: "gnu"
80 End:
81*/