Commit | Line | Data |
---|---|---|
eac85310 MV |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef SCM_THREADS_PTHREADS_H | |
4 | #define SCM_THREADS_PTHREADS_H | |
5 | ||
6 | /* Copyright (C) 2002 Free Software Foundation, Inc. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2, or (at your option) | |
11 | * any later version. | |
12 | * | |
13 | * This program 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 | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this software; see the file COPYING. If not, write to | |
20 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, | |
21 | * Boston, MA 02111-1307 USA | |
22 | * | |
23 | * As a special exception, the Free Software Foundation gives permission | |
24 | * for additional uses of the text contained in its release of GUILE. | |
25 | * | |
26 | * The exception is that, if you link the GUILE library with other files | |
27 | * to produce an executable, this does not by itself cause the | |
28 | * resulting executable to be covered by the GNU General Public License. | |
29 | * Your use of that executable is in no way restricted on account of | |
30 | * linking the GUILE library code into it. | |
31 | * | |
32 | * This exception does not however invalidate any other reasons why | |
33 | * the executable file might be covered by the GNU General Public License. | |
34 | * | |
35 | * This exception applies only to the code released by the | |
36 | * Free Software Foundation under the name GUILE. If you copy | |
37 | * code from other Free Software Foundation releases into a copy of | |
38 | * GUILE, as the General Public License permits, the exception does | |
39 | * not apply to the code that you add in this way. To avoid misleading | |
40 | * anyone as to the status of such modified files, you must delete | |
41 | * this exception notice from them. | |
42 | * | |
43 | * If you write modifications of your own for GUILE, it is your choice | |
44 | * whether to permit this exception to apply to your modifications. | |
45 | * If you do not wish that, delete this exception notice. */ | |
46 | ||
47 | \f | |
48 | ||
9bc4701c | 49 | /* The pthreads-threads implementation. This is a direct mapping. |
eac85310 MV |
50 | */ |
51 | ||
9bc4701c MD |
52 | /* This is an interface between Guile and the pthreads thread package. */ |
53 | ||
eac85310 | 54 | #include <pthread.h> |
0b6843b1 | 55 | #include <sched.h> |
eac85310 | 56 | |
9bc4701c MD |
57 | /* MDJ 021209 <djurfeldt@nada.kth.se>: |
58 | The separation of the plugin interface and the low-level C API | |
59 | (currently in threads.h) needs to be completed in a sensible way. | |
60 | */ | |
61 | ||
62 | /* The scm_t_ types are temporarily used both in plugin and low-level API */ | |
63 | #define scm_t_thread pthread_t | |
eac85310 | 64 | |
9bc4701c | 65 | #define scm_i_plugin_thread_create pthread_create |
eac85310 | 66 | |
9bc4701c MD |
67 | #define scm_i_plugin_thread_join pthread_join |
68 | #define scm_i_plugin_thread_detach pthread_detach | |
0b6843b1 MD |
69 | #define scm_i_plugin_thread_self pthread_self |
70 | #define scm_i_plugin_thread_yield sched_yield | |
eac85310 | 71 | |
0b6843b1 | 72 | /* Size is checked in scm_init_pthread_threads */ |
0b6843b1 | 73 | #define SCM_MUTEX_MAXSIZE (9 * sizeof (long)) |
0b6843b1 | 74 | typedef struct { char _[SCM_MUTEX_MAXSIZE]; } scm_t_mutex; |
28d52ebb MD |
75 | #define scm_t_mutexattr pthread_mutexattr_t |
76 | ||
77 | extern scm_t_mutexattr scm_i_plugin_mutex; /* The "fast" mutex. */ | |
eac85310 | 78 | |
6da2dfc4 MD |
79 | /* This debug stuff made things a bit messy. This needs some |
80 | reorganization. */ | |
0b6843b1 MD |
81 | #ifdef SCM_DEBUG_THREADS |
82 | int scm_i_plugin_mutex_init (scm_t_mutex *, const scm_t_mutexattr *); | |
83 | int scm_i_plugin_mutex_lock (scm_t_mutex *); | |
84 | int scm_i_plugin_mutex_unlock (scm_t_mutex *); | |
85 | #else | |
86 | #define scm_i_plugin_mutex_init(m,a) \ | |
87 | pthread_mutex_init ((pthread_mutex_t *) (m), (a)) | |
88 | #define scm_i_plugin_mutex_lock(m) \ | |
89 | pthread_mutex_lock ((pthread_mutex_t *) (m)) | |
90 | #define scm_i_plugin_mutex_unlock(m) \ | |
91 | pthread_mutex_unlock ((pthread_mutex_t *) (m)) | |
92 | #endif | |
93 | #define scm_i_plugin_mutex_destroy(m) \ | |
94 | pthread_mutex_destroy ((pthread_mutex_t *) (m)) | |
95 | #define scm_i_plugin_mutex_trylock(m) \ | |
96 | pthread_mutex_trylock ((pthread_mutex_t *) (m)) | |
eac85310 | 97 | |
93cd4dcd | 98 | /* Size is checked in scm_init_pthread_threads */ |
0b6843b1 | 99 | #define SCM_REC_MUTEX_MAXSIZE (SCM_MUTEX_MAXSIZE + 3 * sizeof (long)) |
28d52ebb MD |
100 | typedef struct { char _[SCM_REC_MUTEX_MAXSIZE]; } scm_t_rec_mutex; |
101 | ||
102 | extern scm_t_mutexattr scm_i_plugin_rec_mutex; | |
103 | ||
0b6843b1 MD |
104 | #if defined (SCM_MUTEX_RECURSIVE) && !defined (SCM_DEBUG_THREADS) |
105 | /* pthreads has recursive mutexes! */ | |
93cd4dcd MD |
106 | #define scm_i_plugin_rec_mutex_init(m,a) \ |
107 | pthread_mutex_init ((pthread_mutex_t *) (m), (a)) | |
108 | #define scm_i_plugin_rec_mutex_destroy(m) \ | |
109 | pthread_mutex_destroy ((pthread_mutex_t *) (m)) | |
110 | #define scm_i_plugin_rec_mutex_lock(m) \ | |
111 | pthread_mutex_lock ((pthread_mutex_t *) (m)) | |
112 | #define scm_i_plugin_rec_mutex_trylock(m) \ | |
113 | pthread_mutex_trylock ((pthread_mutex_t *) (m)) | |
114 | #define scm_i_plugin_rec_mutex_unlock(m) \ | |
115 | pthread_mutex_unlock ((pthread_mutex_t *) (m)) | |
28d52ebb MD |
116 | #else |
117 | int scm_i_plugin_rec_mutex_init (scm_t_rec_mutex *, const scm_t_mutexattr *); | |
118 | #define scm_i_plugin_rec_mutex_destroy(mx) do { (void) (mx); } while (0) | |
119 | int scm_i_plugin_rec_mutex_lock (scm_t_rec_mutex *); | |
120 | int scm_i_plugin_rec_mutex_trylock (scm_t_rec_mutex *); | |
121 | int scm_i_plugin_rec_mutex_unlock (scm_t_rec_mutex *); | |
122 | #endif | |
123 | ||
9bc4701c | 124 | #define scm_t_cond pthread_cond_t |
eac85310 | 125 | |
9bc4701c | 126 | #define scm_i_plugin_cond_init pthread_cond_init |
6da2dfc4 MD |
127 | #define scm_i_plugin_cond_destroy pthread_cond_destroy |
128 | #ifdef SCM_DEBUG_THREADS | |
129 | int scm_i_plugin_cond_wait (scm_t_cond *, scm_t_mutex *); | |
130 | int scm_i_plugin_cond_timedwait (scm_t_cond *, | |
131 | scm_t_mutex *, | |
132 | const struct timespec *); | |
133 | #else | |
0b6843b1 MD |
134 | #define scm_i_plugin_cond_wait(c, m) \ |
135 | pthread_cond_wait ((c), (pthread_mutex_t *) (m)) | |
136 | #define scm_i_plugin_cond_timedwait(c, m, t) \ | |
137 | pthread_cond_timedwait ((c), (pthread_mutex_t *) (m), (t)) | |
6da2dfc4 | 138 | #endif |
9bc4701c MD |
139 | #define scm_i_plugin_cond_signal pthread_cond_signal |
140 | #define scm_i_plugin_cond_broadcast pthread_cond_broadcast | |
eac85310 | 141 | |
9bc4701c | 142 | #define scm_t_key pthread_key_t |
eac85310 | 143 | |
9bc4701c MD |
144 | #define scm_i_plugin_key_create pthread_key_create |
145 | #define scm_i_plugin_key_delete pthread_key_delete | |
146 | #define scm_i_plugin_setspecific pthread_setspecific | |
147 | #define scm_i_plugin_getspecific pthread_getspecific | |
eac85310 | 148 | |
9bc4701c | 149 | #define scm_i_plugin_select select |
eac85310 | 150 | |
e29e0b09 MD |
151 | #ifdef SCM_DEBUG_THREADS |
152 | void scm_i_assert_heap_locked (void); | |
153 | #endif | |
154 | ||
28d52ebb MD |
155 | void scm_init_pthread_threads (void); |
156 | ||
93cd4dcd | 157 | #endif /* SCM_THREADS_PTHREADS_H */ |
eac85310 MV |
158 | |
159 | /* | |
160 | Local Variables: | |
161 | c-file-style: "gnu" | |
162 | End: | |
163 | */ |