Merge branch 'master' into boehm-demers-weiser-gc
[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, 2006, 2008 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/boehm-gc.h"
33
34 #include "libguile/iselect.h"
35
36 #if (SCM_ENABLE_DEPRECATED == 1)
37
38 /* Thread local data support --- generic C API */
39
40 typedef pthread_key_t scm_t_key;
41
42 #define scm_key_create pthread_key_create
43 #define scm_setspecific pthread_setspecific
44 #define scm_getspecific pthread_getspecific
45 #define scm_key_delete pthread_key_delete
46
47 #endif /* SCM_ENABLE_DEPRECATED == 1 */
48
49 /* Since only one thread can be active anyway, we don't need to do
50 anything special around critical sections. In fact, that's the
51 reason we do only support cooperative threading: Guile's critical
52 regions have not been completely identified yet. (I think.) */
53
54 #define SCM_CRITICAL_SECTION_START
55 #define SCM_CRITICAL_SECTION_END
56
57 #define SCM_I_THREAD_SWITCH_COUNT 50
58
59 #define SCM_THREAD_SWITCHING_CODE \
60 do { \
61 scm_i_switch_counter--; \
62 if (scm_i_switch_counter == 0) \
63 { \
64 scm_i_switch_counter = SCM_I_THREAD_SWITCH_COUNT; \
65 scm_yield(); \
66 } \
67 } while (0)
68
69 SCM_API int scm_i_switch_counter;
70
71 #define SCM_THREAD_LOCAL_DATA (scm_i_copt_thread_data)
72 #define SCM_SET_THREAD_LOCAL_DATA(ptr) (scm_i_copt_set_thread_data (ptr))
73
74 SCM_API void *scm_i_copt_thread_data;
75 SCM_INTERNAL void scm_i_copt_set_thread_data (void *data);
76
77 #endif /* SCM_COOP_PTHREAD_H */
78
79 /*
80 Local Variables:
81 c-file-style: "gnu"
82 End:
83 */