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
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
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
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
35 /* Thread local storage for a single thread */
36 static void *thread_local_storage
= NULL
;
38 /* Backend initialization functions */
40 /* Initialize the threads subsystem. */
42 __gthread_objc_init_thread_system(void)
44 /* No thread support available */
48 /* Close the threads subsystem. */
50 __gthread_objc_close_thread_system(void)
52 /* No thread support available */
56 /* Backend thread functions */
58 /* Create a new thread of execution. */
60 __gthread_objc_thread_detach(void (*func
)(void *arg
), void *arg
)
62 /* No thread support available */
66 /* Set the current thread's priority. */
68 __gthread_objc_thread_set_priority(int priority
)
70 /* No thread support available */
74 /* Return the current thread's priority. */
76 __gthread_objc_thread_get_priority(void)
78 return OBJC_THREAD_INTERACTIVE_PRIORITY
;
81 /* Yield our process time to another thread. */
83 __gthread_objc_thread_yield(void)
88 /* Terminate the current thread. */
90 __gthread_objc_thread_exit(void)
92 /* No thread support available */
93 /* Should we really exit the program */
94 /* exit(&__objc_thread_exit_status); */
98 /* Returns an integer value which uniquely describes a thread. */
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
;
114 /* Returns the thread's local storage pointer. */
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
)
130 /* Deallocate a mutex. */
132 __gthread_objc_mutex_deallocate(objc_mutex_t mutex
)
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 */
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 */
153 /* Unlock the mutex */
155 __gthread_objc_mutex_unlock(objc_mutex_t mutex
)
160 /* Backend condition mutex functions */
162 /* Allocate a condition. */
164 __gthread_objc_condition_allocate(objc_condition_t condition
)
169 /* Deallocate a condition. */
171 __gthread_objc_condition_deallocate(objc_condition_t condition
)
176 /* Wait on the condition */
178 __gthread_objc_condition_wait(objc_condition_t condition
, objc_mutex_t mutex
)
183 /* Wake up all threads waiting on this condition. */
185 __gthread_objc_condition_broadcast(objc_condition_t condition
)
190 /* Wake up one thread waiting on this condition. */
192 __gthread_objc_condition_signal(objc_condition_t condition
)
199 /* POSIX threads specific definitions.
200 Easy, since the interface is just one-to-one mapping. */
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
217 __gthread_once (__gthread_once_t
*once
, void (*func
) (void))
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. */
229 __ehdtor (void *pTcb
)
231 int tid
= (int) pTcb
;
232 void *p
= (void*)taskVarGet(tid
, &eh_context_key
);
237 taskVarSet(tid
, &eh_context_key
, 0);
241 /* This only works for the code in libgcc2.c. */
244 __gthread_key_create (__gthread_key_t
*key
, void (*dtor
) (void *))
248 /* Do this first so that the task variables are visible during the
249 running of the delete hook. */
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
);
261 #define __gthread_setspecific(key, ptr) \
265 __gthread_key_dtor (__gthread_key_t key
, void *ptr
)
267 /* Just reset the key value to zero. */
269 return __gthread_setspecific (key
, 0);
274 #define __gthread_key_delete(key) \
275 taskVarDelete (taskIdSelf (), &key)
277 #define __gthread_getspecific(key) \
279 ? ((taskVarAdd (taskIdSelf (), &key) != OK) \
280 ? (__terminate (), (void*)0) \
286 __gthread_mutex_lock (__gthread_mutex_t
*mutex
)
289 *mutex
= semMCreate (SEM_Q_PRIORITY
| SEM_INVERSION_SAFE
| SEM_DELETE_SAFE
);
290 return semTake (*mutex
, WAIT_FOREVER
);
294 __gthread_mutex_trylock (__gthread_mutex_t
*mutex
)
297 *mutex
= semMCreate (SEM_Q_PRIORITY
| SEM_INVERSION_SAFE
| SEM_DELETE_SAFE
);
298 return semTake (*mutex
, NO_WAIT
);
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 */