* threads.c (scm_thread): Removed filed joining_threads.
[bpt/guile.git] / libguile / pthread-threads.h
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
49 /* The pthreads-threads implementation. This is a direct mapping.
50 */
51
52 /* This is an interface between Guile and the pthreads thread package. */
53
54 #include <pthread.h>
55 #include <sched.h>
56
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
64
65 #define scm_i_plugin_thread_create pthread_create
66
67 #define scm_i_plugin_thread_join pthread_join
68 #define scm_i_plugin_thread_detach pthread_detach
69 #define scm_i_plugin_thread_self pthread_self
70 #define scm_i_plugin_thread_yield sched_yield
71
72 /* Size is checked in scm_init_pthread_threads */
73 #ifdef SCM_DEBUG_THREADS
74 #define SCM_MUTEX_MAXSIZE (9 * sizeof (long))
75 #else
76 #define SCM_MUTEX_MAXSIZE (6 * sizeof (long))
77 #endif
78 typedef struct { char _[SCM_MUTEX_MAXSIZE]; } scm_t_mutex;
79 #define scm_t_mutexattr pthread_mutexattr_t
80
81 extern scm_t_mutexattr scm_i_plugin_mutex; /* The "fast" mutex. */
82
83 #ifdef SCM_DEBUG_THREADS
84 int scm_i_plugin_mutex_init (scm_t_mutex *, const scm_t_mutexattr *);
85 int scm_i_plugin_mutex_lock (scm_t_mutex *);
86 int scm_i_plugin_mutex_unlock (scm_t_mutex *);
87 #else
88 #define scm_i_plugin_mutex_init(m,a) \
89 pthread_mutex_init ((pthread_mutex_t *) (m), (a))
90 #define scm_i_plugin_mutex_lock(m) \
91 pthread_mutex_lock ((pthread_mutex_t *) (m))
92 #define scm_i_plugin_mutex_unlock(m) \
93 pthread_mutex_unlock ((pthread_mutex_t *) (m))
94 #endif
95 #define scm_i_plugin_mutex_destroy(m) \
96 pthread_mutex_destroy ((pthread_mutex_t *) (m))
97 #define scm_i_plugin_mutex_trylock(m) \
98 pthread_mutex_trylock ((pthread_mutex_t *) (m))
99
100 /* Size is checked in scm_init_pthread_threads */
101 #ifdef SCM_DEBUG_THREADS
102 #define SCM_REC_MUTEX_MAXSIZE (SCM_MUTEX_MAXSIZE + 3 * sizeof (long))
103 #else
104 #ifdef SCM_MUTEX_RECURSIVE
105 #define SCM_REC_MUTEX_MAXSIZE SCM_MUTEX_MAXSIZE
106 #else
107 #define SCM_REC_MUTEX_MAXSIZE (SCM_MUTEX_MAXSIZE + 2 * sizeof (long))
108 #endif
109 #endif
110 typedef struct { char _[SCM_REC_MUTEX_MAXSIZE]; } scm_t_rec_mutex;
111
112 extern scm_t_mutexattr scm_i_plugin_rec_mutex;
113
114 #if defined (SCM_MUTEX_RECURSIVE) && !defined (SCM_DEBUG_THREADS)
115 /* pthreads has recursive mutexes! */
116 #define scm_i_plugin_rec_mutex_init(m,a) \
117 pthread_mutex_init ((pthread_mutex_t *) (m), (a))
118 #define scm_i_plugin_rec_mutex_destroy(m) \
119 pthread_mutex_destroy ((pthread_mutex_t *) (m))
120 #define scm_i_plugin_rec_mutex_lock(m) \
121 pthread_mutex_lock ((pthread_mutex_t *) (m))
122 #define scm_i_plugin_rec_mutex_trylock(m) \
123 pthread_mutex_trylock ((pthread_mutex_t *) (m))
124 #define scm_i_plugin_rec_mutex_unlock(m) \
125 pthread_mutex_unlock ((pthread_mutex_t *) (m))
126 #else
127 int scm_i_plugin_rec_mutex_init (scm_t_rec_mutex *, const scm_t_mutexattr *);
128 #define scm_i_plugin_rec_mutex_destroy(mx) do { (void) (mx); } while (0)
129 int scm_i_plugin_rec_mutex_lock (scm_t_rec_mutex *);
130 int scm_i_plugin_rec_mutex_trylock (scm_t_rec_mutex *);
131 int scm_i_plugin_rec_mutex_unlock (scm_t_rec_mutex *);
132 #endif
133
134 #define scm_t_cond pthread_cond_t
135
136 #define scm_i_plugin_cond_init pthread_cond_init
137 #define scm_i_plugin_cond_destroy pthread_cond_destroy
138 #define scm_i_plugin_cond_wait(c, m) \
139 pthread_cond_wait ((c), (pthread_mutex_t *) (m))
140 #define scm_i_plugin_cond_timedwait(c, m, t) \
141 pthread_cond_timedwait ((c), (pthread_mutex_t *) (m), (t))
142 #define scm_i_plugin_cond_signal pthread_cond_signal
143 #define scm_i_plugin_cond_broadcast pthread_cond_broadcast
144
145 #define scm_t_key pthread_key_t
146
147 #define scm_i_plugin_key_create pthread_key_create
148 #define scm_i_plugin_key_delete pthread_key_delete
149 #define scm_i_plugin_setspecific pthread_setspecific
150 #define scm_i_plugin_getspecific pthread_getspecific
151
152 #define scm_i_plugin_select select
153
154 void scm_init_pthread_threads (void);
155
156 #endif /* SCM_THREADS_PTHREADS_H */
157
158 /*
159 Local Variables:
160 c-file-style: "gnu"
161 End:
162 */