27 #ifndef _GLIBCXX_GCC_GTHR_POSIX_H
28 #define _GLIBCXX_GCC_GTHR_POSIX_H
34 #define __GTHREADS_CXX0X 1
37 #if !defined(_REENTRANT) && defined(__osf__)
44 typedef pthread_t __gthread_t;
45 typedef pthread_key_t __gthread_key_t;
46 typedef pthread_once_t __gthread_once_t;
47 typedef pthread_mutex_t __gthread_mutex_t;
48 typedef pthread_mutex_t __gthread_recursive_mutex_t;
49 typedef pthread_cond_t __gthread_cond_t;
50 typedef struct timespec __gthread_time_t;
54 #define __GTHREAD_HAS_COND 1
56 #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
57 #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
58 #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
59 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
60 #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
61 #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
63 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
65 #define __GTHREAD_COND_INIT PTHREAD_COND_INITIALIZER
66 #define __GTHREAD_TIME_INIT {0,0}
68 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
69 # ifndef __gthrw_pragma
70 # define __gthrw_pragma(pragma)
72 # define __gthrw2(name,name2,type) \
73 static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
74 __gthrw_pragma(weak type)
75 # define __gthrw_(name) __gthrw_ ## name
77 # define __gthrw2(name,name2,type)
78 # define __gthrw_(name) name
82 #define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
87 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
88 #define __gthrw3(name) __gthrw2(__gthrw_ ## name, __ ## name, name)
89 __gthrw3(pthread_once)
90 __gthrw3(pthread_getspecific)
91 __gthrw3(pthread_setspecific)
93 __gthrw3(pthread_create)
94 __gthrw3(pthread_join)
95 __gthrw3(pthread_detach)
96 __gthrw3(pthread_equal)
97 __gthrw3(pthread_self)
98 __gthrw3(pthread_cancel)
101 __gthrw3(pthread_mutex_lock)
102 __gthrw3(pthread_mutex_trylock)
103 #ifdef _POSIX_TIMEOUTS
104 #if _POSIX_TIMEOUTS >= 0
105 __gthrw3(pthread_mutex_timedlock)
108 __gthrw3(pthread_mutex_unlock)
109 __gthrw3(pthread_mutex_init)
110 __gthrw3(pthread_mutex_destroy)
112 __gthrw3(pthread_cond_broadcast)
113 __gthrw3(pthread_cond_signal)
114 __gthrw3(pthread_cond_wait)
115 __gthrw3(pthread_cond_timedwait)
116 __gthrw3(pthread_cond_destroy)
118 __gthrw(pthread_once)
119 __gthrw(pthread_getspecific)
120 __gthrw(pthread_setspecific)
122 __gthrw(pthread_create)
123 __gthrw(pthread_join)
124 __gthrw(pthread_equal)
125 __gthrw(pthread_self)
126 __gthrw(pthread_detach)
127 __gthrw(pthread_cancel)
130 __gthrw(pthread_mutex_lock)
131 __gthrw(pthread_mutex_trylock)
132 #ifdef _POSIX_TIMEOUTS
133 #if _POSIX_TIMEOUTS >= 0
134 __gthrw(pthread_mutex_timedlock)
137 __gthrw(pthread_mutex_unlock)
138 __gthrw(pthread_mutex_init)
139 __gthrw(pthread_mutex_destroy)
141 __gthrw(pthread_cond_broadcast)
142 __gthrw(pthread_cond_signal)
143 __gthrw(pthread_cond_wait)
144 __gthrw(pthread_cond_timedwait)
145 __gthrw(pthread_cond_destroy)
148 __gthrw(pthread_key_create)
149 __gthrw(pthread_key_delete)
150 __gthrw(pthread_mutexattr_init)
151 __gthrw(pthread_mutexattr_settype)
152 __gthrw(pthread_mutexattr_destroy)
155 #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
157 #if defined(__osf__) && defined(_PTHREAD_USE_MANGLED_NAMES_)
158 __gthrw3(pthread_cond_init)
159 __gthrw3(pthread_exit)
161 __gthrw(pthread_cond_init)
162 __gthrw(pthread_exit)
164 #ifdef _POSIX_PRIORITY_SCHEDULING
165 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
166 __gthrw(sched_get_priority_max)
167 __gthrw(sched_get_priority_min)
170 __gthrw(pthread_attr_destroy)
171 __gthrw(pthread_attr_init)
172 __gthrw(pthread_attr_setdetachstate)
173 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
174 __gthrw(pthread_getschedparam)
175 __gthrw(pthread_setschedparam)
179 #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
192 #if defined(__FreeBSD__) || (defined(__sun) && defined(__svr4__))
194 static volatile int __gthread_active = -1;
197 __gthread_trigger (
void)
199 __gthread_active = 1;
203 __gthread_active_p (
void)
205 static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER;
206 static pthread_once_t __gthread_active_once = PTHREAD_ONCE_INIT;
209 int __gthread_active_latest_value = __gthread_active;
214 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
216 if (__gthrw_(pthread_once))
220 __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex);
221 __gthrw_(pthread_once) (&__gthread_active_once, __gthread_trigger);
222 __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex);
226 if (__gthread_active < 0)
227 __gthread_active = 0;
229 __gthread_active_latest_value = __gthread_active;
232 return __gthread_active_latest_value != 0;
238 __gthread_active_p (
void)
240 static void *
const __gthread_active_ptr
241 = __extension__ (
void *) &__gthrw_(pthread_cancel);
242 return __gthread_active_ptr != 0;
266 #if defined(__hppa__) && defined(__hpux__)
268 static volatile int __gthread_active = -1;
271 __gthread_active_p (
void)
274 int __gthread_active_latest_value = __gthread_active;
277 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
279 pthread_default_stacksize_np (0, &__s);
280 __gthread_active = __s ? 1 : 0;
281 __gthread_active_latest_value = __gthread_active;
284 return __gthread_active_latest_value != 0;
290 __gthread_active_p (
void)
309 static pthread_key_t _objc_thread_storage;
310 static pthread_attr_t _objc_thread_attribs;
313 static void *thread_local_storage = NULL;
319 __gthread_objc_init_thread_system (
void)
321 if (__gthread_active_p ())
324 if (__gthrw_(pthread_key_create) (&_objc_thread_storage, NULL) == 0)
329 if (__gthrw_(pthread_attr_init) (&_objc_thread_attribs) == 0
330 && __gthrw_(pthread_attr_setdetachstate) (&_objc_thread_attribs,
331 PTHREAD_CREATE_DETACHED) == 0)
341 __gthread_objc_close_thread_system (
void)
343 if (__gthread_active_p ()
344 && __gthrw_(pthread_key_delete) (_objc_thread_storage) == 0
345 && __gthrw_(pthread_attr_destroy) (&_objc_thread_attribs) == 0)
354 static inline objc_thread_t
355 __gthread_objc_thread_detach (
void (*func)(
void *),
void *
arg)
357 objc_thread_t thread_id;
358 pthread_t new_thread_handle;
360 if (!__gthread_active_p ())
363 if (!(__gthrw_(pthread_create) (&new_thread_handle, NULL, (
void *) func, arg)))
364 thread_id = (objc_thread_t) new_thread_handle;
373 __gthread_objc_thread_set_priority (
int priority)
375 if (!__gthread_active_p ())
379 #ifdef _POSIX_PRIORITY_SCHEDULING
380 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
381 pthread_t thread_id = __gthrw_(pthread_self) ();
383 struct sched_param params;
384 int priority_min, priority_max;
386 if (__gthrw_(pthread_getschedparam) (thread_id, &policy, ¶ms) == 0)
388 if ((priority_max = __gthrw_(sched_get_priority_max) (policy)) == -1)
391 if ((priority_min = __gthrw_(sched_get_priority_min) (policy)) == -1)
394 if (priority > priority_max)
395 priority = priority_max;
396 else if (priority < priority_min)
397 priority = priority_min;
398 params.sched_priority = priority;
405 if (__gthrw_(pthread_setschedparam) (thread_id, policy, ¶ms) == 0)
416 __gthread_objc_thread_get_priority (
void)
418 #ifdef _POSIX_PRIORITY_SCHEDULING
419 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
420 if (__gthread_active_p ())
423 struct sched_param params;
425 if (__gthrw_(pthread_getschedparam) (__gthrw_(pthread_self) (), &policy, ¶ms) == 0)
426 return params.sched_priority;
433 return OBJC_THREAD_INTERACTIVE_PRIORITY;
438 __gthread_objc_thread_yield (
void)
440 if (__gthread_active_p ())
441 __gthrw_(sched_yield) ();
446 __gthread_objc_thread_exit (
void)
448 if (__gthread_active_p ())
450 __gthrw_(pthread_exit) (&__objc_thread_exit_status);
457 static inline objc_thread_t
458 __gthread_objc_thread_id (
void)
460 if (__gthread_active_p ())
461 return (objc_thread_t) __gthrw_(pthread_self) ();
463 return (objc_thread_t) 1;
468 __gthread_objc_thread_set_data (
void *value)
470 if (__gthread_active_p ())
471 return __gthrw_(pthread_setspecific) (_objc_thread_storage, value);
474 thread_local_storage = value;
481 __gthread_objc_thread_get_data (
void)
483 if (__gthread_active_p ())
484 return __gthrw_(pthread_getspecific) (_objc_thread_storage);
486 return thread_local_storage;
493 __gthread_objc_mutex_allocate (objc_mutex_t mutex)
495 if (__gthread_active_p ())
497 mutex->backend = objc_malloc (
sizeof (pthread_mutex_t));
499 if (__gthrw_(pthread_mutex_init) ((pthread_mutex_t *) mutex->backend, NULL))
501 objc_free (mutex->backend);
502 mutex->backend = NULL;
512 __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
514 if (__gthread_active_p ())
525 count = __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend);
531 if (__gthrw_(pthread_mutex_destroy) ((pthread_mutex_t *) mutex->backend))
534 objc_free (mutex->backend);
535 mutex->backend = NULL;
542 __gthread_objc_mutex_lock (objc_mutex_t mutex)
544 if (__gthread_active_p ()
545 && __gthrw_(pthread_mutex_lock) ((pthread_mutex_t *) mutex->backend) != 0)
555 __gthread_objc_mutex_trylock (objc_mutex_t mutex)
557 if (__gthread_active_p ()
558 && __gthrw_(pthread_mutex_trylock) ((pthread_mutex_t *) mutex->backend) != 0)
568 __gthread_objc_mutex_unlock (objc_mutex_t mutex)
570 if (__gthread_active_p ()
571 && __gthrw_(pthread_mutex_unlock) ((pthread_mutex_t *) mutex->backend) != 0)
583 __gthread_objc_condition_allocate (objc_condition_t condition)
585 if (__gthread_active_p ())
587 condition->backend = objc_malloc (
sizeof (pthread_cond_t));
589 if (__gthrw_(pthread_cond_init) ((pthread_cond_t *) condition->backend, NULL))
591 objc_free (condition->backend);
592 condition->backend = NULL;
602 __gthread_objc_condition_deallocate (objc_condition_t condition)
604 if (__gthread_active_p ())
606 if (__gthrw_(pthread_cond_destroy) ((pthread_cond_t *) condition->backend))
609 objc_free (condition->backend);
610 condition->backend = NULL;
617 __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
619 if (__gthread_active_p ())
620 return __gthrw_(pthread_cond_wait) ((pthread_cond_t *) condition->backend,
621 (pthread_mutex_t *) mutex->backend);
628 __gthread_objc_condition_broadcast (objc_condition_t condition)
630 if (__gthread_active_p ())
631 return __gthrw_(pthread_cond_broadcast) ((pthread_cond_t *) condition->backend);
638 __gthread_objc_condition_signal (objc_condition_t condition)
640 if (__gthread_active_p ())
641 return __gthrw_(pthread_cond_signal) ((pthread_cond_t *) condition->backend);
649 __gthread_create (__gthread_t *__threadid,
void *(*__func) (
void*),
652 return __gthrw_(pthread_create) (__threadid, NULL, __func, __args);
656 __gthread_join (__gthread_t __threadid,
void **__value_ptr)
658 return __gthrw_(pthread_join) (__threadid, __value_ptr);
662 __gthread_detach (__gthread_t __threadid)
664 return __gthrw_(pthread_detach) (__threadid);
668 __gthread_equal (__gthread_t __t1, __gthread_t __t2)
670 return __gthrw_(pthread_equal) (__t1, __t2);
673 static inline __gthread_t
674 __gthread_self (
void)
676 return __gthrw_(pthread_self) ();
680 __gthread_yield (
void)
682 return __gthrw_(sched_yield) ();
686 __gthread_once (__gthread_once_t *__once,
void (*__func) (
void))
688 if (__gthread_active_p ())
689 return __gthrw_(pthread_once) (__once, __func);
695 __gthread_key_create (__gthread_key_t *__key,
void (*__dtor) (
void *))
697 return __gthrw_(pthread_key_create) (__key, __dtor);
701 __gthread_key_delete (__gthread_key_t __key)
703 return __gthrw_(pthread_key_delete) (__key);
707 __gthread_getspecific (__gthread_key_t __key)
709 return __gthrw_(pthread_getspecific) (__key);
713 __gthread_setspecific (__gthread_key_t __key,
const void *__ptr)
715 return __gthrw_(pthread_setspecific) (__key, __ptr);
719 __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
721 if (__gthread_active_p ())
722 return __gthrw_(pthread_mutex_destroy) (__mutex);
728 __gthread_mutex_lock (__gthread_mutex_t *__mutex)
730 if (__gthread_active_p ())
731 return __gthrw_(pthread_mutex_lock) (__mutex);
737 __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
739 if (__gthread_active_p ())
740 return __gthrw_(pthread_mutex_trylock) (__mutex);
745 #ifdef _POSIX_TIMEOUTS
746 #if _POSIX_TIMEOUTS >= 0
748 __gthread_mutex_timedlock (__gthread_mutex_t *__mutex,
749 const __gthread_time_t *__abs_timeout)
751 if (__gthread_active_p ())
752 return __gthrw_(pthread_mutex_timedlock) (__mutex, __abs_timeout);
760 __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
762 if (__gthread_active_p ())
763 return __gthrw_(pthread_mutex_unlock) (__mutex);
768 #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
770 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
772 if (__gthread_active_p ())
774 pthread_mutexattr_t __attr;
777 __r = __gthrw_(pthread_mutexattr_init) (&__attr);
779 __r = __gthrw_(pthread_mutexattr_settype) (&__attr,
780 PTHREAD_MUTEX_RECURSIVE);
782 __r = __gthrw_(pthread_mutex_init) (__mutex, &__attr);
784 __r = __gthrw_(pthread_mutexattr_destroy) (&__attr);
792 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
794 return __gthread_mutex_lock (__mutex);
798 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
800 return __gthread_mutex_trylock (__mutex);
803 #ifdef _POSIX_TIMEOUTS
804 #if _POSIX_TIMEOUTS >= 0
806 __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex,
807 const __gthread_time_t *__abs_timeout)
809 return __gthread_mutex_timedlock (__mutex, __abs_timeout);
815 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
817 return __gthread_mutex_unlock (__mutex);
821 __gthread_cond_broadcast (__gthread_cond_t *__cond)
823 return __gthrw_(pthread_cond_broadcast) (__cond);
827 __gthread_cond_signal (__gthread_cond_t *__cond)
829 return __gthrw_(pthread_cond_signal) (__cond);
833 __gthread_cond_wait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex)
835 return __gthrw_(pthread_cond_wait) (__cond, __mutex);
839 __gthread_cond_timedwait (__gthread_cond_t *__cond, __gthread_mutex_t *__mutex,
840 const __gthread_time_t *__abs_timeout)
842 return __gthrw_(pthread_cond_timedwait) (__cond, __mutex, __abs_timeout);
846 __gthread_cond_wait_recursive (__gthread_cond_t *__cond,
847 __gthread_recursive_mutex_t *__mutex)
849 return __gthread_cond_wait (__cond, __mutex);
853 __gthread_cond_timedwait_recursive (__gthread_cond_t *__cond,
854 __gthread_recursive_mutex_t *__mutex,
855 const __gthread_time_t *__abs_timeout)
857 return __gthread_cond_timedwait (__cond, __mutex, __abs_timeout);
861 __gthread_cond_destroy (__gthread_cond_t* __cond)
863 return __gthrw_(pthread_cond_destroy) (__cond);
_Tp arg(const complex< _Tp > &)
Return phase angle of z.