1 /* Threads compatibily routines for libgcc2 for VxWorks. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1997 Free Software Foundation, Inc.
4 Contributed by Mike Stump <mrs@wrs.com>.
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 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 __gthr_vxworks_h
31 #define __gthr_vxworks_h
33 /* POSIX threads specific definitions.
34 Easy, since the interface is just one-to-one mapping. */
40 /* typedef void *SEM_ID; */
42 typedef int __gthread_key_t
;
43 typedef char __gthread_once_t
;
44 typedef SEM_ID __gthread_mutex_t
;
46 #define __GTHREAD_MUTEX_INIT 0
47 #define __GTHREAD_ONCE_INIT 0
51 __gthread_once (__gthread_once_t
*once
, void (*func
) ())
57 extern __gthread_key_t eh_context_key
;
59 /* This is not the right way to do it, but the semantic of pthreads
60 don't map well enough onto VxWorks. */
66 free ((void*)eh_context_key
);
70 /* This only works for the code in libgcc2.c. */
73 __gthread_key_create (__gthread_key_t
*key
, void (*dtor
) (void *))
77 /* We don't have a way to track dtor here, so instead, we
78 register a generic routine that can cleanup any task. */
80 taskDeleteHookAdd (__ehdtor
);
85 #define __gthread_setspecific(key, ptr) \
89 __gthread_key_dtor (__gthread_key_t key
, void *ptr
)
91 /* Just reset the key value to zero. */
93 return __gthread_setspecific (key
, 0);
98 #define __gthread_key_delete(key) \
99 taskVarDelete (taskIdSelf (), &key)
101 #define __gthread_getspecific(key) \
103 ? ((taskVarAdd (taskIdSelf (), &key) != OK) \
104 ? (__terminate (), (void*)0) \
110 __gthread_mutex_lock (__gthread_mutex_t
*mutex
)
113 *mutex
= semMCreate (SEM_Q_PRIORITY
| SEM_INVERSION_SAFE
| SEM_DELETE_SAFE
);
114 return semTake (*mutex
, WAIT_FOREVER
);
118 __gthread_mutex_trylock (__gthread_mutex_t
*mutex
)
121 *mutex
= semMCreate (SEM_Q_PRIORITY
| SEM_INVERSION_SAFE
| SEM_DELETE_SAFE
);
122 return semTake (*mutex
, NO_WAIT
);
126 __gthread_mutex_unlock (__gthread_mutex_t
*mutex
)
128 /* We could return the */
129 return semGive (*mutex
);
132 #endif /* not __gthr_vxworks_h */