CPPMyth
Library to interoperate with MythTV server
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
43 extern "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)
100 struct timespec
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 
110 struct _pthread_v;
111 typedef struct _pthread_v *pthread_t;
112 
114 {
115  int count;
116  int total;
117  CRITICAL_SECTION m;
118  CONDITION_VARIABLE cv;
119 };
120 
121 typedef struct pthread_barrier_t pthread_barrier_t;
122 
124 {
125  unsigned p_state;
126  void *stack;
127  size_t s_size;
128 };
129 
130 typedef struct pthread_attr_t pthread_attr_t;
131 
132 typedef long pthread_once_t;
133 typedef unsigned pthread_mutexattr_t;
134 typedef SRWLOCK pthread_rwlock_t;
135 typedef CRITICAL_SECTION pthread_mutex_t;
136 typedef unsigned pthread_key_t;
137 typedef void *pthread_barrierattr_t;
138 typedef long pthread_spinlock_t;
139 typedef int pthread_condattr_t;
140 typedef CONDITION_VARIABLE pthread_cond_t;
141 typedef int pthread_rwlockattr_t;
142 
143 extern pthread_t pthread_self(void);
144 
145 extern int pthread_once(pthread_once_t *o, void(*func)(void));
146 
147 extern int pthread_mutex_lock(pthread_mutex_t *m);
148 
149 extern int pthread_mutex_unlock(pthread_mutex_t *m);
150 
151 extern int pthread_mutex_trylock(pthread_mutex_t *m);
152 
153 extern int pthread_mutex_init(pthread_mutex_t *m, pthread_mutexattr_t *a);
154 
155 extern 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 
160 extern int pthread_equal(pthread_t t1, pthread_t t2);
161 
162 extern int pthread_rwlock_init(pthread_rwlock_t *l, pthread_rwlockattr_t *a);
163 
164 extern int pthread_rwlock_destroy(pthread_rwlock_t *l);
165 
166 extern int pthread_rwlock_rdlock(pthread_rwlock_t *l);
167 
168 extern int pthread_rwlock_wrlock(pthread_rwlock_t *l);
169 
170 extern int pthread_rwlock_unlock(pthread_rwlock_t *l);
171 
172 extern int pthread_rwlock_tryrdlock(pthread_rwlock_t *l);
173 
174 extern int pthread_rwlock_trywrlock(pthread_rwlock_t *l);
175 
176 extern void pthread_tls_init(void);
177 
178 extern int pthread_rwlock_timedrdlock(pthread_rwlock_t *l, const struct timespec *ts);
179 
180 extern int pthread_rwlock_timedwrlock(pthread_rwlock_t *l, const struct timespec *ts);
181 
182 extern int pthread_get_concurrency(int *val);
183 
184 extern 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 
190 extern int pthread_exit(void *res);
191 
192 extern void pthread_testcancel(void);
193 
194 extern int pthread_cancel(pthread_t t);
195 
196 extern int pthread_attr_init(pthread_attr_t *attr);
197 
198 extern int pthread_attr_destroy(pthread_attr_t *attr);
199 
200 extern int pthread_attr_setdetachstate(pthread_attr_t *a, int flag);
201 
202 extern int pthread_attr_getdetachstate(pthread_attr_t *a, int *flag);
203 
204 extern int pthread_attr_setinheritsched(pthread_attr_t *a, int flag);
205 
206 extern int pthread_attr_getinheritsched(pthread_attr_t *a, int *flag);
207 
208 extern int pthread_attr_setscope(pthread_attr_t *a, int flag);
209 
210 extern int pthread_attr_getscope(pthread_attr_t *a, int *flag);
211 
212 extern int pthread_attr_getstackaddr(pthread_attr_t *attr, void **stack);
213 
214 extern int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stack);
215 
216 extern int pthread_attr_getstacksize(pthread_attr_t *attr, size_t *size);
217 
218 extern 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 
227 extern int pthread_setcancelstate(int state, int *oldstate);
228 
229 extern int pthread_setcanceltype(int type, int *oldtype);
230 
231 extern unsigned __stdcall pthread_create_wrapper(void *args);
232 
233 extern int pthread_create(pthread_t *th, pthread_attr_t *attr, void *(*func)(void *), void *arg);
234 
235 extern int pthread_join(pthread_t t, void **res);
236 
237 extern int pthread_detach(pthread_t t);
238 
239 extern int pthread_mutexattr_init(pthread_mutexattr_t *a);
240 
241 extern int pthread_mutexattr_destroy(pthread_mutexattr_t *a);
242 
243 extern int pthread_mutexattr_gettype(pthread_mutexattr_t *a, int *type);
244 
245 extern int pthread_mutexattr_settype(pthread_mutexattr_t *a, int type);
246 
247 extern int pthread_mutexattr_getpshared(pthread_mutexattr_t *a, int *type);
248 
249 extern int pthread_mutexattr_setpshared(pthread_mutexattr_t * a, int type);
250 
251 extern int pthread_mutexattr_getprotocol(pthread_mutexattr_t *a, int *type);
252 
253 extern int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int type);
254 
255 extern int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *a, int * prio);
256 
257 extern int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *a, int prio);
258 
259 extern int pthread_mutex_timedlock(pthread_mutex_t *m, struct timespec *ts);
260 
261 extern int pthread_barrier_destroy(pthread_barrier_t *b);
262 
263 extern int pthread_barrier_init(pthread_barrier_t *b, void *attr, int count);
264 
265 extern int pthread_barrier_wait(pthread_barrier_t *b);
266 
267 extern int pthread_barrierattr_init(void **attr);
268 
269 extern int pthread_barrierattr_destroy(void **attr);
270 
271 extern int pthread_barrierattr_setpshared(void **attr, int s);
272 
273 extern int pthread_barrierattr_getpshared(void **attr, int *s);
274 
275 extern int pthread_key_create(pthread_key_t *key, void(*dest)(void *));
276 
277 extern int pthread_key_delete(pthread_key_t key);
278 
279 extern void *pthread_getspecific(pthread_key_t key);
280 
281 extern int pthread_setspecific(pthread_key_t key, const void *value);
282 
283 extern int pthread_spin_init(pthread_spinlock_t *l, int pshared);
284 
285 extern int pthread_spin_destroy(pthread_spinlock_t *l);
286 
287 extern int pthread_spin_lock(pthread_spinlock_t *l);
288 
289 extern int pthread_spin_trylock(pthread_spinlock_t *l);
290 
291 extern int pthread_spin_unlock(pthread_spinlock_t *l);
292 
293 extern int pthread_cond_init(pthread_cond_t *c, pthread_condattr_t *a);
294 
295 extern int pthread_cond_signal(pthread_cond_t *c);
296 
297 extern int pthread_cond_broadcast(pthread_cond_t *c);
298 
299 extern int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m);
300 
301 extern int pthread_cond_destroy(pthread_cond_t *c);
302 
303 extern int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, struct timespec *t);
304 
305 extern 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 
310 extern int pthread_condattr_init(pthread_condattr_t *a);
311 
312 extern int pthread_condattr_getpshared(pthread_condattr_t *a, int *s);
313 
314 extern int pthread_condattr_setpshared(pthread_condattr_t *a, int s);
315 
316 extern int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a);
317 
318 extern int pthread_rwlockattr_init(pthread_rwlockattr_t *a);
319 
320 extern int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *a, int *s);
321 
322 extern 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 */