]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/libgcc-thr.h
libstdc++.exp (test_libstdc++): Set LD_LIBRARY_PATH and SHLIB_PATH appropriately.
[thirdparty/gcc.git] / gcc / libgcc-thr.h
CommitLineData
c404fea2
TT
1/* Threads compatibily routines for libgcc2. */
2/* Compile this one with gcc. */
3/* Copyright (C) 1997 Free Software Foundation, Inc.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22/* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
28
29#ifndef __libgcc_thr_h
30#define __libgcc_thr_h
31
32/* If this file is compiled with threads support, it must
33 #define __GTHREADS 1
34 to indicate that threads support is present.
35
36 The threads interface must define the following types:
37 __gthread_key_t
38 __gthread_once_t
39 __gthread_mutex_t
40
41 The threads interface must define the following macros:
42
43 __GTHREAD_ONCE_INIT
44 to initialize __gthread_once_t
45 __GTHREAD_MUTEX_INIT
46 to initialize __gthread_mutex_t to get a fast
47 non-recursive mutex.
48
49 The threads interface must define the following static functions:
50
51 int __gthread_once (__gthread_once_t *once, void (*func) ())
52
53 int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
54 int __gthread_key_delete (__gthread_key_t key)
55
56 void *__gthread_getspecific (__gthread_key_t key)
57 int __gthread_setspecific (__gthread_key_t key, const void *ptr)
58
59 int __gthread_mutex_lock (__gthread_mutex_t *mutex);
60 int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
61 int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
62
63 All functions returning int should return 0 on success, -1 on error.
64
65 Currently supported threads packages are
66 POSIX threads with -D_PTHREADS
67 DCE threads with -D_DCE_THREADS
68 Solaris/UI threads with -D_SOLARIS_THREADS
69*/
70
71#if _PTHREADS
72/* POSIX threads specific definitions.
73 Easy, since the interface is just one-to-one mapping. */
74
75#define __GTHREADS 1
76
77#include <pthread.h>
78
79typedef pthread_key_t __gthread_key_t;
80typedef pthread_once_t __gthread_once_t;
81typedef pthread_mutex_t __gthread_mutex_t;
82
83#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
84#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
85
86static inline int
87__gthread_once (__gthread_once_t *once, void (*func) ())
88{
89 return pthread_once (once, func);
90}
91
92static inline int
93__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
94{
95 return pthread_key_create (key, dtor);
96}
97
98static inline int
99__gthread_key_delete (__gthread_key_t key)
100{
101 return pthread_key_delete (key);
102}
103
104static inline void *
105__gthread_getspecific (__gthread_key_t key)
106{
107 return pthread_getspecific (key);
108}
109
110static inline int
111__gthread_setspecific (__gthread_key_t key, const void *ptr)
112{
113 return pthread_setspecific (key, ptr);
114}
115
116static inline int
117__gthread_mutex_lock (__gthread_mutex_t *mutex)
118{
119 return pthread_mutex_lock (mutex);
120}
121
122static inline int
123__gthread_mutex_trylock (__gthread_mutex_t *mutex)
124{
125 return pthread_mutex_trylock (mutex);
126}
127
128static inline int
129__gthread_mutex_unlock (__gthread_mutex_t *mutex)
130{
131 return pthread_mutex_unlock (mutex);
132}
133
134#elif _DCE_THREADS
135/* DCE threads interface.
136 DCE threads are based on POSIX threads draft 4, and many things
137 have changed since then. */
138
139#define __GTHREADS 1
140
141#include <pthread.h>
142
143typedef pthread_key_t __gthread_key_t;
144typedef pthread_once_t __gthread_once_t;
145typedef pthread_mutex_t __gthread_mutex_t;
146
147#define __GTHREAD_ONCE_INIT pthread_once_init
148/* Howto define __GTHREAD_MUTEX_INIT? */
149
150static inline int
151__gthread_once (__gthread_once_t *once, void (*func) ())
152{
153 return pthread_once (once, func);
154}
155
156static inline int
157__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
158{
159 return pthread_keycreate (key, dtor);
160}
161
162static inline int
163__gthread_key_delete (__gthread_key_t key)
164{
165 return pthread_key_delete (key);
166}
167
168static inline void *
169__gthread_getspecific (__gthread_key_t key)
170{
171 void *ptr;
172 if (pthread_getspecific (key, &ptr) == 0)
173 return ptr;
174 else
175 return 0;
176}
177
178static inline int
179__gthread_setspecific (__gthread_key_t key, const void *ptr)
180{
181 return pthread_setspecific (key, (void *) ptr);
182}
183
184static inline int
185__gthread_mutex_lock (__gthread_mutex_t *mutex)
186{
187 return pthread_mutex_lock (mutex);
188}
189
190static inline int
191__gthread_mutex_trylock (__gthread_mutex_t *mutex)
192{
193 return pthread_mutex_trylock (mutex);
194}
195
196static inline int
197__gthread_mutex_unlock (__gthread_mutex_t *mutex)
198{
199 return pthread_mutex_unlock (mutex);
200}
201
202#elif _SOLARIS_THREADS
203/* Solaris threads as found in Solaris 2.[456].
204 Actually these are Unix International (UI) threads, but I don't
205 know if anyone else implements these. */
206
207#define __GTHREADS 1
208
209#include <thread.h>
210#include <errno.h>
211
212typedef thread_key_t __gthread_key_t;
213typedef struct
214{
215 mutex_t mutex;
216 int once;
217} __gthread_once_t;
218typedef mutex_t __gthread_mutex_t;
219
220#define __GTHREAD_ONCE_INIT { DEFAULTMUTEX, 0 }
221#define __GTHREAD_MUTEX_INIT DEFAULTMUTEX
222
223static inline int
224__gthread_once (__gthread_once_t *once, void (*func) ())
225{
226 if (once == 0 || func == 0)
227 {
228 errno = EINVAL;
229 return -1;
230 }
231
232 if (once->once == 0)
233 {
234 if (mutex_lock (&once->mutex) != 0)
235 return -1;
236 if (once->once == 0)
237 {
238 (*func) ();
239 once->once ++;
240 }
241 mutex_unlock (&once->mutex);
242 }
243 return 0;
244}
245
246static inline int
247__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
248{
249 return thr_keycreate (key, dtor);
250}
251
252static inline int
253__gthread_key_delete (__gthread_key_t key)
254{
255 /* Not possible. */
256 return -1;
257}
258
259static inline void *
260__gthread_getspecific (__gthread_key_t key)
261{
262 void *ptr;
263 if (thr_getspecific (key, &ptr) == 0)
264 return ptr;
265 else
266 return 0;
267}
268
269static inline int
270__gthread_setspecific (__gthread_key_t key, const void *ptr)
271{
272 return thr_setspecific (key, (void *) ptr);
273}
274
275static inline int
276__gthread_mutex_lock (__gthread_mutex_t *mutex)
277{
278 return mutex_lock (mutex);
279}
280
281static inline int
282__gthread_mutex_trylock (__gthread_mutex_t *mutex)
283{
284 return mutex_trylock (mutex);
285}
286
287static inline int
288__gthread_mutex_unlock (__gthread_mutex_t *mutex)
289{
290 return mutex_unlock (mutex);
291}
292
293#else /* no threads */
294
295/* Just provide compatibility for mutex handling. */
296
297typedef int __gthread_mutex_t;
298
299#define __GTHREAD_MUTEX_INIT 0
300
301static inline int
302__gthread_mutex_lock (__gthread_mutex_t *mutex)
303{
304 return 0;
305}
306
307static inline int
308__gthread_mutex_trylock (__gthread_mutex_t *mutex)
309{
310 return 0;
311}
312
313static inline int
314__gthread_mutex_unlock (__gthread_mutex_t *mutex)
315{
316 return 0;
317}
318
319#endif /* no threads */
320
321#endif /* not __libgcc_thr_h */