xref: /dflybsd-src/contrib/gcc-4.7/libgcc/config/gthr-vxworks.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino /* Threads compatibility routines for libgcc2 and libobjc for VxWorks.  */
2*e4b17023SJohn Marino /* Compile this one with gcc.  */
3*e4b17023SJohn Marino /* Copyright (C) 1997, 1999, 2000, 2008, 2009, 2011
4*e4b17023SJohn Marino    Free Software Foundation, Inc.
5*e4b17023SJohn Marino    Contributed by Mike Stump <mrs@wrs.com>.
6*e4b17023SJohn Marino 
7*e4b17023SJohn Marino This file is part of GCC.
8*e4b17023SJohn Marino 
9*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
10*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
11*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
12*e4b17023SJohn Marino version.
13*e4b17023SJohn Marino 
14*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
16*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17*e4b17023SJohn Marino for more details.
18*e4b17023SJohn Marino 
19*e4b17023SJohn Marino Under Section 7 of GPL version 3, you are granted additional
20*e4b17023SJohn Marino permissions described in the GCC Runtime Library Exception, version
21*e4b17023SJohn Marino 3.1, as published by the Free Software Foundation.
22*e4b17023SJohn Marino 
23*e4b17023SJohn Marino You should have received a copy of the GNU General Public License and
24*e4b17023SJohn Marino a copy of the GCC Runtime Library Exception along with this program;
25*e4b17023SJohn Marino see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
26*e4b17023SJohn Marino <http://www.gnu.org/licenses/>.  */
27*e4b17023SJohn Marino 
28*e4b17023SJohn Marino #ifndef GCC_GTHR_VXWORKS_H
29*e4b17023SJohn Marino #define GCC_GTHR_VXWORKS_H
30*e4b17023SJohn Marino 
31*e4b17023SJohn Marino #ifdef _LIBOBJC
32*e4b17023SJohn Marino 
33*e4b17023SJohn Marino /* libobjc requires the optional pthreads component.  */
34*e4b17023SJohn Marino #include "gthr-posix.h"
35*e4b17023SJohn Marino 
36*e4b17023SJohn Marino #else
37*e4b17023SJohn Marino #ifdef __cplusplus
38*e4b17023SJohn Marino #define UNUSED(x)
39*e4b17023SJohn Marino #else
40*e4b17023SJohn Marino #define UNUSED(x) x __attribute__((unused))
41*e4b17023SJohn Marino #endif
42*e4b17023SJohn Marino 
43*e4b17023SJohn Marino #ifdef __cplusplus
44*e4b17023SJohn Marino extern "C" {
45*e4b17023SJohn Marino #endif
46*e4b17023SJohn Marino 
47*e4b17023SJohn Marino #define __GTHREADS 1
48*e4b17023SJohn Marino #define __gthread_active_p() 1
49*e4b17023SJohn Marino 
50*e4b17023SJohn Marino /* Mutexes are easy, except that they need to be initialized at runtime.  */
51*e4b17023SJohn Marino 
52*e4b17023SJohn Marino #include <semLib.h>
53*e4b17023SJohn Marino 
54*e4b17023SJohn Marino typedef SEM_ID __gthread_mutex_t;
55*e4b17023SJohn Marino /* All VxWorks mutexes are recursive.  */
56*e4b17023SJohn Marino typedef SEM_ID __gthread_recursive_mutex_t;
57*e4b17023SJohn Marino #define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
58*e4b17023SJohn Marino #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
59*e4b17023SJohn Marino 
60*e4b17023SJohn Marino static inline void
__gthread_mutex_init_function(__gthread_mutex_t * mutex)61*e4b17023SJohn Marino __gthread_mutex_init_function (__gthread_mutex_t *mutex)
62*e4b17023SJohn Marino {
63*e4b17023SJohn Marino   *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
64*e4b17023SJohn Marino }
65*e4b17023SJohn Marino 
66*e4b17023SJohn Marino static inline int
__gthread_mutex_destroy(__gthread_mutex_t * UNUSED (mutex))67*e4b17023SJohn Marino __gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
68*e4b17023SJohn Marino {
69*e4b17023SJohn Marino   return 0;
70*e4b17023SJohn Marino }
71*e4b17023SJohn Marino 
72*e4b17023SJohn Marino static inline int
__gthread_mutex_lock(__gthread_mutex_t * mutex)73*e4b17023SJohn Marino __gthread_mutex_lock (__gthread_mutex_t *mutex)
74*e4b17023SJohn Marino {
75*e4b17023SJohn Marino   return semTake (*mutex, WAIT_FOREVER);
76*e4b17023SJohn Marino }
77*e4b17023SJohn Marino 
78*e4b17023SJohn Marino static inline int
__gthread_mutex_trylock(__gthread_mutex_t * mutex)79*e4b17023SJohn Marino __gthread_mutex_trylock (__gthread_mutex_t *mutex)
80*e4b17023SJohn Marino {
81*e4b17023SJohn Marino   return semTake (*mutex, NO_WAIT);
82*e4b17023SJohn Marino }
83*e4b17023SJohn Marino 
84*e4b17023SJohn Marino static inline int
__gthread_mutex_unlock(__gthread_mutex_t * mutex)85*e4b17023SJohn Marino __gthread_mutex_unlock (__gthread_mutex_t *mutex)
86*e4b17023SJohn Marino {
87*e4b17023SJohn Marino   return semGive (*mutex);
88*e4b17023SJohn Marino }
89*e4b17023SJohn Marino 
90*e4b17023SJohn Marino static inline void
__gthread_recursive_mutex_init_function(__gthread_recursive_mutex_t * mutex)91*e4b17023SJohn Marino __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
92*e4b17023SJohn Marino {
93*e4b17023SJohn Marino   __gthread_mutex_init_function (mutex);
94*e4b17023SJohn Marino }
95*e4b17023SJohn Marino 
96*e4b17023SJohn Marino static inline int
__gthread_recursive_mutex_lock(__gthread_recursive_mutex_t * mutex)97*e4b17023SJohn Marino __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
98*e4b17023SJohn Marino {
99*e4b17023SJohn Marino   return __gthread_mutex_lock (mutex);
100*e4b17023SJohn Marino }
101*e4b17023SJohn Marino 
102*e4b17023SJohn Marino static inline int
__gthread_recursive_mutex_trylock(__gthread_recursive_mutex_t * mutex)103*e4b17023SJohn Marino __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
104*e4b17023SJohn Marino {
105*e4b17023SJohn Marino   return __gthread_mutex_trylock (mutex);
106*e4b17023SJohn Marino }
107*e4b17023SJohn Marino 
108*e4b17023SJohn Marino static inline int
__gthread_recursive_mutex_unlock(__gthread_recursive_mutex_t * mutex)109*e4b17023SJohn Marino __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
110*e4b17023SJohn Marino {
111*e4b17023SJohn Marino   return __gthread_mutex_unlock (mutex);
112*e4b17023SJohn Marino }
113*e4b17023SJohn Marino 
114*e4b17023SJohn Marino /* pthread_once is complicated enough that it's implemented
115*e4b17023SJohn Marino    out-of-line.  See config/vxlib.c.  */
116*e4b17023SJohn Marino 
117*e4b17023SJohn Marino typedef struct
118*e4b17023SJohn Marino {
119*e4b17023SJohn Marino #if !defined(__RTP__)
120*e4b17023SJohn Marino #if defined(__PPC__)
121*e4b17023SJohn Marino   __attribute ((aligned (__alignof (unsigned))))
122*e4b17023SJohn Marino #endif
123*e4b17023SJohn Marino   volatile unsigned char busy;
124*e4b17023SJohn Marino #endif
125*e4b17023SJohn Marino   volatile unsigned char done;
126*e4b17023SJohn Marino #if !defined(__RTP__) && defined(__PPC__)
127*e4b17023SJohn Marino   /* PPC's test-and-set implementation requires a 4 byte aligned
128*e4b17023SJohn Marino      object, of which it only sets the first byte.  We use padding
129*e4b17023SJohn Marino      here, in order to maintain some amount of backwards
130*e4b17023SJohn Marino      compatibility.  Without this padding, gthread_once objects worked
131*e4b17023SJohn Marino      by accident because they happen to be static objects and the ppc
132*e4b17023SJohn Marino      port automatically increased their alignment to 4 bytes.  */
133*e4b17023SJohn Marino   unsigned char pad1;
134*e4b17023SJohn Marino   unsigned char pad2;
135*e4b17023SJohn Marino #endif
136*e4b17023SJohn Marino }
137*e4b17023SJohn Marino __gthread_once_t;
138*e4b17023SJohn Marino 
139*e4b17023SJohn Marino #if defined (__RTP__)
140*e4b17023SJohn Marino # define __GTHREAD_ONCE_INIT { 0 }
141*e4b17023SJohn Marino #elif defined (__PPC__)
142*e4b17023SJohn Marino # define __GTHREAD_ONCE_INIT { 0, 0, 0, 0 }
143*e4b17023SJohn Marino #else
144*e4b17023SJohn Marino # define __GTHREAD_ONCE_INIT { 0, 0 }
145*e4b17023SJohn Marino #endif
146*e4b17023SJohn Marino 
147*e4b17023SJohn Marino extern int __gthread_once (__gthread_once_t *__once, void (*__func)(void));
148*e4b17023SJohn Marino 
149*e4b17023SJohn Marino /* Thread-specific data requires a great deal of effort, since VxWorks
150*e4b17023SJohn Marino    is not really set up for it.  See config/vxlib.c for the gory
151*e4b17023SJohn Marino    details.  All the TSD routines are sufficiently complex that they
152*e4b17023SJohn Marino    need to be implemented out of line.  */
153*e4b17023SJohn Marino 
154*e4b17023SJohn Marino typedef unsigned int __gthread_key_t;
155*e4b17023SJohn Marino 
156*e4b17023SJohn Marino extern int __gthread_key_create (__gthread_key_t *__keyp, void (*__dtor)(void *));
157*e4b17023SJohn Marino extern int __gthread_key_delete (__gthread_key_t __key);
158*e4b17023SJohn Marino 
159*e4b17023SJohn Marino extern void *__gthread_getspecific (__gthread_key_t __key);
160*e4b17023SJohn Marino extern int __gthread_setspecific (__gthread_key_t __key, void *__ptr);
161*e4b17023SJohn Marino 
162*e4b17023SJohn Marino #undef UNUSED
163*e4b17023SJohn Marino 
164*e4b17023SJohn Marino #ifdef __cplusplus
165*e4b17023SJohn Marino }
166*e4b17023SJohn Marino #endif
167*e4b17023SJohn Marino 
168*e4b17023SJohn Marino #endif /* not _LIBOBJC */
169*e4b17023SJohn Marino 
170*e4b17023SJohn Marino #endif /* gthr-vxworks.h */
171