CPPMyth
Library to interoperate with MythTV server
Loading...
Searching...
No Matches
winpthreads.h
1/*
2 * Posix Threads library for Microsoft Windows
3 *
4 * Use at own risk, there is no implied warranty to this code.
5 * It uses undocumented features of Microsoft Windows that can change
6 * at any time in the future.
7 *
8 * (C) 2010 Lockless Inc.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 *
14 *
15 * * Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * * Neither the name of Lockless Inc. nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AN
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33 * OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef WIN_PTHREADS
37#define WIN_PTHREADS
38
39#include <Windows.h>
40#include <errno.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#ifndef ETIMEDOUT
47#define ETIMEDOUT 110
48#endif
49#ifndef ENOTSUP
50#define ENOTSUP 134
51#endif
52
53#define PTHREAD_CANCEL_DISABLE 0
54#define PTHREAD_CANCEL_ENABLE 0x01
55
56#define PTHREAD_CANCEL_DEFERRED 0
57#define PTHREAD_CANCEL_ASYNCHRONOUS 0x02
58
59#define PTHREAD_CREATE_JOINABLE 0
60#define PTHREAD_CREATE_DETACHED 0x04
61
62#define PTHREAD_EXPLICT_SCHED 0
63#define PTHREAD_INHERIT_SCHED 0x08
64
65#define PTHREAD_SCOPE_PROCESS 0
66#define PTHREAD_SCOPE_SYSTEM 0x10
67
68#define PTHREAD_DEFAULT_ATTR (PTHREAD_CANCEL_ENABLE)
69
70#define PTHREAD_CANCELED ((void *) 0xDEADBEEF)
71
72#define PTHREAD_ONCE_INIT 0
73#define PTHREAD_MUTEX_INITIALIZER {(void*)-1,-1,0,0,0,0}
74#define PTHREAD_RWLOCK_INITIALIZER {0}
75#define PTHREAD_COND_INITIALIZER {0}
76#define PTHREAD_BARRIER_INITIALIZER \
77 {0,0,PTHREAD_MUTEX_INITIALIZER,PTHREAD_COND_INITIALIZER}
78#define PTHREAD_SPINLOCK_INITIALIZER 0
79
80#define PTHREAD_DESTRUCTOR_ITERATIONS 256
81#define PTHREAD_KEYS_MAX (1<<20)
82
83#define PTHREAD_MUTEX_NORMAL 0
84#define PTHREAD_MUTEX_ERRORCHECK 1
85#define PTHREAD_MUTEX_RECURSIVE 2
86#define PTHREAD_MUTEX_DEFAULT 3
87#define PTHREAD_MUTEX_SHARED 4
88#define PTHREAD_MUTEX_PRIVATE 0
89#define PTHREAD_PRIO_NONE 0
90#define PTHREAD_PRIO_INHERIT 8
91#define PTHREAD_PRIO_PROTECT 16
92#define PTHREAD_PRIO_MULT 32
93#define PTHREAD_PROCESS_SHARED 0
94#define PTHREAD_PROCESS_PRIVATE 1
95
96#define PTHREAD_BARRIER_SERIAL_THREAD 1
97
98/* Windows doesn't have this, so declare it ourselves. */
99#if (_MSC_VER < 1900)
101{
102 /* long long in windows is the same as long in unix for 64bit */
103 long long tv_sec;
104 long long tv_nsec;
105};
106#else
107#include <time.h>
108#endif
109
110struct _pthread_v;
111typedef struct _pthread_v *pthread_t;
112
114{
115 int count;
116 int total;
117 CRITICAL_SECTION m;
118 CONDITION_VARIABLE cv;
119};
120
122
124{
125 unsigned p_state;
126 void *stack;
127 size_t s_size;
128};
129
130typedef struct pthread_attr_t pthread_attr_t;
131
132typedef long pthread_once_t;
133typedef unsigned pthread_mutexattr_t;
134typedef SRWLOCK pthread_rwlock_t;
135typedef CRITICAL_SECTION pthread_mutex_t;
136typedef unsigned pthread_key_t;
137typedef void *pthread_barrierattr_t;
138typedef long pthread_spinlock_t;
139typedef int pthread_condattr_t;
140typedef CONDITION_VARIABLE pthread_cond_t;
141typedef int pthread_rwlockattr_t;
142
143extern pthread_t pthread_self(void);
144
145extern int pthread_once(pthread_once_t *o, void(*func)(void));
146
147extern int pthread_mutex_lock(pthread_mutex_t *m);
148
149extern int pthread_mutex_unlock(pthread_mutex_t *m);
150
151extern int pthread_mutex_trylock(pthread_mutex_t *m);
152
153extern int pthread_mutex_init(pthread_mutex_t *m, pthread_mutexattr_t *a);
154
155extern int pthread_mutex_destroy(pthread_mutex_t *m);
156
157#define pthread_mutex_getprioceiling(M, P) ENOTSUP
158#define pthread_mutex_setprioceiling(M, P) ENOTSUP
159
160extern int pthread_equal(pthread_t t1, pthread_t t2);
161
162extern int pthread_rwlock_init(pthread_rwlock_t *l, pthread_rwlockattr_t *a);
163
164extern int pthread_rwlock_destroy(pthread_rwlock_t *l);
165
166extern int pthread_rwlock_rdlock(pthread_rwlock_t *l);
167
168extern int pthread_rwlock_wrlock(pthread_rwlock_t *l);
169
170extern int pthread_rwlock_unlock(pthread_rwlock_t *l);
171
172extern int pthread_rwlock_tryrdlock(pthread_rwlock_t *l);
173
174extern int pthread_rwlock_trywrlock(pthread_rwlock_t *l);
175
176extern void pthread_tls_init(void);
177
178extern int pthread_rwlock_timedrdlock(pthread_rwlock_t *l, const struct timespec *ts);
179
180extern int pthread_rwlock_timedwrlock(pthread_rwlock_t *l, const struct timespec *ts);
181
182extern int pthread_get_concurrency(int *val);
183
184extern int pthread_set_concurrency(int val);
185
186#define pthread_getschedparam(T, P, S) ENOTSUP
187#define pthread_setschedparam(T, P, S) ENOTSUP
188#define pthread_getcpuclockid(T, C) ENOTSUP
189
190extern int pthread_exit(void *res);
191
192extern void pthread_testcancel(void);
193
194extern int pthread_cancel(pthread_t t);
195
196extern int pthread_attr_init(pthread_attr_t *attr);
197
198extern int pthread_attr_destroy(pthread_attr_t *attr);
199
200extern int pthread_attr_setdetachstate(pthread_attr_t *a, int flag);
201
202extern int pthread_attr_getdetachstate(pthread_attr_t *a, int *flag);
203
204extern int pthread_attr_setinheritsched(pthread_attr_t *a, int flag);
205
206extern int pthread_attr_getinheritsched(pthread_attr_t *a, int *flag);
207
208extern int pthread_attr_setscope(pthread_attr_t *a, int flag);
209
210extern int pthread_attr_getscope(pthread_attr_t *a, int *flag);
211
212extern int pthread_attr_getstackaddr(pthread_attr_t *attr, void **stack);
213
214extern int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stack);
215
216extern int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *size);
217
218extern int pthread_attr_setstacksize(pthread_attr_t *attr, size_t size);
219
220#define pthread_attr_getguardsize(A, S) ENOTSUP
221#define pthread_attr_setgaurdsize(A, S) ENOTSUP
222#define pthread_attr_getschedparam(A, S) ENOTSUP
223#define pthread_attr_setschedparam(A, S) ENOTSUP
224#define pthread_attr_getschedpolicy(A, S) ENOTSUP
225#define pthread_attr_setschedpolicy(A, S) ENOTSUP
226
227extern int pthread_setcancelstate(int state, int *oldstate);
228
229extern int pthread_setcanceltype(int type, int *oldtype);
230
231extern unsigned __stdcall pthread_create_wrapper(void *args);
232
233extern int pthread_create(pthread_t *th, pthread_attr_t *attr, void *(*func)(void *), void *arg);
234
235extern int pthread_join(pthread_t t, void **res);
236
237extern int pthread_detach(pthread_t t);
238
239extern int pthread_mutexattr_init(pthread_mutexattr_t *a);
240
241extern int pthread_mutexattr_destroy(pthread_mutexattr_t *a);
242
243extern int pthread_mutexattr_gettype(pthread_mutexattr_t *a, int *type);
244
245extern int pthread_mutexattr_settype(pthread_mutexattr_t *a, int type);
246
247extern int pthread_mutexattr_getpshared(pthread_mutexattr_t *a, int *type);
248
249extern int pthread_mutexattr_setpshared(pthread_mutexattr_t * a, int type);
250
251extern int pthread_mutexattr_getprotocol(pthread_mutexattr_t *a, int *type);
252
253extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int type);
254
255extern int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *a, int * prio);
256
257extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *a, int prio);
258
259extern int pthread_mutex_timedlock(pthread_mutex_t *m, struct timespec *ts);
260
261extern int pthread_barrier_destroy(pthread_barrier_t *b);
262
263extern int pthread_barrier_init(pthread_barrier_t *b, void *attr, int count);
264
265extern int pthread_barrier_wait(pthread_barrier_t *b);
266
267extern int pthread_barrierattr_init(void **attr);
268
269extern int pthread_barrierattr_destroy(void **attr);
270
271extern int pthread_barrierattr_setpshared(void **attr, int s);
272
273extern int pthread_barrierattr_getpshared(void **attr, int *s);
274
275extern int pthread_key_create(pthread_key_t *key, void(*dest)(void *));
276
277extern int pthread_key_delete(pthread_key_t key);
278
279extern void *pthread_getspecific(pthread_key_t key);
280
281extern int pthread_setspecific(pthread_key_t key, const void *value);
282
283extern int pthread_spin_init(pthread_spinlock_t *l, int pshared);
284
285extern int pthread_spin_destroy(pthread_spinlock_t *l);
286
287extern int pthread_spin_lock(pthread_spinlock_t *l);
288
289extern int pthread_spin_trylock(pthread_spinlock_t *l);
290
291extern int pthread_spin_unlock(pthread_spinlock_t *l);
292
293extern int pthread_cond_init(pthread_cond_t *c, pthread_condattr_t *a);
294
295extern int pthread_cond_signal(pthread_cond_t *c);
296
297extern int pthread_cond_broadcast(pthread_cond_t *c);
298
299extern int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m);
300
301extern int pthread_cond_destroy(pthread_cond_t *c);
302
303extern int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, struct timespec *t);
304
305extern int pthread_condattr_destroy(pthread_condattr_t *a);
306
307#define pthread_condattr_getclock(A, C) ENOTSUP
308#define pthread_condattr_setclock(A, C) ENOTSUP
309
310extern int pthread_condattr_init(pthread_condattr_t *a);
311
312extern int pthread_condattr_getpshared(pthread_condattr_t *a, int *s);
313
314extern int pthread_condattr_setpshared(pthread_condattr_t *a, int s);
315
316extern int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a);
317
318extern int pthread_rwlockattr_init(pthread_rwlockattr_t *a);
319
320extern int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *a, int *s);
321
322extern int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *a, int s);
323
324/* No fork() in windows - so ignore this */
325#define pthread_atfork(F1,F2,F3) 0
326
327/* Windows has rudimentary signals support */
328#define pthread_kill(T, S) 0
329#define pthread_sigmask(H, S1, S2) 0
330
331#ifdef __cplusplus
332}
333#endif
334
335#endif /* WIN_PTHREADS */