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 MV |
54 | #include <pthread.h> |
55 | ||
9bc4701c MD |
56 | /* MDJ 021209 <djurfeldt@nada.kth.se>: |
57 | The separation of the plugin interface and the low-level C API | |
58 | (currently in threads.h) needs to be completed in a sensible way. | |
59 | */ | |
60 | ||
61 | /* The scm_t_ types are temporarily used both in plugin and low-level API */ | |
62 | #define scm_t_thread pthread_t | |
eac85310 | 63 | |
9bc4701c | 64 | #define scm_i_plugin_thread_create pthread_create |
eac85310 | 65 | |
9bc4701c MD |
66 | #define scm_i_plugin_thread_join pthread_join |
67 | #define scm_i_plugin_thread_detach pthread_detach | |
68 | #define scm_i_plugin_thread_self pthread_self | |
eac85310 | 69 | |
9bc4701c | 70 | #define scm_t_mutex pthread_mutex_t |
28d52ebb MD |
71 | #define scm_t_mutexattr pthread_mutexattr_t |
72 | ||
73 | extern scm_t_mutexattr scm_i_plugin_mutex; /* The "fast" mutex. */ | |
eac85310 | 74 | |
9bc4701c MD |
75 | #define scm_i_plugin_mutex_init pthread_mutex_init |
76 | #define scm_i_plugin_mutex_destroy pthread_mutex_destroy | |
77 | #define scm_i_plugin_mutex_lock pthread_mutex_lock | |
78 | #define scm_i_plugin_mutex_trylock pthread_mutex_trylock | |
79 | #define scm_i_plugin_mutex_unlock pthread_mutex_unlock | |
eac85310 | 80 | |
93cd4dcd | 81 | /* Size is checked in scm_init_pthread_threads */ |
28d52ebb MD |
82 | #define SCM_REC_MUTEX_MAXSIZE (8 * sizeof (long)) |
83 | typedef struct { char _[SCM_REC_MUTEX_MAXSIZE]; } scm_t_rec_mutex; | |
84 | ||
85 | extern scm_t_mutexattr scm_i_plugin_rec_mutex; | |
86 | ||
93cd4dcd MD |
87 | #ifdef SCM_MUTEX_RECURSIVE /* pthreads has recursive mutexes! */ |
88 | #define scm_i_plugin_rec_mutex_init(m,a) \ | |
89 | pthread_mutex_init ((pthread_mutex_t *) (m), (a)) | |
90 | #define scm_i_plugin_rec_mutex_destroy(m) \ | |
91 | pthread_mutex_destroy ((pthread_mutex_t *) (m)) | |
92 | #define scm_i_plugin_rec_mutex_lock(m) \ | |
93 | pthread_mutex_lock ((pthread_mutex_t *) (m)) | |
94 | #define scm_i_plugin_rec_mutex_trylock(m) \ | |
95 | pthread_mutex_trylock ((pthread_mutex_t *) (m)) | |
96 | #define scm_i_plugin_rec_mutex_unlock(m) \ | |
97 | pthread_mutex_unlock ((pthread_mutex_t *) (m)) | |
28d52ebb MD |
98 | #else |
99 | int scm_i_plugin_rec_mutex_init (scm_t_rec_mutex *, const scm_t_mutexattr *); | |
100 | #define scm_i_plugin_rec_mutex_destroy(mx) do { (void) (mx); } while (0) | |
101 | int scm_i_plugin_rec_mutex_lock (scm_t_rec_mutex *); | |
102 | int scm_i_plugin_rec_mutex_trylock (scm_t_rec_mutex *); | |
103 | int scm_i_plugin_rec_mutex_unlock (scm_t_rec_mutex *); | |
104 | #endif | |
105 | ||
9bc4701c | 106 | #define scm_t_cond pthread_cond_t |
eac85310 | 107 | |
9bc4701c MD |
108 | #define scm_i_plugin_cond_init pthread_cond_init |
109 | #define scm_i_plugin_cond_destroy pthread_cond_destroy | |
110 | #define scm_i_plugin_cond_wait pthread_cond_wait | |
111 | #define scm_i_plugin_cond_timedwait pthread_cond_timedwait | |
112 | #define scm_i_plugin_cond_signal pthread_cond_signal | |
113 | #define scm_i_plugin_cond_broadcast pthread_cond_broadcast | |
eac85310 | 114 | |
9bc4701c | 115 | #define scm_t_key pthread_key_t |
eac85310 | 116 | |
9bc4701c MD |
117 | #define scm_i_plugin_key_create pthread_key_create |
118 | #define scm_i_plugin_key_delete pthread_key_delete | |
119 | #define scm_i_plugin_setspecific pthread_setspecific | |
120 | #define scm_i_plugin_getspecific pthread_getspecific | |
eac85310 | 121 | |
9bc4701c | 122 | #define scm_i_plugin_select select |
eac85310 | 123 | |
28d52ebb MD |
124 | void scm_init_pthread_threads (void); |
125 | ||
93cd4dcd | 126 | #endif /* SCM_THREADS_PTHREADS_H */ |
eac85310 MV |
127 | |
128 | /* | |
129 | Local Variables: | |
130 | c-file-style: "gnu" | |
131 | End: | |
132 | */ |