Commit | Line | Data |
---|---|---|
d97eb496 MV |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef SCM_COOP_PTHREADS_H | |
4 | #define SCM_COOP_PTHREADS_H | |
5 | ||
2b829bbb | 6 | /* Copyright (C) 2002, 2006 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 | ||
e7bca227 | 32 | #include "libguile/boehm-gc.h" |
89f423d5 | 33 | |
76734914 MD |
34 | #include "libguile/iselect.h" |
35 | ||
9be8bb45 MD |
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 | ||
d97eb496 MV |
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 | ||
0019d6a1 | 57 | #define SCM_I_THREAD_SWITCH_COUNT 50 |
d97eb496 | 58 | |
d97eb496 MV |
59 | #define SCM_THREAD_SWITCHING_CODE \ |
60 | do { \ | |
0019d6a1 MV |
61 | scm_i_switch_counter--; \ |
62 | if (scm_i_switch_counter == 0) \ | |
d97eb496 | 63 | { \ |
0019d6a1 | 64 | scm_i_switch_counter = SCM_I_THREAD_SWITCH_COUNT; \ |
d97eb496 MV |
65 | scm_yield(); \ |
66 | } \ | |
67 | } while (0) | |
68 | ||
0019d6a1 | 69 | SCM_API int scm_i_switch_counter; |
d97eb496 | 70 | |
0019d6a1 MV |
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)) | |
d97eb496 | 73 | |
0019d6a1 MV |
74 | SCM_API void *scm_i_copt_thread_data; |
75 | SCM_API void scm_i_copt_set_thread_data (void *data); | |
d97eb496 MV |
76 | |
77 | #endif /* SCM_COOP_PTHREAD_H */ | |
78 | ||
79 | /* | |
80 | Local Variables: | |
81 | c-file-style: "gnu" | |
82 | End: | |
83 | */ |