Fix mdoc(7)/man(7) mix up.
[netbsd-mini2440.git] / gnu / lib / libstdc++-v3_4 / arch / mips64el / gthr-default.h
blob3c4a18ab36c8708ea8478c65f974f28ee5233c77
1 /* This file is automatically generated. DO NOT EDIT! */
2 /* Generated from: NetBSD: mknative-gcc,v 1.22 2006/06/25 03:06:15 mrg Exp */
3 /* Generated from: NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp */
5 /* Threads compatibility routines for libgcc2 and libobjc. */
6 /* Compile this one with gcc. */
7 /* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
8 Free Software Foundation, Inc.
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free
14 Software Foundation; either version 2, or (at your option) any later
15 version.
17 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
18 WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 for more details.
22 You should have received a copy of the GNU General Public License
23 along with GCC; see the file COPYING. If not, write to the Free
24 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
25 02110-1301, USA. */
27 /* As a special exception, if you link this library with other files,
28 some of which are compiled with GCC, to produce an executable,
29 this library does not by itself cause the resulting executable
30 to be covered by the GNU General Public License.
31 This exception does not however invalidate any other reasons why
32 the executable file might be covered by the GNU General Public License. */
34 #ifndef _GLIBCXX_GCC_GTHR_POSIX_H
35 #define _GLIBCXX_GCC_GTHR_POSIX_H
37 /* POSIX threads specific definitions.
38 Easy, since the interface is just one-to-one mapping. */
40 #define __GTHREADS 1
42 /* Some implementations of <pthread.h> require this to be defined. */
43 #if !defined(_REENTRANT) && defined(__osf__)
44 #define _REENTRANT 1
45 #endif
47 #include <pthread.h>
48 #include <unistd.h>
50 typedef pthread_key_t __gthread_key_t;
51 typedef pthread_once_t __gthread_once_t;
52 typedef pthread_mutex_t __gthread_mutex_t;
53 typedef pthread_mutex_t __gthread_recursive_mutex_t;
55 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
56 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
57 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
58 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
59 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
60 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
61 #else
62 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
63 #endif
65 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
66 # ifndef __gthrw_pragma
67 # define __gthrw_pragma(pragma)
68 # endif
69 # define __gthrw2(name,name2,type) \
70 extern __typeof(type) name __attribute__ ((__weakref__(#name2))); \
71 __gthrw_pragma(weak type)
72 # define __gthrw_(name) __gthrw_ ## name
73 #else
74 # define __gthrw2(name,name2,type)
75 # define __gthrw_(name) name
76 #endif
78 /* Typically, __gthrw_foo is a weak reference to symbol foo. */
79 #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
81 /* On Tru64, /usr/include/pthread.h uses #pragma extern_prefix "__" to
82 map a subset of the POSIX pthread API to mangled versions of their
83 names. */
84 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
85 #define __gthrw3(name) __gthrw2(__gthrw_ ## name, __ ## name, name)
86 __gthrw3(pthread_once)
87 __gthrw3(pthread_getspecific)
88 __gthrw3(pthread_setspecific)
89 __gthrw3(pthread_create)
90 __gthrw3(pthread_cancel)
91 __gthrw3(pthread_mutex_lock)
92 __gthrw3(pthread_mutex_trylock)
93 __gthrw3(pthread_mutex_unlock)
94 __gthrw3(pthread_mutex_init)
95 #else
96 __gthrw(pthread_once)
97 __gthrw(pthread_getspecific)
98 __gthrw(pthread_setspecific)
99 __gthrw(pthread_create)
100 __gthrw(pthread_cancel)
101 __gthrw(pthread_mutex_lock)
102 __gthrw(pthread_mutex_trylock)
103 __gthrw(pthread_mutex_unlock)
104 __gthrw(pthread_mutex_init)
105 #endif
107 __gthrw(pthread_key_create)
108 __gthrw(pthread_key_delete)
109 __gthrw(pthread_mutexattr_init)
110 __gthrw(pthread_mutexattr_settype)
111 __gthrw(pthread_mutexattr_destroy)
114 #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
115 /* Objective-C. */
116 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
117 __gthrw3(pthread_cond_broadcast)
118 __gthrw3(pthread_cond_destroy)
119 __gthrw3(pthread_cond_init)
120 __gthrw3(pthread_cond_signal)
121 __gthrw3(pthread_cond_wait)
122 __gthrw3(pthread_exit)
123 __gthrw3(pthread_mutex_destroy)
124 __gthrw3(pthread_self)
125 #else
126 __gthrw(pthread_cond_broadcast)
127 __gthrw(pthread_cond_destroy)
128 __gthrw(pthread_cond_init)
129 __gthrw(pthread_cond_signal)
130 __gthrw(pthread_cond_wait)
131 __gthrw(pthread_exit)
132 __gthrw(pthread_mutex_destroy)
133 __gthrw(pthread_self)
134 #endif /* __osf__ && _PTHREAD_USE_MANGLED_NAMES_ */
135 #ifdef _POSIX_PRIORITY_SCHEDULING
136 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
137 __gthrw(sched_get_priority_max)
138 __gthrw(sched_get_priority_min)
139 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
140 #endif /* _POSIX_PRIORITY_SCHEDULING */
141 __gthrw(sched_yield)
142 __gthrw(pthread_attr_destroy)
143 __gthrw(pthread_attr_init)
144 __gthrw(pthread_attr_setdetachstate)
145 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
146 __gthrw(pthread_getschedparam)
147 __gthrw(pthread_setschedparam)
148 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
149 #endif /* _LIBOBJC || _LIBOBJC_WEAK */
151 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
153 static inline int
154 __gthread_active_p (void)
156 static void *const __gthread_active_ptr
157 = __extension__ (void *) &__gthrw_(pthread_cancel);
158 return __gthread_active_ptr != 0;
161 #else /* not __GXX_WEAK__ */
163 static inline int
164 __gthread_active_p (void)
166 return 1;
169 #endif /* __GXX_WEAK__ */
171 #ifdef _LIBOBJC
173 /* This is the config.h file in libobjc/ */
174 #include <config.h>
176 #ifdef HAVE_SCHED_H
177 # include <sched.h>
178 #endif
180 /* Key structure for maintaining thread specific storage */
181 static pthread_key_t _objc_thread_storage;
182 static pthread_attr_t _objc_thread_attribs;
184 /* Thread local storage for a single thread */
185 static void *thread_local_storage = NULL;
187 /* Backend initialization functions */
189 /* Initialize the threads subsystem. */
190 static inline int
191 __gthread_objc_init_thread_system (void)
193 if (__gthread_active_p ())
195 /* Initialize the thread storage key. */
196 if (__gthrw_(pthread_key_create) (&_objc_thread_storage, NULL) == 0)
198 /* The normal default detach state for threads is
199 * PTHREAD_CREATE_JOINABLE which causes threads to not die
200 * when you think they should. */
201 if (__gthrw_(pthread_attr_init) (&_objc_thread_attribs) == 0
202 && __gthrw_(pthread_attr_setdetachstate) (&_objc_thread_attribs,
203 PTHREAD_CREATE_DETACHED) == 0)
204 return 0;
208 return -1;
211 /* Close the threads subsystem. */
212 static inline int
213 __gthread_objc_close_thread_system (void)
215 if (__gthread_active_p ()
216 && __gthrw_(pthread_key_delete) (_objc_thread_storage) == 0
217 && __gthrw_(pthread_attr_destroy) (&_objc_thread_attribs) == 0)
218 return 0;
220 return -1;
223 /* Backend thread functions */
225 /* Create a new thread of execution. */
226 static inline objc_thread_t
227 __gthread_objc_thread_detach (void (*func)(void *), void *arg)
229 objc_thread_t thread_id;
230 pthread_t new_thread_handle;
232 if (!__gthread_active_p ())
233 return NULL;
235 if (!(__gthrw_(pthread_create) (&new_thread_handle, NULL, (void *) func, arg)))
236 thread_id = (objc_thread_t) new_thread_handle;
237 else
238 thread_id = NULL;
240 return thread_id;
243 /* Set the current thread's priority. */
244 static inline int
245 __gthread_objc_thread_set_priority (int priority)
247 if (!__gthread_active_p ())
248 return -1;
249 else
251 #ifdef _POSIX_PRIORITY_SCHEDULING
252 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
253 pthread_t thread_id = __gthrw_(pthread_self) ();
254 int policy;
255 struct sched_param params;
256 int priority_min, priority_max;
258 if (__gthrw_(pthread_getschedparam) (thread_id, &policy, &params) == 0)
260 if ((priority_max = __gthrw_(sched_get_priority_max) (policy)) == -1)
261 return -1;
263 if ((priority_min = __gthrw_(sched_get_priority_min) (policy)) == -1)
264 return -1;
266 if (priority > priority_max)
267 priority = priority_max;
268 else if (priority < priority_min)
269 priority = priority_min;
270 params.sched_priority = priority;
273 * The solaris 7 and several other man pages incorrectly state that
274 * this should be a pointer to policy but pthread.h is universally
275 * at odds with this.
277 if (__gthrw_(pthread_setschedparam) (thread_id, policy, &params) == 0)
278 return 0;
280 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
281 #endif /* _POSIX_PRIORITY_SCHEDULING */
282 return -1;
286 /* Return the current thread's priority. */
287 static inline int
288 __gthread_objc_thread_get_priority (void)
290 #ifdef _POSIX_PRIORITY_SCHEDULING
291 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
292 if (__gthread_active_p ())
294 int policy;
295 struct sched_param params;
297 if (__gthrw_(pthread_getschedparam) (__gthrw_(pthread_self) (), &policy, &params) == 0)
298 return params.sched_priority;
299 else
300 return -1;
302 else
303 #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
304 #endif /* _POSIX_PRIORITY_SCHEDULING */
305 return OBJC_THREAD_INTERACTIVE_PRIORITY;
308 /* Yield our process time to another thread. */
309 static inline void
310 __gthread_objc_thread_yield (void)
312 if (__gthread_active_p ())
313 __gthrw_(sched_yield) ();
316 /* Terminate the current thread. */
317 static inline int
318 __gthread_objc_thread_exit (void)
320 if (__gthread_active_p ())
321 /* exit the thread */
322 __gthrw_(pthread_exit) (&__objc_thread_exit_status);
324 /* Failed if we reached here */
325 return -1;
328 /* Returns an integer value which uniquely describes a thread. */
329 static inline objc_thread_t
330 __gthread_objc_thread_id (void)
332 if (__gthread_active_p ())
333 return (objc_thread_t) __gthrw_(pthread_self) ();
334 else
335 return (objc_thread_t) 1;
338 /* Sets the thread's local storage pointer. */
339 static inline int
340 __gthread_objc_thread_set_data (void *value)
342 if (__gthread_active_p ())
343 return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
344 else
346 thread_local_storage = value;
347 return 0;
351 /* Returns the thread's local storage pointer. */
352 static inline void *
353 __gthread_objc_thread_get_data (void)
355 if (__gthread_active_p ())
356 return __gthrw_(pthread_getspecific) (_objc_thread_storage);
357 else
358 return thread_local_storage;
361 /* Backend mutex functions */
363 /* Allocate a mutex. */
364 static inline int
365 __gthread_objc_mutex_allocate (objc_mutex_t mutex)
367 if (__gthread_active_p ())
369 mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
371 if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend, NULL))
373 objc_free (mutex->backend);
374 mutex->backend = NULL;
375 return -1;
379 return 0;
382 /* Deallocate a mutex. */
383 static inline int
384 __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
386 if (__gthread_active_p ())
388 int count;
391 * Posix Threads specifically require that the thread be unlocked
392 * for __gthrw_(pthread_mutex_destroy) to work.
397 count = __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
398 if (count < 0)
399 return -1;
401 while (count);
403 if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
404 return -1;
406 objc_free (mutex->backend);
407 mutex->backend = NULL;
409 return 0;
412 /* Grab a lock on a mutex. */
413 static inline int
414 __gthread_objc_mutex_lock (objc_mutex_t mutex)
416 if (__gthread_active_p ()
417 && __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend) != 0)
419 return -1;
422 return 0;
425 /* Try to grab a lock on a mutex. */
426 static inline int
427 __gthread_objc_mutex_trylock (objc_mutex_t mutex)
429 if (__gthread_active_p ()
430 && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 0)
432 return -1;
435 return 0;
438 /* Unlock the mutex */
439 static inline int
440 __gthread_objc_mutex_unlock (objc_mutex_t mutex)
442 if (__gthread_active_p ()
443 && __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend) != 0)
445 return -1;
448 return 0;
451 /* Backend condition mutex functions */
453 /* Allocate a condition. */
454 static inline int
455 __gthread_objc_condition_allocate (objc_condition_t condition)
457 if (__gthread_active_p ())
459 condition->backend = objc_malloc (sizeof (pthread_cond_t));
461 if (__gthrw_(pthread_cond_init) ((pthread_cond_t *) condition->backend, NULL))
463 objc_free (condition->backend);
464 condition->backend = NULL;
465 return -1;
469 return 0;
472 /* Deallocate a condition. */
473 static inline int
474 __gthread_objc_condition_deallocate (objc_condition_t condition)
476 if (__gthread_active_p ())
478 if (__gthrw_(pthread_cond_destroy) ((pthread_cond_t *) condition->backend))
479 return -1;
481 objc_free (condition->backend);
482 condition->backend = NULL;
484 return 0;
487 /* Wait on the condition */
488 static inline int
489 __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
491 if (__gthread_active_p ())
492 return __gthrw_(pthread_cond_wait) ((pthread_cond_t *) condition->backend,
493 (pthread_mutex_t *) mutex->backend);
494 else
495 return 0;
498 /* Wake up all threads waiting on this condition. */
499 static inline int
500 __gthread_objc_condition_broadcast (objc_condition_t condition)
502 if (__gthread_active_p ())
503 return __gthrw_(pthread_cond_broadcast) ((pthread_cond_t *) condition->backend);
504 else
505 return 0;
508 /* Wake up one thread waiting on this condition. */
509 static inline int
510 __gthread_objc_condition_signal (objc_condition_t condition)
512 if (__gthread_active_p ())
513 return __gthrw_(pthread_cond_signal) ((pthread_cond_t *) condition->backend);
514 else
515 return 0;
518 #else /* _LIBOBJC */
520 static inline int
521 __gthread_once (__gthread_once_t *once, void (*func) (void))
523 if (__gthread_active_p ())
524 return __gthrw_(pthread_once) (once, func);
525 else
526 return -1;
529 static inline int
530 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
532 return __gthrw_(pthread_key_create) (key, dtor);
535 static inline int
536 __gthread_key_delete (__gthread_key_t key)
538 return __gthrw_(pthread_key_delete) (key);
541 static inline void *
542 __gthread_getspecific (__gthread_key_t key)
544 return __gthrw_(pthread_getspecific) (key);
547 static inline int
548 __gthread_setspecific (__gthread_key_t key, const void *ptr)
550 return __gthrw_(pthread_setspecific) (key, ptr);
553 static inline int
554 __gthread_mutex_lock (__gthread_mutex_t *mutex)
556 if (__gthread_active_p ())
557 return __gthrw_(pthread_mutex_lock) (mutex);
558 else
559 return 0;
562 static inline int
563 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
565 if (__gthread_active_p ())
566 return __gthrw_(pthread_mutex_trylock) (mutex);
567 else
568 return 0;
571 static inline int
572 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
574 if (__gthread_active_p ())
575 return __gthrw_(pthread_mutex_unlock) (mutex);
576 else
577 return 0;
580 #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
581 static inline int
582 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
584 if (__gthread_active_p ())
586 pthread_mutexattr_t attr;
587 int r;
589 r = __gthrw_(pthread_mutexattr_init) (&attr);
590 if (!r)
591 r = __gthrw_(pthread_mutexattr_settype) (&attr, PTHREAD_MUTEX_RECURSIVE);
592 if (!r)
593 r = __gthrw_(pthread_mutex_init) (mutex, &attr);
594 if (!r)
595 r = __gthrw_(pthread_mutexattr_destroy) (&attr);
596 return r;
598 return 0;
600 #endif
602 static inline int
603 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
605 return __gthread_mutex_lock (mutex);
608 static inline int
609 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
611 return __gthread_mutex_trylock (mutex);
614 static inline int
615 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
617 return __gthread_mutex_unlock (mutex);
620 #endif /* _LIBOBJC */
622 #endif /* ! _GLIBCXX_GCC_GTHR_POSIX_H */