The FSF has a new address.
[bpt/guile.git] / libguile / null-threads.h
1 /* classes: h_files */
2
3 #ifndef SCM_NULL_THREADS_H
4 #define SCM_NULL_THREADS_H
5
6 /* Copyright (C) 2005 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 null-threads implementation. We provide the subset of the
26 standard pthread API that is used by Guile, but no new threads can
27 be created.
28
29 This file merely exits so that Guile can be compiled and run
30 without using pthreads. Improving performance via optimizations
31 that are possible in a single-threaded program is not a primary
32 goal.
33 */
34
35 #include <errno.h>
36
37 /* Threads
38 */
39 #define scm_i_pthread_t int
40 #define scm_i_pthread_self() 0
41 #define scm_i_pthread_create(t,a,f,d) (*(t)=0, (void)(f), ENOSYS)
42 #define scm_i_pthread_detach(t) do { } while (0)
43 #define scm_i_pthread_exit(v) exit(0)
44 #define scm_i_sched_yield() 0
45
46 /* Signals
47 */
48 #define scm_i_pthread_sigmask sigprocmask
49
50 /* Mutexes
51 */
52 #define SCM_I_PTHREAD_MUTEX_INITIALIZER 0
53 #define SCM_I_PTHREAD_RECURSIVE_MUTEX_INITIALIZER 0
54 #define scm_i_pthread_mutex_t int
55 #define scm_i_pthread_mutex_init(m,a) (*(m) = 0)
56 #define scm_i_pthread_mutex_destroy(m) do { (void)(m); } while(0)
57 #define scm_i_pthread_mutex_trylock(m) ((*(m))++)
58 #define scm_i_pthread_mutex_lock(m) ((*(m))++)
59 #define scm_i_pthread_mutex_unlock(m) ((*(m))--)
60
61 /* Condition variables
62 */
63 #define SCM_I_PTHREAD_COND_INITIALIZER 0
64 #define scm_i_pthread_cond_t int
65 #define scm_i_pthread_cond_init(c,a) (*(c) = 0)
66 #define scm_i_pthread_cond_destroy(c) do { (void)(c); } while(0)
67 #define scm_i_pthread_cond_signal(c) (*(c) = 1)
68 #define scm_i_pthread_cond_broadcast(c) (*(c) = 1)
69 #define scm_i_pthread_cond_wait(c,m) (abort(), 0)
70 #define scm_i_pthread_cond_timedwait(c,m,t) (abort(), 0)
71
72 /* Onces
73 */
74 #define scm_i_pthread_once_t int
75 #define SCM_I_PTHREAD_ONCE_INIT 0
76 #define scm_i_pthread_once(o,f) do { \
77 if(!*(o)) { *(o)=1; f (); } \
78 } while(0)
79
80 /* Thread specific storage
81 */
82 typedef struct scm_i_pthread_key_t {
83 struct scm_i_pthread_key_t *next;
84 void *value;
85 void (*destr_func) (void *);
86 } scm_i_pthread_key_t;
87
88 SCM_API int scm_i_pthread_key_create (scm_i_pthread_key_t *key,
89 void (*destr_func) (void *));
90 #define scm_i_pthread_setspecific(k,p) ((k).value = (p))
91 #define scm_i_pthread_getspecific(k) ((k).value)
92
93 /* Convenience functions
94 */
95 #define scm_i_scm_pthread_mutex_lock scm_i_pthread_mutex_lock
96 #define scm_i_frame_pthread_mutex_lock scm_i_pthread_mutex_lock
97 #define scm_i_scm_pthread_cond_wait scm_i_pthread_cond_wait
98 #define scm_i_scm_pthread_cond_timedwait scm_i_pthread_cond_timedwait
99
100
101 #endif /* SCM_NULL_THREADS_H */
102
103 /*
104 Local Variables:
105 c-file-style: "gnu"
106 End:
107 */