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 void *p
= (void*)taskVarGet(tid
, &eh_context_key
);
71 taskVarSet(tid
, &eh_context_key
, 0);
75 /* This only works for the code in libgcc2.c. */
78 __gthread_key_create (__gthread_key_t
*key
, void (*dtor
) (void *))
82 /* Do this first so that the task variables are visible during the
83 running of the delete hook. */
87 /* We don't have a way to track dtor here, so instead, we
88 register a generic routine that can cleanup any task. */
90 taskDeleteHookAdd (__ehdtor
);
95 #define __gthread_setspecific(key, ptr) \
99 __gthread_key_dtor (__gthread_key_t key
, void *ptr
)
101 /* Just reset the key value to zero. */
103 return __gthread_setspecific (key
, 0);
108 #define __gthread_key_delete(key) \
109 taskVarDelete (taskIdSelf (), &key)
111 #define __gthread_getspecific(key) \
113 ? ((taskVarAdd (taskIdSelf (), &key) != OK) \
114 ? (__terminate (), (void*)0) \
120 __gthread_mutex_lock (__gthread_mutex_t
*mutex
)
123 *mutex
= semMCreate (SEM_Q_PRIORITY
| SEM_INVERSION_SAFE
| SEM_DELETE_SAFE
);
124 return semTake (*mutex
, WAIT_FOREVER
);
128 __gthread_mutex_trylock (__gthread_mutex_t
*mutex
)
131 *mutex
= semMCreate (SEM_Q_PRIORITY
| SEM_INVERSION_SAFE
| SEM_DELETE_SAFE
);
132 return semTake (*mutex
, NO_WAIT
);
136 __gthread_mutex_unlock (__gthread_mutex_t
*mutex
)
138 /* We could return the */
139 return semGive (*mutex
);
142 #endif /* not __gthr_vxworks_h */