OSDN Git Service

PR middle-end/35616
[pf3gnuchains/gcc-fork.git] / gcc / gthr-vxworks.h
1 /* Threads compatibility routines for libgcc2 and libobjc for VxWorks.  */
2 /* Compile this one with gcc.  */
3 /* Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
4    Contributed by Mike Stump <mrs@wrs.com>.
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, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, 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_VXWORKS_H
31 #define GCC_GTHR_VXWORKS_H
32
33 #ifdef _LIBOBJC
34
35 /* libobjc requires the optional pthreads component.  */
36 #include "gthr-posix.h"
37
38 #else
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #define __GTHREADS 1
45 #define __gthread_active_p() 1
46
47 /* Mutexes are easy, except that they need to be initialized at runtime.  */
48
49 #include <semLib.h>
50
51 typedef SEM_ID __gthread_mutex_t;
52 /* All VxWorks mutexes are recursive.  */
53 typedef SEM_ID __gthread_recursive_mutex_t;
54 #define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
55 #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
56
57 static inline void
58 __gthread_mutex_init_function (__gthread_mutex_t *mutex)
59 {
60   *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
61 }
62
63 static inline int
64 __gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
65 {
66   return 0;
67 }
68
69 static inline int
70 __gthread_mutex_lock (__gthread_mutex_t *mutex)
71 {
72   return semTake (*mutex, WAIT_FOREVER);
73 }
74
75 static inline int
76 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
77 {
78   return semTake (*mutex, NO_WAIT);
79 }
80
81 static inline int
82 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
83 {
84   return semGive (*mutex);
85 }
86
87 static inline void
88 __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
89 {
90   __gthread_mutex_init_function (mutex);
91 }
92
93 static inline int
94 __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
95 {
96   return __gthread_mutex_lock (mutex);
97 }
98
99 static inline int
100 __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
101 {
102   return __gthread_mutex_trylock (mutex);
103 }
104
105 static inline int
106 __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
107 {
108   return __gthread_mutex_unlock (mutex);
109 }
110
111 /* pthread_once is complicated enough that it's implemented
112    out-of-line.  See config/vxlib.c.  */
113
114 typedef struct
115 {
116 #ifndef __RTP__
117   volatile unsigned char busy;
118 #endif
119   volatile unsigned char done;
120 }
121 __gthread_once_t;
122
123 #ifndef __RTP__
124 # define __GTHREAD_ONCE_INIT { 0, 0 }
125 #else
126 # define __GTHREAD_ONCE_INIT { 0 }
127 #endif
128
129 extern int __gthread_once (__gthread_once_t *once, void (*func)(void));
130
131 /* Thread-specific data requires a great deal of effort, since VxWorks
132    is not really set up for it.  See config/vxlib.c for the gory
133    details.  All the TSD routines are sufficiently complex that they
134    need to be implemented out of line.  */
135
136 typedef unsigned int __gthread_key_t;
137
138 extern int __gthread_key_create (__gthread_key_t *keyp, void (*dtor)(void *));
139 extern int __gthread_key_delete (__gthread_key_t key);
140
141 extern void *__gthread_getspecific (__gthread_key_t key);
142 extern int __gthread_setspecific (__gthread_key_t key, void *ptr);
143
144 #ifdef __cplusplus
145 }
146 #endif
147
148 #endif /* not _LIBOBJC */
149
150 #endif /* gthr-vxworks.h */