1*e4b17023SJohn Marino /* RTEMS threads compatibility routines for libgcc2 and libobjc. 2*e4b17023SJohn Marino by: Rosimildo da Silva( rdasilva@connecttel.com ) */ 3*e4b17023SJohn Marino /* Compile this one with gcc. */ 4*e4b17023SJohn Marino /* Copyright (C) 1997, 1999, 2000, 2002, 2003, 2005, 2008, 2009 5*e4b17023SJohn Marino Free Software Foundation, Inc. 6*e4b17023SJohn Marino 7*e4b17023SJohn Marino This file is part of GCC. 8*e4b17023SJohn Marino 9*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 10*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 11*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 12*e4b17023SJohn Marino version. 13*e4b17023SJohn Marino 14*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 15*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 16*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17*e4b17023SJohn Marino for more details. 18*e4b17023SJohn Marino 19*e4b17023SJohn Marino Under Section 7 of GPL version 3, you are granted additional 20*e4b17023SJohn Marino permissions described in the GCC Runtime Library Exception, version 21*e4b17023SJohn Marino 3.1, as published by the Free Software Foundation. 22*e4b17023SJohn Marino 23*e4b17023SJohn Marino You should have received a copy of the GNU General Public License and 24*e4b17023SJohn Marino a copy of the GCC Runtime Library Exception along with this program; 25*e4b17023SJohn Marino see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 26*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 27*e4b17023SJohn Marino 28*e4b17023SJohn Marino #ifndef GCC_GTHR_RTEMS_H 29*e4b17023SJohn Marino #define GCC_GTHR_RTEMS_H 30*e4b17023SJohn Marino 31*e4b17023SJohn Marino #ifdef __cplusplus 32*e4b17023SJohn Marino extern "C" { 33*e4b17023SJohn Marino #endif 34*e4b17023SJohn Marino 35*e4b17023SJohn Marino #define __GTHREADS 1 36*e4b17023SJohn Marino 37*e4b17023SJohn Marino #define __GTHREAD_ONCE_INIT 0 38*e4b17023SJohn Marino #define __GTHREAD_MUTEX_INIT_FUNCTION rtems_gxx_mutex_init 39*e4b17023SJohn Marino #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION rtems_gxx_recursive_mutex_init 40*e4b17023SJohn Marino 41*e4b17023SJohn Marino /* Avoid dependency on rtems specific headers. */ 42*e4b17023SJohn Marino typedef void *__gthread_key_t; 43*e4b17023SJohn Marino typedef int __gthread_once_t; 44*e4b17023SJohn Marino typedef void *__gthread_mutex_t; 45*e4b17023SJohn Marino typedef void *__gthread_recursive_mutex_t; 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino /* 48*e4b17023SJohn Marino * External functions provided by RTEMS. They are very similar to their POSIX 49*e4b17023SJohn Marino * counterparts. A "Wrapper API" is being use to avoid dependency on any RTEMS 50*e4b17023SJohn Marino * header files. 51*e4b17023SJohn Marino */ 52*e4b17023SJohn Marino 53*e4b17023SJohn Marino /* generic per task variables */ 54*e4b17023SJohn Marino extern int rtems_gxx_once (__gthread_once_t *__once, void (*__func) (void)); 55*e4b17023SJohn Marino extern int rtems_gxx_key_create (__gthread_key_t *__key, void (*__dtor) (void *)); 56*e4b17023SJohn Marino extern int rtems_gxx_key_delete (__gthread_key_t __key); 57*e4b17023SJohn Marino extern void *rtems_gxx_getspecific (__gthread_key_t __key); 58*e4b17023SJohn Marino extern int rtems_gxx_setspecific (__gthread_key_t __key, const void *__ptr); 59*e4b17023SJohn Marino 60*e4b17023SJohn Marino /* mutex support */ 61*e4b17023SJohn Marino extern void rtems_gxx_mutex_init (__gthread_mutex_t *__mutex); 62*e4b17023SJohn Marino extern int rtems_gxx_mutex_destroy (__gthread_mutex_t *__mutex); 63*e4b17023SJohn Marino extern int rtems_gxx_mutex_lock (__gthread_mutex_t *__mutex); 64*e4b17023SJohn Marino extern int rtems_gxx_mutex_trylock (__gthread_mutex_t *__mutex); 65*e4b17023SJohn Marino extern int rtems_gxx_mutex_unlock (__gthread_mutex_t *__mutex); 66*e4b17023SJohn Marino 67*e4b17023SJohn Marino /* recursive mutex support */ 68*e4b17023SJohn Marino extern void rtems_gxx_recursive_mutex_init (__gthread_recursive_mutex_t *__mutex); 69*e4b17023SJohn Marino extern int rtems_gxx_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex); 70*e4b17023SJohn Marino extern int rtems_gxx_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex); 71*e4b17023SJohn Marino extern int rtems_gxx_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex); 72*e4b17023SJohn Marino 73*e4b17023SJohn Marino /* RTEMS threading is always active */ 74*e4b17023SJohn Marino static inline int 75*e4b17023SJohn Marino __gthread_active_p (void) 76*e4b17023SJohn Marino { 77*e4b17023SJohn Marino return 1; 78*e4b17023SJohn Marino } 79*e4b17023SJohn Marino 80*e4b17023SJohn Marino /* Wrapper calls */ 81*e4b17023SJohn Marino static inline int 82*e4b17023SJohn Marino __gthread_once (__gthread_once_t *__once, void (*__func) (void)) 83*e4b17023SJohn Marino { 84*e4b17023SJohn Marino return rtems_gxx_once( __once, __func ); 85*e4b17023SJohn Marino } 86*e4b17023SJohn Marino 87*e4b17023SJohn Marino static inline int 88*e4b17023SJohn Marino __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *)) 89*e4b17023SJohn Marino { 90*e4b17023SJohn Marino return rtems_gxx_key_create( __key, __dtor ); 91*e4b17023SJohn Marino } 92*e4b17023SJohn Marino 93*e4b17023SJohn Marino static inline int 94*e4b17023SJohn Marino __gthread_key_delete (__gthread_key_t __key) 95*e4b17023SJohn Marino { 96*e4b17023SJohn Marino return rtems_gxx_key_delete (__key); 97*e4b17023SJohn Marino } 98*e4b17023SJohn Marino 99*e4b17023SJohn Marino static inline void * 100*e4b17023SJohn Marino __gthread_getspecific (__gthread_key_t __key) 101*e4b17023SJohn Marino { 102*e4b17023SJohn Marino return rtems_gxx_getspecific (__key); 103*e4b17023SJohn Marino } 104*e4b17023SJohn Marino 105*e4b17023SJohn Marino static inline int 106*e4b17023SJohn Marino __gthread_setspecific (__gthread_key_t __key, const void *__ptr) 107*e4b17023SJohn Marino { 108*e4b17023SJohn Marino return rtems_gxx_setspecific (__key, __ptr); 109*e4b17023SJohn Marino } 110*e4b17023SJohn Marino 111*e4b17023SJohn Marino static inline int 112*e4b17023SJohn Marino __gthread_mutex_destroy (__gthread_mutex_t *__mutex) 113*e4b17023SJohn Marino { 114*e4b17023SJohn Marino return rtems_gxx_mutex_destroy (__mutex); 115*e4b17023SJohn Marino } 116*e4b17023SJohn Marino 117*e4b17023SJohn Marino static inline int 118*e4b17023SJohn Marino __gthread_mutex_lock (__gthread_mutex_t *__mutex) 119*e4b17023SJohn Marino { 120*e4b17023SJohn Marino return rtems_gxx_mutex_lock (__mutex); 121*e4b17023SJohn Marino } 122*e4b17023SJohn Marino 123*e4b17023SJohn Marino static inline int 124*e4b17023SJohn Marino __gthread_mutex_trylock (__gthread_mutex_t *__mutex) 125*e4b17023SJohn Marino { 126*e4b17023SJohn Marino return rtems_gxx_mutex_trylock (__mutex); 127*e4b17023SJohn Marino } 128*e4b17023SJohn Marino 129*e4b17023SJohn Marino static inline int 130*e4b17023SJohn Marino __gthread_mutex_unlock (__gthread_mutex_t *__mutex) 131*e4b17023SJohn Marino { 132*e4b17023SJohn Marino return rtems_gxx_mutex_unlock( __mutex ); 133*e4b17023SJohn Marino } 134*e4b17023SJohn Marino 135*e4b17023SJohn Marino static inline int 136*e4b17023SJohn Marino __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex) 137*e4b17023SJohn Marino { 138*e4b17023SJohn Marino return rtems_gxx_recursive_mutex_lock (__mutex); 139*e4b17023SJohn Marino } 140*e4b17023SJohn Marino 141*e4b17023SJohn Marino static inline int 142*e4b17023SJohn Marino __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex) 143*e4b17023SJohn Marino { 144*e4b17023SJohn Marino return rtems_gxx_recursive_mutex_trylock (__mutex); 145*e4b17023SJohn Marino } 146*e4b17023SJohn Marino 147*e4b17023SJohn Marino static inline int 148*e4b17023SJohn Marino __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) 149*e4b17023SJohn Marino { 150*e4b17023SJohn Marino return rtems_gxx_recursive_mutex_unlock( __mutex ); 151*e4b17023SJohn Marino } 152*e4b17023SJohn Marino 153*e4b17023SJohn Marino #ifdef __cplusplus 154*e4b17023SJohn Marino } 155*e4b17023SJohn Marino #endif 156*e4b17023SJohn Marino 157*e4b17023SJohn Marino #endif /* ! GCC_GTHR_RTEMS_H */ 158