OSDN Git Service

2003-01-29 Joel Sherrill <joel@OARcorp.com>
[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 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 2, 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 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA.  */
22
23 /* As a special exception, if you link this library with other files,
24    some of which are compiled with GCC, to produce an executable,
25    this library does not by itself cause the resulting executable
26    to be covered by the GNU General Public License.
27    This exception does not however invalidate any other reasons why
28    the executable file might be covered by the GNU General Public License.  */
29
30 #ifndef GCC_GTHR_RTEMS_H
31 #define GCC_GTHR_RTEMS_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #define __GTHREADS 1
38
39 #define __GTHREAD_ONCE_INIT  0
40 #define __GTHREAD_MUTEX_INIT_FUNCTION  rtems_gxx_mutex_init
41
42 /* Avoid dependency on rtems specific headers.  */
43 typedef void *__gthread_key_t;
44 typedef int   __gthread_once_t;
45 typedef void *__gthread_mutex_t;
46
47 /*
48  * External functions provided by RTEMS. They are very similar to their POSIX
49  * counterparts. A "Wrapper API" is being use to avoid dependency on any RTEMS
50  * header files.
51  */
52
53 /* generic per task variables */
54 extern int rtems_gxx_once (__gthread_once_t *once, void (*func) (void));
55 extern int rtems_gxx_key_create (__gthread_key_t *key, void (*dtor) (void *));
56 extern int rtems_gxx_key_delete (__gthread_key_t key);
57 extern void *rtems_gxx_getspecific (__gthread_key_t key);
58 extern int rtems_gxx_setspecific (__gthread_key_t key, const void *ptr);
59
60 /* mutex support */
61 extern void rtems_gxx_mutex_init (__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
67 /* RTEMS threading is always active */
68 static inline int
69 __gthread_active_p (void)
70 {
71   return 1;
72 }
73
74 /* Wrapper calls */
75 static inline int
76 __gthread_once (__gthread_once_t *once, void (*func) (void))
77 {
78    return rtems_gxx_once( once, func );
79 }
80
81 static inline int
82 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
83 {
84   return rtems_gxx_key_create( key, dtor );
85 }
86
87 static inline int
88 __gthread_key_delete (__gthread_key_t key)
89 {
90   return rtems_gxx_key_delete (key);
91 }
92
93 static inline void *
94 __gthread_getspecific (__gthread_key_t key)
95 {
96   return rtems_gxx_getspecific (key);
97 }
98
99 static inline int
100 __gthread_setspecific (__gthread_key_t key, const void *ptr)
101 {
102   return rtems_gxx_setspecific (key, ptr);
103 }
104
105 static inline int
106 __gthread_mutex_lock (__gthread_mutex_t *mutex)
107 {
108     return rtems_gxx_mutex_lock (mutex);
109 }
110
111 static inline int
112 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
113 {
114     return rtems_gxx_mutex_trylock (mutex);
115 }
116
117 static inline int
118 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
119 {
120     return rtems_gxx_mutex_unlock( mutex );
121 }
122
123 #ifdef __cplusplus
124 }
125 #endif
126
127 #endif /* ! GCC_GTHR_RTEMS_H */