]>
Commit | Line | Data |
---|---|---|
f24af81b TT |
1 | |
2 | /* Compile this one with gcc. */ | |
3 | /* Copyright (C) 1997 Free Software Foundation, Inc. | |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, 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 | ||
40 | typedef pthread_key_t __gthread_key_t; | |
41 | typedef pthread_once_t __gthread_once_t; | |
42 | typedef 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 | ||
61 | static void *__gthread_active_ptr = &pthread_create; | |
62 | ||
63 | static 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 | ||
71 | static inline int | |
d1e51320 | 72 | __gthread_active_p (void) |
f24af81b TT |
73 | { |
74 | return 1; | |
75 | } | |
76 | ||
77 | #endif /* SUPPORTS_WEAK */ | |
78 | ||
79 | static 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 | ||
88 | static inline int | |
89 | __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *)) | |
90 | { | |
91 | return pthread_keycreate (key, dtor); | |
92 | } | |
93 | ||
94 | static inline int | |
95 | __gthread_key_dtor (__gthread_key_t key, void *ptr) | |
96 | { | |
97 | /* Nothing needed. */ | |
98 | return 0; | |
99 | } | |
100 | ||
101 | static inline int | |
102 | __gthread_key_delete (__gthread_key_t key) | |
103 | { | |
104 | return pthread_key_delete (key); | |
105 | } | |
106 | ||
107 | static 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 | ||
117 | static inline int | |
118 | __gthread_setspecific (__gthread_key_t key, const void *ptr) | |
119 | { | |
120 | return pthread_setspecific (key, (void *) ptr); | |
121 | } | |
122 | ||
123 | static 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 | ||
132 | static 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 | ||
141 | static 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 */ |