Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
[dragonfly.git] / contrib / gcc-3.4 / gcc / gthr-vxworks.h
CommitLineData
003757ed
MD
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>.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 2, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING. If not, write to the Free
20Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2102111-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 GCC_GTHR_VXWORKS_H
31#define GCC_GTHR_VXWORKS_H
32
33#ifdef _LIBOBJC
34
35/* libobjc requires the optional pthreads component. */
36#include "gthr-posix.h"
37
38#else
39
40#define __GTHREADS 1
41#define __gthread_active_p() 1
42
43/* Mutexes are easy, except that they need to be initialized at runtime. */
44
45#include <semLib.h>
46
47typedef SEM_ID __gthread_mutex_t;
48#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
49
50static inline void
51__gthread_mutex_init_function (__gthread_mutex_t *mutex)
52{
53 *mutex = semMCreate (SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);
54}
55
56static inline int
57__gthread_mutex_lock (__gthread_mutex_t *mutex)
58{
59 return semTake (*mutex, WAIT_FOREVER);
60}
61
62static inline int
63__gthread_mutex_trylock (__gthread_mutex_t *mutex)
64{
65 return semTake (*mutex, NO_WAIT);
66}
67
68static inline int
69__gthread_mutex_unlock (__gthread_mutex_t *mutex)
70{
71 return semGive (*mutex);
72}
73
74/* pthread_once is complicated enough that it's implemented
75 out-of-line. See config/vxlib.c. */
76
77typedef struct
78{
79 volatile unsigned char busy;
80 volatile unsigned char done;
81}
82__gthread_once_t;
83
84#define __GTHREAD_ONCE_INIT { 0, 0 }
85
86extern int __gthread_once (__gthread_once_t *once, void (*func)(void));
87
88/* Thread-specific data requires a great deal of effort, since VxWorks
89 is not really set up for it. See config/vxlib.c for the gory
90 details. All the TSD routines are sufficiently complex that they
91 need to be implemented out of line. */
92
93typedef unsigned int __gthread_key_t;
94
95extern int __gthread_key_create (__gthread_key_t *keyp, void (*dtor)(void *));
96extern int __gthread_key_delete (__gthread_key_t key);
97
98extern void *__gthread_getspecific (__gthread_key_t key);
99extern int __gthread_setspecific (__gthread_key_t key, void *ptr);
100
101#endif /* not _LIBOBJC */
102
103#endif /* gthr-vxworks.h */