]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gthr-dce.h
Oops, missed ChangeLog in last checkin...
[thirdparty/gcc.git] / gcc / gthr-dce.h
CommitLineData
f24af81b
TT
1
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 __gthr_dce_h
30#define __gthr_dce_h
31
32/* DCE threads interface.
33 DCE threads are based on POSIX threads draft 4, and many things
34 have changed since then. */
35
36#define __GTHREADS 1
37
38#include <pthread.h>
39
40typedef pthread_key_t __gthread_key_t;
41typedef pthread_once_t __gthread_once_t;
42typedef pthread_mutex_t __gthread_mutex_t;
43
44#define __GTHREAD_ONCE_INIT pthread_once_init
45/* Howto define __GTHREAD_MUTEX_INIT? */
46
47#if SUPPORTS_WEAK && GTHREAD_USE_WEAK
48
49#pragma weak pthread_once
50#pragma weak pthread_once_init
51#pragma weak pthread_key_create
52#pragma weak pthread_key_delete
53#pragma weak pthread_getspecific
54#pragma weak pthread_setspecific
55#pragma weak pthread_create
56
57#pragma weak pthread_mutex_lock
58#pragma weak pthread_mutex_trylock
59#pragma weak pthread_mutex_unlock
60
61static void *__gthread_active_ptr = &pthread_create;
62
63static inline int
d1e51320 64__gthread_active_p (void)
f24af81b
TT
65{
66 return __gthread_active_ptr != 0;
67}
68
69#else /* not SUPPORTS_WEAK */
70
71static inline int
d1e51320 72__gthread_active_p (void)
f24af81b
TT
73{
74 return 1;
75}
76
77#endif /* SUPPORTS_WEAK */
78
79static inline int
d1e51320 80__gthread_once (__gthread_once_t *once, void (*func) (void))
f24af81b
TT
81{
82 if (__gthread_active_p ())
83 return pthread_once (once, func);
84 else
85 return -1;
86}
87
88static inline int
89__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
90{
91 return pthread_keycreate (key, dtor);
92}
93
94static inline int
95__gthread_key_dtor (__gthread_key_t key, void *ptr)
96{
97 /* Nothing needed. */
98 return 0;
99}
100
101static inline int
102__gthread_key_delete (__gthread_key_t key)
103{
104 return pthread_key_delete (key);
105}
106
107static inline void *
108__gthread_getspecific (__gthread_key_t key)
109{
110 void *ptr;
111 if (pthread_getspecific (key, &ptr) == 0)
112 return ptr;
113 else
114 return 0;
115}
116
117static inline int
118__gthread_setspecific (__gthread_key_t key, const void *ptr)
119{
120 return pthread_setspecific (key, (void *) ptr);
121}
122
123static inline int
124__gthread_mutex_lock (__gthread_mutex_t *mutex)
125{
126 if (__gthread_active_p ())
127 return pthread_mutex_lock (mutex);
128 else
129 return 0;
130}
131
132static inline int
133__gthread_mutex_trylock (__gthread_mutex_t *mutex)
134{
135 if (__gthread_active_p ())
136 return pthread_mutex_trylock (mutex);
137 else
138 return 0;
139}
140
141static inline int
142__gthread_mutex_unlock (__gthread_mutex_t *mutex)
143{
144 if (__gthread_active_p ())
145 return pthread_mutex_unlock (mutex);
146 else
147 return 0;
148}
149
150#endif /* not __gthr_dce_h */