Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6536 serge 1
/* Threads compatibility routines for libgcc2 and libobjc.  */
2
/* Compile this one with gcc.  */
3
 
4
/* Copyright (C) 1999-2015 Free Software Foundation, Inc.
5
   Contributed by Mumit Khan .
6
 
7
This file is part of GCC.
8
 
9
GCC is free software; you can redistribute it and/or modify it under
10
the terms of the GNU General Public License as published by the Free
11
Software Foundation; either version 3, or (at your option) any later
12
version.
13
 
14
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15
WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17
for more details.
18
 
19
Under Section 7 of GPL version 3, you are granted additional
20
permissions described in the GCC Runtime Library Exception, version
21
3.1, as published by the Free Software Foundation.
22
 
23
You should have received a copy of the GNU General Public License and
24
a copy of the GCC Runtime Library Exception along with this program;
25
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
26
.  */
27
 
28
#ifndef GCC_GTHR_KOS32_H
29
#define GCC_GTHR_KOS32_H
30
 
31
/* Make sure CONST_CAST2 (origin in system.h) is declared.  */
32
#ifndef CONST_CAST2
33
#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq)
34
#endif
35
 
36
 
37
#define __GTHREADS 1
38
 
39
#include 
40
 
41
#ifndef __UNUSED_PARAM
42
#define __UNUSED_PARAM(x) x
43
#endif
44
 
45
 
46
#ifdef __cplusplus
47
extern "C" {
48
#endif
49
 
50
typedef unsigned long __gthread_key_t;
51
 
52
typedef struct
53
{
54
    int done;
55
    long started;
56
} __gthread_once_t;
57
 
58
typedef struct
59
{
60
    volatile int lock;
61
    int handle;
62
} __gthread_mutex_t;
63
 
64
typedef struct
65
{
66
    volatile int lock;
67
    int handle;
68
    long depth;
69
    unsigned long owner;
70
} __gthread_recursive_mutex_t;
71
 
72
#define __GTHREAD_ONCE_INIT {0, -1}
73
#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
74
 
75
#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION \
76
  __gthread_recursive_mutex_init_function
77
 
78
 
79
#if defined (_WIN32) && !defined(__CYGWIN__)
80
#define MINGW32_SUPPORTS_MT_EH 1
81
/* Mingw runtime >= v0.3 provides a magic variable that is set to nonzero
82
   if -mthreads option was specified, or 0 otherwise. This is to get around
83
   the lack of weak symbols in PE-COFF.  */
84
extern int _CRT_MT;
85
extern int __mingwthr_key_dtor (unsigned long, void (*) (void *));
86
#endif /* _WIN32 && !__CYGWIN__ */
87
 
88
 
89
static inline int __gthread_active_p (void)
90
{
91
#ifdef MINGW32_SUPPORTS_MT_EH
92
  return _CRT_MT;
93
#else
94
  return 1;
95
#endif
96
}
97
 
98
extern int __gthr_kos32_once (__gthread_once_t *, void (*) (void));
99
extern int __gthr_kos32_key_create (__gthread_key_t *, void (*) (void*));
100
extern int __gthr_kos32_key_delete (__gthread_key_t);
101
extern void * __gthr_kos32_getspecific (__gthread_key_t);
102
extern int __gthr_kos32_setspecific (__gthread_key_t, const void *);
103
extern void __gthr_kos32_mutex_init_function (__gthread_mutex_t *);
104
extern int __gthr_kos32_mutex_lock (__gthread_mutex_t *);
105
extern int __gthr_kos32_mutex_trylock (__gthread_mutex_t *);
106
extern int __gthr_kos32_mutex_unlock (__gthread_mutex_t *);
107
extern void __gthr_kos32_recursive_mutex_init_function (__gthread_recursive_mutex_t *);
108
extern int  __gthr_kos32_recursive_mutex_lock (__gthread_recursive_mutex_t *);
109
extern int  __gthr_kos32_recursive_mutex_trylock (__gthread_recursive_mutex_t *);
110
extern int  __gthr_kos32_recursive_mutex_unlock (__gthread_recursive_mutex_t *);
111
extern void __gthr_kos32_mutex_destroy (__gthread_mutex_t *);
112
extern int  __gthr_kos32_recursive_mutex_destroy (__gthread_recursive_mutex_t *);
113
 
114
static inline int __gthread_once (__gthread_once_t *__once, void (*__func) (void))
115
{
116
    if (__gthread_active_p ())
117
        return __gthr_kos32_once (__once, __func);
118
    else
119
        return -1;
120
}
121
 
122
static inline int __gthread_key_create (__gthread_key_t *__key, void (*__dtor) (void *))
123
{
124
    return __gthr_kos32_key_create (__key, __dtor);
125
}
126
 
127
static inline int __gthread_key_delete (__gthread_key_t __key)
128
{
129
    return __gthr_kos32_key_delete (__key);
130
}
131
 
132
static inline void* __gthread_getspecific (__gthread_key_t __key)
133
{
134
    return __gthr_kos32_getspecific (__key);
135
}
136
 
137
static inline int __gthread_setspecific (__gthread_key_t __key, const void *__ptr)
138
{
139
    return __gthr_kos32_setspecific (__key, __ptr);
140
}
141
 
142
static inline void __gthread_mutex_init_function (__gthread_mutex_t *__mutex)
143
{
144
    __gthr_kos32_mutex_init_function(__mutex);
145
}
146
 
147
static inline void __gthread_mutex_destroy (__gthread_mutex_t *__mutex)
148
{
149
    __gthr_kos32_mutex_destroy (__mutex);
150
}
151
 
152
static inline int __gthread_mutex_lock (__gthread_mutex_t *__mutex)
153
{
154
    if (__gthread_active_p ())
155
        return __gthr_kos32_mutex_lock (__mutex);
156
    else
157
        return 0;
158
}
159
 
160
static inline int __gthread_mutex_trylock (__gthread_mutex_t *__mutex)
161
{
162
    if (__gthread_active_p ())
163
        return __gthr_kos32_mutex_trylock (__mutex);
164
    else
165
        return 0;
166
}
167
 
168
static inline int __gthread_mutex_unlock (__gthread_mutex_t *__mutex)
169
{
170
    if (__gthread_active_p ())
171
        return __gthr_kos32_mutex_unlock (__mutex);
172
    else
173
        return 0;
174
}
175
 
176
static inline void __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex)
177
{
178
    __gthr_kos32_recursive_mutex_init_function (__mutex);
179
}
180
 
181
static inline int __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex)
182
{
183
    if (__gthread_active_p ())
184
        return __gthr_kos32_recursive_mutex_lock (__mutex);
185
    else
186
        return 0;
187
}
188
 
189
static inline int __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex)
190
{
191
    if (__gthread_active_p ())
192
        return __gthr_kos32_recursive_mutex_trylock (__mutex);
193
    else
194
        return 0;
195
}
196
 
197
static inline int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)
198
{
199
  if (__gthread_active_p ())
200
        return __gthr_kos32_recursive_mutex_unlock (__mutex);
201
  else
202
        return 0;
203
}
204
 
205
static inline int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex)
206
{
207
    return __gthr_kos32_recursive_mutex_destroy (__mutex);
208
}
209
 
210
 
211
#ifdef __cplusplus
212
}
213
#endif
214
 
215
#endif /* ! GCC_GTHR_WIN32_H */