OSDN Git Service

* lex.c (lang_init_options): New function.
[pf3gnuchains/gcc-fork.git] / gcc / gthr-vxworks.h
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>.
5
6 This file is part of GNU CC.
7
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)
11 any later version.
12
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.
17
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.  */
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 __gthr_vxworks_h
31 #define __gthr_vxworks_h
32
33 /* POSIX threads specific definitions.
34    Easy, since the interface is just one-to-one mapping. */
35
36 #define __GTHREADS 1
37
38 #include <vxWorks.h>
39 #include <semLib.h>
40 /* typedef void *SEM_ID; */
41
42 typedef int __gthread_key_t;
43 typedef char __gthread_once_t;
44 typedef SEM_ID __gthread_mutex_t;
45
46 #define __GTHREAD_MUTEX_INIT 0
47 #define __GTHREAD_ONCE_INIT 0
48
49 #ifndef REG_SAVED_REG
50 static inline int
51 __gthread_once (__gthread_once_t *once, void (*func) ())
52 {
53   (*func)();
54   return 0;
55 }
56
57 extern __gthread_key_t eh_context_key;
58
59 /* This is not the right way to do it, but the semantic of pthreads
60    don't map well enough onto VxWorks.  */
61
62 static void
63 __ehdtor ()
64 {
65   if (eh_context_key)
66     free ((void*)eh_context_key);
67   eh_context_key = 0;
68 }
69
70 /* This only works for the code in libgcc2.c.  */
71
72 static inline int
73 __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
74 {
75   *key = 0;
76
77   /* We don't have a way to track dtor here, so instead, we
78      register a generic routine that can cleanup any task.  */
79
80   taskDeleteHookAdd (__ehdtor);
81
82   return 0;
83 }
84
85 #define __gthread_setspecific(key, ptr) \
86   (key = (int) ptr, 0)
87
88 static inline int
89 __gthread_key_dtor (__gthread_key_t key, void *ptr)
90 {
91   /* Just reset the key value to zero. */
92   if (ptr)
93     return __gthread_setspecific (key, 0);
94   else
95     return 0;
96 }
97
98 #define __gthread_key_delete(key) \
99   taskVarDelete (taskIdSelf (), &key)
100
101 #define __gthread_getspecific(key)                      \
102      ((key == 0)                                        \
103       ? ((taskVarAdd (taskIdSelf (), &key) != OK)       \
104          ? (__terminate (), (void*)0)                   \
105          : (void*)0)                                    \
106       : (void*)key)
107 #endif
108
109 static inline int
110 __gthread_mutex_lock (__gthread_mutex_t *mutex)
111 {
112   if (*mutex == 0)
113     *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
114   return semTake (*mutex, WAIT_FOREVER);
115 }
116
117 static inline int
118 __gthread_mutex_trylock (__gthread_mutex_t *mutex)
119 {
120   if (*mutex == 0)
121     *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
122   return semTake (*mutex, NO_WAIT);
123 }
124
125 static inline int
126 __gthread_mutex_unlock (__gthread_mutex_t *mutex)
127 {
128   /* We could return the */
129   return semGive (*mutex);
130 }
131
132 #endif /* not __gthr_vxworks_h */