1*e4b17023SJohn Marino /* Threads compatibility routines for libgcc2. */ 2*e4b17023SJohn Marino /* Compile this one with gcc. */ 3*e4b17023SJohn Marino /* Copyright (C) 1997, 1998, 2004, 2008, 2009, 2011 4*e4b17023SJohn Marino Free Software Foundation, Inc. 5*e4b17023SJohn Marino 6*e4b17023SJohn Marino This file is part of GCC. 7*e4b17023SJohn Marino 8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 11*e4b17023SJohn Marino version. 12*e4b17023SJohn Marino 13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16*e4b17023SJohn Marino for more details. 17*e4b17023SJohn Marino 18*e4b17023SJohn Marino Under Section 7 of GPL version 3, you are granted additional 19*e4b17023SJohn Marino permissions described in the GCC Runtime Library Exception, version 20*e4b17023SJohn Marino 3.1, as published by the Free Software Foundation. 21*e4b17023SJohn Marino 22*e4b17023SJohn Marino You should have received a copy of the GNU General Public License and 23*e4b17023SJohn Marino a copy of the GCC Runtime Library Exception along with this program; 24*e4b17023SJohn Marino see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 25*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 26*e4b17023SJohn Marino 27*e4b17023SJohn Marino #ifndef GCC_GTHR_H 28*e4b17023SJohn Marino #define GCC_GTHR_H 29*e4b17023SJohn Marino 30*e4b17023SJohn Marino #ifndef HIDE_EXPORTS 31*e4b17023SJohn Marino #pragma GCC visibility push(default) 32*e4b17023SJohn Marino #endif 33*e4b17023SJohn Marino 34*e4b17023SJohn Marino /* If this file is compiled with threads support, it must 35*e4b17023SJohn Marino #define __GTHREADS 1 36*e4b17023SJohn Marino to indicate that threads support is present. Also it has define 37*e4b17023SJohn Marino function 38*e4b17023SJohn Marino int __gthread_active_p () 39*e4b17023SJohn Marino that returns 1 if thread system is active, 0 if not. 40*e4b17023SJohn Marino 41*e4b17023SJohn Marino The threads interface must define the following types: 42*e4b17023SJohn Marino __gthread_key_t 43*e4b17023SJohn Marino __gthread_once_t 44*e4b17023SJohn Marino __gthread_mutex_t 45*e4b17023SJohn Marino __gthread_recursive_mutex_t 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino The threads interface must define the following macros: 48*e4b17023SJohn Marino 49*e4b17023SJohn Marino __GTHREAD_ONCE_INIT 50*e4b17023SJohn Marino to initialize __gthread_once_t 51*e4b17023SJohn Marino __GTHREAD_MUTEX_INIT 52*e4b17023SJohn Marino to initialize __gthread_mutex_t to get a fast 53*e4b17023SJohn Marino non-recursive mutex. 54*e4b17023SJohn Marino __GTHREAD_MUTEX_INIT_FUNCTION 55*e4b17023SJohn Marino some systems can't initialize a mutex without a 56*e4b17023SJohn Marino function call. On such systems, define this to a 57*e4b17023SJohn Marino function which looks like this: 58*e4b17023SJohn Marino void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *) 59*e4b17023SJohn Marino Don't define __GTHREAD_MUTEX_INIT in this case 60*e4b17023SJohn Marino __GTHREAD_RECURSIVE_MUTEX_INIT 61*e4b17023SJohn Marino __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION 62*e4b17023SJohn Marino as above, but for a recursive mutex. 63*e4b17023SJohn Marino 64*e4b17023SJohn Marino The threads interface must define the following static functions: 65*e4b17023SJohn Marino 66*e4b17023SJohn Marino int __gthread_once (__gthread_once_t *once, void (*func) ()) 67*e4b17023SJohn Marino 68*e4b17023SJohn Marino int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *)) 69*e4b17023SJohn Marino int __gthread_key_delete (__gthread_key_t key) 70*e4b17023SJohn Marino 71*e4b17023SJohn Marino void *__gthread_getspecific (__gthread_key_t key) 72*e4b17023SJohn Marino int __gthread_setspecific (__gthread_key_t key, const void *ptr) 73*e4b17023SJohn Marino 74*e4b17023SJohn Marino int __gthread_mutex_destroy (__gthread_mutex_t *mutex); 75*e4b17023SJohn Marino 76*e4b17023SJohn Marino int __gthread_mutex_lock (__gthread_mutex_t *mutex); 77*e4b17023SJohn Marino int __gthread_mutex_trylock (__gthread_mutex_t *mutex); 78*e4b17023SJohn Marino int __gthread_mutex_unlock (__gthread_mutex_t *mutex); 79*e4b17023SJohn Marino 80*e4b17023SJohn Marino int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex); 81*e4b17023SJohn Marino int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex); 82*e4b17023SJohn Marino int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex); 83*e4b17023SJohn Marino 84*e4b17023SJohn Marino The following are supported in POSIX threads only. They are required to 85*e4b17023SJohn Marino fix a deadlock in static initialization inside libsupc++. The header file 86*e4b17023SJohn Marino gthr-posix.h defines a symbol __GTHREAD_HAS_COND to signify that these extra 87*e4b17023SJohn Marino features are supported. 88*e4b17023SJohn Marino 89*e4b17023SJohn Marino Types: 90*e4b17023SJohn Marino __gthread_cond_t 91*e4b17023SJohn Marino 92*e4b17023SJohn Marino Macros: 93*e4b17023SJohn Marino __GTHREAD_COND_INIT 94*e4b17023SJohn Marino __GTHREAD_COND_INIT_FUNCTION 95*e4b17023SJohn Marino 96*e4b17023SJohn Marino Interface: 97*e4b17023SJohn Marino int __gthread_cond_broadcast (__gthread_cond_t *cond); 98*e4b17023SJohn Marino int __gthread_cond_wait (__gthread_cond_t *cond, __gthread_mutex_t *mutex); 99*e4b17023SJohn Marino int __gthread_cond_wait_recursive (__gthread_cond_t *cond, 100*e4b17023SJohn Marino __gthread_recursive_mutex_t *mutex); 101*e4b17023SJohn Marino 102*e4b17023SJohn Marino All functions returning int should return zero on success or the error 103*e4b17023SJohn Marino number. If the operation is not supported, -1 is returned. 104*e4b17023SJohn Marino 105*e4b17023SJohn Marino If the following are also defined, you should 106*e4b17023SJohn Marino #define __GTHREADS_CXX0X 1 107*e4b17023SJohn Marino to enable the c++0x thread library. 108*e4b17023SJohn Marino 109*e4b17023SJohn Marino Types: 110*e4b17023SJohn Marino __gthread_t 111*e4b17023SJohn Marino __gthread_time_t 112*e4b17023SJohn Marino 113*e4b17023SJohn Marino Interface: 114*e4b17023SJohn Marino int __gthread_create (__gthread_t *thread, void *(*func) (void*), 115*e4b17023SJohn Marino void *args); 116*e4b17023SJohn Marino int __gthread_join (__gthread_t thread, void **value_ptr); 117*e4b17023SJohn Marino int __gthread_detach (__gthread_t thread); 118*e4b17023SJohn Marino int __gthread_equal (__gthread_t t1, __gthread_t t2); 119*e4b17023SJohn Marino __gthread_t __gthread_self (void); 120*e4b17023SJohn Marino int __gthread_yield (void); 121*e4b17023SJohn Marino 122*e4b17023SJohn Marino int __gthread_mutex_timedlock (__gthread_mutex_t *m, 123*e4b17023SJohn Marino const __gthread_time_t *abs_timeout); 124*e4b17023SJohn Marino int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *m, 125*e4b17023SJohn Marino const __gthread_time_t *abs_time); 126*e4b17023SJohn Marino 127*e4b17023SJohn Marino int __gthread_cond_signal (__gthread_cond_t *cond); 128*e4b17023SJohn Marino int __gthread_cond_timedwait (__gthread_cond_t *cond, 129*e4b17023SJohn Marino __gthread_mutex_t *mutex, 130*e4b17023SJohn Marino const __gthread_time_t *abs_timeout); 131*e4b17023SJohn Marino int __gthread_cond_timedwait_recursive (__gthread_cond_t *cond, 132*e4b17023SJohn Marino __gthread_recursive_mutex_t *mutex, 133*e4b17023SJohn Marino const __gthread_time_t *abs_time) 134*e4b17023SJohn Marino 135*e4b17023SJohn Marino */ 136*e4b17023SJohn Marino 137*e4b17023SJohn Marino #if SUPPORTS_WEAK 138*e4b17023SJohn Marino /* The pe-coff weak support isn't fully compatible to ELF's weak. 139*e4b17023SJohn Marino For static libraries it might would work, but as we need to deal 140*e4b17023SJohn Marino with shared versions too, we disable it for mingw-targets. */ 141*e4b17023SJohn Marino #ifdef __MINGW32__ 142*e4b17023SJohn Marino #undef GTHREAD_USE_WEAK 143*e4b17023SJohn Marino #define GTHREAD_USE_WEAK 0 144*e4b17023SJohn Marino #endif 145*e4b17023SJohn Marino 146*e4b17023SJohn Marino #ifndef GTHREAD_USE_WEAK 147*e4b17023SJohn Marino #define GTHREAD_USE_WEAK 1 148*e4b17023SJohn Marino #endif 149*e4b17023SJohn Marino #endif 150*e4b17023SJohn Marino #include "gthr-default.h" 151*e4b17023SJohn Marino 152*e4b17023SJohn Marino #ifndef HIDE_EXPORTS 153*e4b17023SJohn Marino #pragma GCC visibility pop 154*e4b17023SJohn Marino #endif 155*e4b17023SJohn Marino 156*e4b17023SJohn Marino #endif /* ! GCC_GTHR_H */ 157