OSDN Git Service

2008-02-21 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / gthr-rtems.h
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, 1999, 2000, 2002, 2003, 2005 
5    Free Software Foundation, Inc.
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING.  If not, write to the Free
21 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 02110-1301, USA.  */
23
24 /* As a special exception, if you link this library with other files,
25    some of which are compiled with GCC, to produce an executable,
26    this library does not by itself cause the resulting executable
27    to be covered by the GNU General Public License.
28    This exception does not however invalidate any other reasons why
29    the executable file might be covered by the GNU General Public License.  */
30
31 #ifndef GCC_GTHR_RTEMS_H
32 #define GCC_GTHR_RTEMS_H
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #define __GTHREADS 1
39
40 #define __GTHREAD_ONCE_INIT  0
41 #define __GTHREAD_MUTEX_INIT_FUNCTION  rtems_gxx_mutex_init
42 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION  rtems_gxx_recursive_mutex_init
43
44 /* Avoid dependency on rtems specific headers.  */
45 typedef void *__gthread_key_t;
46 typedef int   __gthread_once_t;
47 typedef void *__gthread_mutex_t;
48 typedef void *__gthread_recursive_mutex_t;
49
50 /*
51  * External functions provided by RTEMS. They are very similar to their POSIX
52  * counterparts. A "Wrapper API" is being use to avoid dependency on any RTEMS
53  * header files.
54  */
55
56 /* generic per task variables */
57 extern int rtems_gxx_once (__gthread_once_t *once, void (*func) (void));
58 extern int rtems_gxx_key_create (__gthread_key_t *key, void (*dtor) (void *));
59 extern int rtems_gxx_key_delete (__gthread_key_t key);
60 extern void *rtems_gxx_getspecific (__gthread_key_t key);
61 extern int rtems_gxx_setspecific (__gthread_key_t key, const void *ptr);
62
63 /* mutex support */
64 extern void rtems_gxx_mutex_init (__gthread_mutex_t *mutex);
65 extern int rtems_gxx_mutex_lock (__gthread_mutex_t *mutex);
66 extern int rtems_gxx_mutex_trylock (__gthread_mutex_t *mutex);
67 extern int rtems_gxx_mutex_unlock (__gthread_mutex_t *mutex);
68
69 /* recursive mutex support */
70 extern void rtems_gxx_recursive_mutex_init (__gthread_recursive_mutex_t *mutex);
71 extern int rtems_gxx_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex);
72 extern int rtems_gxx_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex);
73 extern int rtems_gxx_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex);
74
75 /* RTEMS threading is always active */
76 static inline int
77 __gthread_active_p (void)
78 {
79   return 1;
80 }
81
82 /* Wrapper calls */
83 static inline int
84 __gthread_once (__gthread_once_t *once, void (*func) (void))
85 {
86    return rtems_gxx_once( once, func );
87 }
88
89 static inline int
90 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
91 {
92   return rtems_gxx_key_create( key, dtor );
93 }
94
95 static inline int
96 __gthread_key_delete (__gthread_key_t key)
97 {
98   return rtems_gxx_key_delete (key);
99 }
100
101 static inline void *
102 __gthread_getspecific (__gthread_key_t key)
103 {
104   return rtems_gxx_getspecific (key);
105 }
106
107 static inline int
108 __gthread_setspecific (__gthread_key_t key, const void *ptr)
109 {
110   return rtems_gxx_setspecific (key, ptr);
111 }
112
113 static inline int
114 __gthread_mutex_lock (__gthread_mutex_t *mutex)
115 {
116     return rtems_gxx_mutex_lock (mutex);
117 }
118
119 static inline int
120 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
121 {
122     return rtems_gxx_mutex_trylock (mutex);
123 }
124
125 static inline int
126 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
127 {
128     return rtems_gxx_mutex_unlock( mutex );
129 }
130
131 static inline int
132 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
133 {
134     return rtems_gxx_recursive_mutex_lock (mutex);
135 }
136
137 static inline int
138 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
139 {
140     return rtems_gxx_recursive_mutex_trylock (mutex);
141 }
142
143 static inline int
144 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
145 {
146     return rtems_gxx_recursive_mutex_unlock( mutex );
147 }
148
149 #ifdef __cplusplus
150 }
151 #endif
152
153 #endif /* ! GCC_GTHR_RTEMS_H */