* cp-tree.def (FUNCTION_NAME): New tree node.
[official-gcc.git] / gcc / gthr-dce.h
blob3cba8a0e4b867b6a23117e3700befc5439596400
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1997 Free Software Foundation, Inc.
5 This file is part of GNU CC.
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.
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.
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. */
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. */
29 #ifndef __gthr_dce_h
30 #define __gthr_dce_h
32 /* DCE threads interface.
33 DCE threads are based on POSIX threads draft 4, and many things
34 have changed since then. */
36 #define __GTHREADS 1
38 #include <pthread.h>
40 typedef pthread_key_t __gthread_key_t;
41 typedef pthread_once_t __gthread_once_t;
42 typedef pthread_mutex_t __gthread_mutex_t;
44 #define __GTHREAD_ONCE_INIT pthread_once_init
45 /* Howto define __GTHREAD_MUTEX_INIT? */
47 #if SUPPORTS_WEAK && GTHREAD_USE_WEAK
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
57 #pragma weak pthread_mutex_lock
58 #pragma weak pthread_mutex_trylock
59 #pragma weak pthread_mutex_unlock
61 static void *__gthread_active_ptr = &pthread_create;
63 static inline int
64 __gthread_active_p ()
66 return __gthread_active_ptr != 0;
69 #else /* not SUPPORTS_WEAK */
71 static inline int
72 __gthread_active_p ()
74 return 1;
77 #endif /* SUPPORTS_WEAK */
79 static inline int
80 __gthread_once (__gthread_once_t *once, void (*func) ())
82 if (__gthread_active_p ())
83 return pthread_once (once, func);
84 else
85 return -1;
88 static inline int
89 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
91 return pthread_keycreate (key, dtor);
94 static inline int
95 __gthread_key_dtor (__gthread_key_t key, void *ptr)
97 /* Nothing needed. */
98 return 0;
101 static inline int
102 __gthread_key_delete (__gthread_key_t key)
104 return pthread_key_delete (key);
107 static inline void *
108 __gthread_getspecific (__gthread_key_t key)
110 void *ptr;
111 if (pthread_getspecific (key, &ptr) == 0)
112 return ptr;
113 else
114 return 0;
117 static inline int
118 __gthread_setspecific (__gthread_key_t key, const void *ptr)
120 return pthread_setspecific (key, (void *) ptr);
123 static inline int
124 __gthread_mutex_lock (__gthread_mutex_t *mutex)
126 if (__gthread_active_p ())
127 return pthread_mutex_lock (mutex);
128 else
129 return 0;
132 static inline int
133 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
135 if (__gthread_active_p ())
136 return pthread_mutex_trylock (mutex);
137 else
138 return 0;
141 static inline int
142 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
144 if (__gthread_active_p ())
145 return pthread_mutex_unlock (mutex);
146 else
147 return 0;
150 #endif /* not __gthr_dce_h */