]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/gthr-rtems.h
re PR other/53889 (Gthreads doesn't support destroying recursive mutexes)
[thirdparty/gcc.git] / libgcc / config / gthr-rtems.h
CommitLineData
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 6This file is part of GCC.
bc98ef7f 7
1322177d
LB
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
748086b7 10Software Foundation; either version 3, or (at your option) any later
1322177d 11version.
bc98ef7f 12
1322177d
LB
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.
bc98ef7f 17
748086b7
JJ
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/>. */
bc98ef7f 26
88657302
RH
27#ifndef GCC_GTHR_RTEMS_H
28#define GCC_GTHR_RTEMS_H
bc98ef7f 29
f22b4bc4
JS
30#ifdef __cplusplus
31extern "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
41typedef void *__gthread_key_t;
42typedef int __gthread_once_t;
43typedef void *__gthread_mutex_t;
5d58d2f8 44typedef 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
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);
bc98ef7f
JS
58
59/* mutex support */
09e361bb
JJ
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);
bc98ef7f 65
5d58d2f8 66/* recursive mutex support */
09e361bb
JJ
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);
bc98ef7f 71
e08f13ee
JS
72/* RTEMS threading is always active */
73static inline int
74__gthread_active_p (void)
75{
76 return 1;
77}
78
bc98ef7f
JS
79/* Wrapper calls */
80static 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
86static 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 92static 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
98static inline void *
09e361bb 99__gthread_getspecific (__gthread_key_t __key)
bc98ef7f 100{
09e361bb 101 return rtems_gxx_getspecific (__key);
bc98ef7f
JS
102}
103
104static 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 110static 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 116static 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
122static 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
128static 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 134static 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
140static 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
146static 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
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
f22b4bc4
JS
160#ifdef __cplusplus
161}
162#endif
163
88657302 164#endif /* ! GCC_GTHR_RTEMS_H */