]>
Commit | Line | Data |
---|---|---|
fbe5a4a6 | 1 | /* RTEMS threads compatibility routines for libgcc2 and libobjc. |
bc98ef7f JS |
2 | by: Rosimildo da Silva( rdasilva@connecttel.com ) */ |
3 | /* Compile this one with gcc. */ | |
1504e3e1 | 4 | /* Copyright (C) 1997-2012 Free Software Foundation, Inc. |
bc98ef7f | 5 | |
1322177d | 6 | This file is part of GCC. |
bc98ef7f | 7 | |
1322177d LB |
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 | |
748086b7 | 10 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 11 | version. |
bc98ef7f | 12 | |
1322177d LB |
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. | |
bc98ef7f | 17 | |
748086b7 JJ |
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/>. */ | |
bc98ef7f | 26 | |
88657302 RH |
27 | #ifndef GCC_GTHR_RTEMS_H |
28 | #define GCC_GTHR_RTEMS_H | |
bc98ef7f | 29 | |
f22b4bc4 JS |
30 | #ifdef __cplusplus |
31 | extern "C" { | |
32 | #endif | |
bc98ef7f JS |
33 | |
34 | #define __GTHREADS 1 | |
35 | ||
36 | #define __GTHREAD_ONCE_INIT 0 | |
37 | #define __GTHREAD_MUTEX_INIT_FUNCTION rtems_gxx_mutex_init | |
5d58d2f8 | 38 | #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION rtems_gxx_recursive_mutex_init |
bc98ef7f | 39 | |
fbe5a4a6 | 40 | /* Avoid dependency on rtems specific headers. */ |
bc98ef7f JS |
41 | typedef void *__gthread_key_t; |
42 | typedef int __gthread_once_t; | |
43 | typedef void *__gthread_mutex_t; | |
5d58d2f8 | 44 | typedef void *__gthread_recursive_mutex_t; |
bc98ef7f JS |
45 | |
46 | /* | |
589005ff | 47 | * External functions provided by RTEMS. They are very similar to their POSIX |
bc98ef7f JS |
48 | * counterparts. A "Wrapper API" is being use to avoid dependency on any RTEMS |
49 | * header files. | |
50 | */ | |
51 | ||
52 | /* generic per task variables */ | |
09e361bb JJ |
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); | |
bc98ef7f JS |
58 | |
59 | /* mutex support */ | |
09e361bb JJ |
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); | |
bc98ef7f | 65 | |
5d58d2f8 | 66 | /* recursive mutex support */ |
09e361bb JJ |
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); | |
bc98ef7f | 71 | |
e08f13ee JS |
72 | /* RTEMS threading is always active */ |
73 | static inline int | |
74 | __gthread_active_p (void) | |
75 | { | |
76 | return 1; | |
77 | } | |
78 | ||
bc98ef7f JS |
79 | /* Wrapper calls */ |
80 | static inline int | |
09e361bb | 81 | __gthread_once (__gthread_once_t *__once, void (*__func) (void)) |
bc98ef7f | 82 | { |
09e361bb | 83 | return rtems_gxx_once( __once, __func ); |
bc98ef7f JS |
84 | } |
85 | ||
86 | static inline int | |
09e361bb | 87 | __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *)) |
bc98ef7f | 88 | { |
09e361bb | 89 | return rtems_gxx_key_create( __key, __dtor ); |
bc98ef7f JS |
90 | } |
91 | ||
bc98ef7f | 92 | static inline int |
09e361bb | 93 | __gthread_key_delete (__gthread_key_t __key) |
bc98ef7f | 94 | { |
09e361bb | 95 | return rtems_gxx_key_delete (__key); |
bc98ef7f JS |
96 | } |
97 | ||
98 | static inline void * | |
09e361bb | 99 | __gthread_getspecific (__gthread_key_t __key) |
bc98ef7f | 100 | { |
09e361bb | 101 | return rtems_gxx_getspecific (__key); |
bc98ef7f JS |
102 | } |
103 | ||
104 | static inline int | |
09e361bb | 105 | __gthread_setspecific (__gthread_key_t __key, const void *__ptr) |
bc98ef7f | 106 | { |
09e361bb | 107 | return rtems_gxx_setspecific (__key, __ptr); |
bc98ef7f JS |
108 | } |
109 | ||
4dabf736 | 110 | static inline int |
09e361bb | 111 | __gthread_mutex_destroy (__gthread_mutex_t *__mutex) |
4dabf736 | 112 | { |
09e361bb | 113 | return rtems_gxx_mutex_destroy (__mutex); |
4dabf736 JB |
114 | } |
115 | ||
bc98ef7f | 116 | static inline int |
09e361bb | 117 | __gthread_mutex_lock (__gthread_mutex_t *__mutex) |
bc98ef7f | 118 | { |
09e361bb | 119 | return rtems_gxx_mutex_lock (__mutex); |
bc98ef7f JS |
120 | } |
121 | ||
122 | static inline int | |
09e361bb | 123 | __gthread_mutex_trylock (__gthread_mutex_t *__mutex) |
bc98ef7f | 124 | { |
09e361bb | 125 | return rtems_gxx_mutex_trylock (__mutex); |
bc98ef7f JS |
126 | } |
127 | ||
128 | static inline int | |
09e361bb | 129 | __gthread_mutex_unlock (__gthread_mutex_t *__mutex) |
bc98ef7f | 130 | { |
09e361bb | 131 | return rtems_gxx_mutex_unlock( __mutex ); |
bc98ef7f JS |
132 | } |
133 | ||
5d58d2f8 | 134 | static inline int |
09e361bb | 135 | __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex) |
5d58d2f8 | 136 | { |
09e361bb | 137 | return rtems_gxx_recursive_mutex_lock (__mutex); |
5d58d2f8 RC |
138 | } |
139 | ||
140 | static inline int | |
09e361bb | 141 | __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex) |
5d58d2f8 | 142 | { |
09e361bb | 143 | return rtems_gxx_recursive_mutex_trylock (__mutex); |
5d58d2f8 RC |
144 | } |
145 | ||
146 | static inline int | |
09e361bb | 147 | __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) |
5d58d2f8 | 148 | { |
09e361bb | 149 | return rtems_gxx_recursive_mutex_unlock( __mutex ); |
5d58d2f8 RC |
150 | } |
151 | ||
1504e3e1 JW |
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 | ||
f22b4bc4 JS |
160 | #ifdef __cplusplus |
161 | } | |
162 | #endif | |
163 | ||
88657302 | 164 | #endif /* ! GCC_GTHR_RTEMS_H */ |