The FSF has a new address.
[bpt/guile.git] / libguile / coop-pthreads.h
1 /* classes: h_files */
2
3 #ifndef SCM_COOP_PTHREADS_H
4 #define SCM_COOP_PTHREADS_H
5
6 /* Copyright (C) 2002 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
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but 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 02110-1301 USA
21 */
22
23 \f
24
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.
28 */
29
30 #include <pthread.h>
31
32 #include "libguile/iselect.h"
33
34 #if (SCM_ENABLE_DEPRECATED == 1)
35
36 /* Thread local data support --- generic C API */
37
38 typedef 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
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
55 #define SCM_I_THREAD_SWITCH_COUNT 50
56
57 #define SCM_THREAD_SWITCHING_CODE \
58 do { \
59 scm_i_switch_counter--; \
60 if (scm_i_switch_counter == 0) \
61 { \
62 scm_i_switch_counter = SCM_I_THREAD_SWITCH_COUNT; \
63 scm_yield(); \
64 } \
65 } while (0)
66
67 SCM_API int scm_i_switch_counter;
68
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))
71
72 SCM_API void *scm_i_copt_thread_data;
73 SCM_API void scm_i_copt_set_thread_data (void *data);
74
75 #endif /* SCM_COOP_PTHREAD_H */
76
77 /*
78 Local Variables:
79 c-file-style: "gnu"
80 End:
81 */