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