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-2015 Free Software Foundation, Inc. 5 6This file is part of GCC. 7 8GCC is free software; you can redistribute it and/or modify it under 9the terms of the GNU General Public License as published by the Free 10Software Foundation; either version 3, or (at your option) any later 11version. 12 13GCC is distributed in the hope that it will be useful, but WITHOUT ANY 14WARRANTY; without even the implied warranty of MERCHANTABILITY or 15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16for more details. 17 18Under Section 7 of GPL version 3, you are granted additional 19permissions described in the GCC Runtime Library Exception, version 203.1, as published by the Free Software Foundation. 21 22You should have received a copy of the GNU General Public License and 23a copy of the GCC Runtime Library Exception along with this program; 24see 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 31extern "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. */ 41typedef void *__gthread_key_t; 42typedef int __gthread_once_t; 43typedef void *__gthread_mutex_t; 44typedef 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 */ 53extern int rtems_gxx_once (__gthread_once_t *__once, void (*__func) (void)); 54extern int rtems_gxx_key_create (__gthread_key_t *__key, void (*__dtor) (void *)); 55extern int rtems_gxx_key_delete (__gthread_key_t __key); 56extern void *rtems_gxx_getspecific (__gthread_key_t __key); 57extern int rtems_gxx_setspecific (__gthread_key_t __key, const void *__ptr); 58 59/* mutex support */ 60extern void rtems_gxx_mutex_init (__gthread_mutex_t *__mutex); 61extern int rtems_gxx_mutex_destroy (__gthread_mutex_t *__mutex); 62extern int rtems_gxx_mutex_lock (__gthread_mutex_t *__mutex); 63extern int rtems_gxx_mutex_trylock (__gthread_mutex_t *__mutex); 64extern int rtems_gxx_mutex_unlock (__gthread_mutex_t *__mutex); 65 66/* recursive mutex support */ 67extern void rtems_gxx_recursive_mutex_init (__gthread_recursive_mutex_t *__mutex); 68extern int rtems_gxx_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex); 69extern int rtems_gxx_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex); 70extern int rtems_gxx_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex); 71 72/* RTEMS threading is always active */ 73static inline int 74__gthread_active_p (void) 75{ 76 return 1; 77} 78 79/* Wrapper calls */ 80static inline int 81__gthread_once (__gthread_once_t *__once, void (*__func) (void)) 82{ 83 return rtems_gxx_once( __once, __func ); 84} 85 86static inline int 87__gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *)) 88{ 89 return rtems_gxx_key_create( __key, __dtor ); 90} 91 92static inline int 93__gthread_key_delete (__gthread_key_t __key) 94{ 95 return rtems_gxx_key_delete (__key); 96} 97 98static inline void * 99__gthread_getspecific (__gthread_key_t __key) 100{ 101 return rtems_gxx_getspecific (__key); 102} 103 104static inline int 105__gthread_setspecific (__gthread_key_t __key, const void *__ptr) 106{ 107 return rtems_gxx_setspecific (__key, __ptr); 108} 109 110static inline int 111__gthread_mutex_destroy (__gthread_mutex_t *__mutex) 112{ 113 return rtems_gxx_mutex_destroy (__mutex); 114} 115 116static inline int 117__gthread_mutex_lock (__gthread_mutex_t *__mutex) 118{ 119 return rtems_gxx_mutex_lock (__mutex); 120} 121 122static inline int 123__gthread_mutex_trylock (__gthread_mutex_t *__mutex) 124{ 125 return rtems_gxx_mutex_trylock (__mutex); 126} 127 128static inline int 129__gthread_mutex_unlock (__gthread_mutex_t *__mutex) 130{ 131 return rtems_gxx_mutex_unlock( __mutex ); 132} 133 134static inline int 135__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex) 136{ 137 return rtems_gxx_recursive_mutex_lock (__mutex); 138} 139 140static inline int 141__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex) 142{ 143 return rtems_gxx_recursive_mutex_trylock (__mutex); 144} 145 146static inline int 147__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) 148{ 149 return rtems_gxx_recursive_mutex_unlock( __mutex ); 150} 151 152static 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