Fix type.
[official-gcc.git] / gcc / gthr-vxworks.h
blobc85b5e535f37ee1462eb70458b9a0b35ce75167a
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>.
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 2, 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 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. */
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. */
30 #ifndef GCC_GTHR_VXWORKS_H
31 #define GCC_GTHR_VXWORKS_H
33 #ifdef _LIBOBJC
35 /* Thread local storage for a single thread */
36 static void *thread_local_storage = NULL;
38 /* Backend initialization functions */
40 /* Initialize the threads subsystem. */
41 int
42 __gthread_objc_init_thread_system (void)
44 /* No thread support available */
45 return -1;
48 /* Close the threads subsystem. */
49 int
50 __gthread_objc_close_thread_system (void)
52 /* No thread support available */
53 return -1;
56 /* Backend thread functions */
58 /* Create a new thread of execution. */
59 objc_thread_t
60 __gthread_objc_thread_detach (void (*func)(void *arg), void *arg)
62 /* No thread support available */
63 return NULL;
66 /* Set the current thread's priority. */
67 int
68 __gthread_objc_thread_set_priority (int priority)
70 /* No thread support available */
71 return -1;
74 /* Return the current thread's priority. */
75 int
76 __gthread_objc_thread_get_priority (void)
78 return OBJC_THREAD_INTERACTIVE_PRIORITY;
81 /* Yield our process time to another thread. */
82 void
83 __gthread_objc_thread_yield (void)
85 return;
88 /* Terminate the current thread. */
89 int
90 __gthread_objc_thread_exit (void)
92 /* No thread support available */
93 /* Should we really exit the program */
94 /* exit (&__objc_thread_exit_status); */
95 return -1;
98 /* Returns an integer value which uniquely describes a thread. */
99 objc_thread_t
100 __gthread_objc_thread_id (void)
102 /* No thread support, use 1. */
103 return (objc_thread_t) 1;
106 /* Sets the thread's local storage pointer. */
108 __gthread_objc_thread_set_data (void *value)
110 thread_local_storage = value;
111 return 0;
114 /* Returns the thread's local storage pointer. */
115 void *
116 __gthread_objc_thread_get_data (void)
118 return thread_local_storage;
121 /* Backend mutex functions */
123 /* Allocate a mutex. */
125 __gthread_objc_mutex_allocate (objc_mutex_t mutex)
127 return 0;
130 /* Deallocate a mutex. */
132 __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
134 return 0;
137 /* Grab a lock on a mutex. */
139 __gthread_objc_mutex_lock (objc_mutex_t mutex)
141 /* There can only be one thread, so we always get the lock */
142 return 0;
145 /* Try to grab a lock on a mutex. */
147 __gthread_objc_mutex_trylock (objc_mutex_t mutex)
149 /* There can only be one thread, so we always get the lock */
150 return 0;
153 /* Unlock the mutex */
155 __gthread_objc_mutex_unlock (objc_mutex_t mutex)
157 return 0;
160 /* Backend condition mutex functions */
162 /* Allocate a condition. */
164 __gthread_objc_condition_allocate (objc_condition_t condition)
166 return 0;
169 /* Deallocate a condition. */
171 __gthread_objc_condition_deallocate (objc_condition_t condition)
173 return 0;
176 /* Wait on the condition */
178 __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
180 return 0;
183 /* Wake up all threads waiting on this condition. */
185 __gthread_objc_condition_broadcast (objc_condition_t condition)
187 return 0;
190 /* Wake up one thread waiting on this condition. */
192 __gthread_objc_condition_signal (objc_condition_t condition)
194 return 0;
197 #else /* _LIBOBJC */
199 /* POSIX threads specific definitions.
200 Easy, since the interface is just one-to-one mapping. */
202 #define __GTHREADS 1
204 #include <vxWorks.h>
205 #include <semLib.h>
206 /* typedef void *SEM_ID; */
208 typedef int __gthread_key_t;
209 typedef char __gthread_once_t;
210 typedef SEM_ID __gthread_mutex_t;
212 #define __GTHREAD_MUTEX_INIT 0
213 #define __GTHREAD_ONCE_INIT 0
215 #ifndef REG_SAVED_REG
216 static inline int
217 __gthread_once (__gthread_once_t *once, void (*func) (void))
219 (*func)();
220 return 0;
223 extern __gthread_key_t eh_context_key;
225 /* This is not the right way to do it, but the semantic of pthreads
226 don't map well enough onto VxWorks. */
228 static void
229 __ehdtor (void *pTcb)
231 int tid = (int) pTcb;
232 void *p = (void *) taskVarGet (tid, &eh_context_key);
233 if (p != (void *) -1)
235 if (p)
236 free (p);
237 taskVarSet (tid, &eh_context_key, 0);
241 /* This only works for the code in libgcc2.c. */
243 static inline int
244 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
246 *key = 0;
248 /* Do this first so that the task variables are visible during the
249 running of the delete hook. */
251 taskVarInit ();
253 /* We don't have a way to track dtor here, so instead, we
254 register a generic routine that can cleanup any task. */
256 taskDeleteHookAdd (__ehdtor);
258 return 0;
261 #define __gthread_setspecific(key, ptr) \
262 (key = (int) ptr, 0)
264 static inline int
265 __gthread_key_dtor (__gthread_key_t key, void *ptr)
267 /* Just reset the key value to zero. */
268 if (ptr)
269 return __gthread_setspecific (key, 0);
270 else
271 return 0;
274 #define __gthread_key_delete(key) \
275 taskVarDelete (taskIdSelf (), &key)
277 #define __gthread_getspecific(key) \
278 ((key == 0) \
279 ? ((taskVarAdd (taskIdSelf (), &key) != OK) \
280 ? (__terminate (), (void *) 0) \
281 : (void *) 0) \
282 : (void *) key)
283 #endif
285 static inline int
286 __gthread_mutex_lock (__gthread_mutex_t *mutex)
288 if (*mutex == 0)
289 *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
290 return semTake (*mutex, WAIT_FOREVER);
293 static inline int
294 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
296 if (*mutex == 0)
297 *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
298 return semTake (*mutex, NO_WAIT);
301 static inline int
302 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
304 /* We could return the */
305 return semGive (*mutex);
308 #endif /* _LIBOBJC */
310 #endif /* ! GCC_GTHR_VXWORKS_H */