]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/gthr-vxworks.h
Update copyright years.
[thirdparty/gcc.git] / libgcc / config / gthr-vxworks.h
CommitLineData
15794a95 1/* Threads compatibility routines for libgcc2 and libobjc for VxWorks. */
7cc34889 2/* Compile this one with gcc. */
cbe34bb5 3/* Copyright (C) 1997-2017 Free Software Foundation, Inc.
7cc34889
MS
4 Contributed by Mike Stump <mrs@wrs.com>.
5
1322177d 6This file is part of GCC.
7cc34889 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.
7cc34889 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.
7cc34889 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.
7cc34889 21
748086b7
JJ
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/>. */
7cc34889 26
88657302
RH
27#ifndef GCC_GTHR_VXWORKS_H
28#define GCC_GTHR_VXWORKS_H
7cc34889 29
15794a95
L
30#ifdef _LIBOBJC
31
4977bab6 32/* libobjc requires the optional pthreads component. */
9fbcc75d 33#include "gthr-posix.h"
15794a95 34
4977bab6 35#else
37ca4602
NS
36#ifdef __cplusplus
37#define UNUSED(x)
38#else
7727f8f2 39#define UNUSED(x) x __attribute__((__unused__))
37ca4602 40#endif
7cc34889 41
ac0d72f6
RS
42#ifdef __cplusplus
43extern "C" {
44#endif
45
7cc34889 46#define __GTHREADS 1
4977bab6
ZW
47#define __gthread_active_p() 1
48
49/* Mutexes are easy, except that they need to be initialized at runtime. */
7cc34889 50
7cc34889 51#include <semLib.h>
7cc34889 52
7cc34889 53typedef SEM_ID __gthread_mutex_t;
40aac948
JM
54/* All VxWorks mutexes are recursive. */
55typedef SEM_ID __gthread_recursive_mutex_t;
4977bab6 56#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
40aac948 57#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
7cc34889 58
4977bab6
ZW
59static inline void
60__gthread_mutex_init_function (__gthread_mutex_t *mutex)
7cc34889 61{
4977bab6 62 *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
7cc34889
MS
63}
64
4dabf736
JB
65static inline int
66__gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
67{
68 return 0;
69}
70
7cc34889
MS
71static inline int
72__gthread_mutex_lock (__gthread_mutex_t *mutex)
73{
7cc34889
MS
74 return semTake (*mutex, WAIT_FOREVER);
75}
76
77static inline int
78__gthread_mutex_trylock (__gthread_mutex_t *mutex)
79{
7cc34889
MS
80 return semTake (*mutex, NO_WAIT);
81}
82
83static inline int
84__gthread_mutex_unlock (__gthread_mutex_t *mutex)
85{
7cc34889
MS
86 return semGive (*mutex);
87}
88
40aac948
JM
89static inline void
90__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
91{
92 __gthread_mutex_init_function (mutex);
93}
94
95static inline int
96__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
97{
98 return __gthread_mutex_lock (mutex);
99}
100
101static inline int
102__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
103{
104 return __gthread_mutex_trylock (mutex);
105}
106
107static inline int
108__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
109{
110 return __gthread_mutex_unlock (mutex);
111}
112
1504e3e1
JW
113static inline int
114__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
115{
116 return __gthread_mutex_destroy (__mutex);
117}
118
4977bab6
ZW
119/* pthread_once is complicated enough that it's implemented
120 out-of-line. See config/vxlib.c. */
121
122typedef struct
123{
24a40b35
NS
124#if !defined(__RTP__)
125#if defined(__PPC__)
126 __attribute ((aligned (__alignof (unsigned))))
127#endif
4977bab6 128 volatile unsigned char busy;
ac0d72f6 129#endif
4977bab6 130 volatile unsigned char done;
24a40b35
NS
131#if !defined(__RTP__) && defined(__PPC__)
132 /* PPC's test-and-set implementation requires a 4 byte aligned
133 object, of which it only sets the first byte. We use padding
134 here, in order to maintain some amount of backwards
135 compatibility. Without this padding, gthread_once objects worked
136 by accident because they happen to be static objects and the ppc
137 port automatically increased their alignment to 4 bytes. */
138 unsigned char pad1;
139 unsigned char pad2;
140#endif
4977bab6
ZW
141}
142__gthread_once_t;
143
24a40b35 144#if defined (__RTP__)
ac0d72f6 145# define __GTHREAD_ONCE_INIT { 0 }
b8698a0f 146#elif defined (__PPC__)
24a40b35
NS
147# define __GTHREAD_ONCE_INIT { 0, 0, 0, 0 }
148#else
149# define __GTHREAD_ONCE_INIT { 0, 0 }
ac0d72f6 150#endif
4977bab6 151
09e361bb 152extern int __gthread_once (__gthread_once_t *__once, void (*__func)(void));
4977bab6
ZW
153
154/* Thread-specific data requires a great deal of effort, since VxWorks
155 is not really set up for it. See config/vxlib.c for the gory
156 details. All the TSD routines are sufficiently complex that they
157 need to be implemented out of line. */
158
159typedef unsigned int __gthread_key_t;
160
09e361bb
JJ
161extern int __gthread_key_create (__gthread_key_t *__keyp, void (*__dtor)(void *));
162extern int __gthread_key_delete (__gthread_key_t __key);
4977bab6 163
09e361bb
JJ
164extern void *__gthread_getspecific (__gthread_key_t __key);
165extern int __gthread_setspecific (__gthread_key_t __key, void *__ptr);
4977bab6 166
37ca4602
NS
167#undef UNUSED
168
ac0d72f6
RS
169#ifdef __cplusplus
170}
171#endif
172
4977bab6 173#endif /* not _LIBOBJC */
15794a95 174
4977bab6 175#endif /* gthr-vxworks.h */