2010-07-27 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc/alias-decl.git] / gcc / gthr-vxworks.h
blobd4da14ef49295674f6dfc9fd87436223764f5f49
1 /* Threads compatibility routines for libgcc2 and libobjc for VxWorks. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1997, 1999, 2000, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Mike Stump <mrs@wrs.com>.
6 This file is part of GCC.
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 3, or (at your option) any later
11 version.
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.
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.
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/>. */
27 #ifndef GCC_GTHR_VXWORKS_H
28 #define GCC_GTHR_VXWORKS_H
30 #ifdef _LIBOBJC
32 /* libobjc requires the optional pthreads component. */
33 #include "gthr-posix.h"
35 #else
36 #ifdef __cplusplus
37 #define UNUSED(x)
38 #else
39 #define UNUSED(x) x __attribute__((unused))
40 #endif
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 #define __GTHREADS 1
47 #define __gthread_active_p() 1
49 /* Mutexes are easy, except that they need to be initialized at runtime. */
51 #include <semLib.h>
53 typedef SEM_ID __gthread_mutex_t;
54 /* All VxWorks mutexes are recursive. */
55 typedef SEM_ID __gthread_recursive_mutex_t;
56 #define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
57 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
59 static inline void
60 __gthread_mutex_init_function (__gthread_mutex_t *mutex)
62 *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
65 static inline int
66 __gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
68 return 0;
71 static inline int
72 __gthread_mutex_lock (__gthread_mutex_t *mutex)
74 return semTake (*mutex, WAIT_FOREVER);
77 static inline int
78 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
80 return semTake (*mutex, NO_WAIT);
83 static inline int
84 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
86 return semGive (*mutex);
89 static inline void
90 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
92 __gthread_mutex_init_function (mutex);
95 static inline int
96 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
98 return __gthread_mutex_lock (mutex);
101 static inline int
102 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
104 return __gthread_mutex_trylock (mutex);
107 static inline int
108 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
110 return __gthread_mutex_unlock (mutex);
113 /* pthread_once is complicated enough that it's implemented
114 out-of-line. See config/vxlib.c. */
116 typedef struct
118 #if !defined(__RTP__)
119 #if defined(__PPC__)
120 __attribute ((aligned (__alignof (unsigned))))
121 #endif
122 volatile unsigned char busy;
123 #endif
124 volatile unsigned char done;
125 #if !defined(__RTP__) && defined(__PPC__)
126 /* PPC's test-and-set implementation requires a 4 byte aligned
127 object, of which it only sets the first byte. We use padding
128 here, in order to maintain some amount of backwards
129 compatibility. Without this padding, gthread_once objects worked
130 by accident because they happen to be static objects and the ppc
131 port automatically increased their alignment to 4 bytes. */
132 unsigned char pad1;
133 unsigned char pad2;
134 #endif
136 __gthread_once_t;
138 #if defined (__RTP__)
139 # define __GTHREAD_ONCE_INIT { 0 }
140 #elif defined (__PPC__)
141 # define __GTHREAD_ONCE_INIT { 0, 0, 0, 0 }
142 #else
143 # define __GTHREAD_ONCE_INIT { 0, 0 }
144 #endif
146 extern int __gthread_once (__gthread_once_t *__once, void (*__func)(void));
148 /* Thread-specific data requires a great deal of effort, since VxWorks
149 is not really set up for it. See config/vxlib.c for the gory
150 details. All the TSD routines are sufficiently complex that they
151 need to be implemented out of line. */
153 typedef unsigned int __gthread_key_t;
155 extern int __gthread_key_create (__gthread_key_t *__keyp, void (*__dtor)(void *));
156 extern int __gthread_key_delete (__gthread_key_t __key);
158 extern void *__gthread_getspecific (__gthread_key_t __key);
159 extern int __gthread_setspecific (__gthread_key_t __key, void *__ptr);
161 #undef UNUSED
163 #ifdef __cplusplus
165 #endif
167 #endif /* not _LIBOBJC */
169 #endif /* gthr-vxworks.h */