… | |
… | |
14 | #endif |
14 | #endif |
15 | |
15 | |
16 | ///////////////////////////////////////////////////////////////////////////// |
16 | ///////////////////////////////////////////////////////////////////////////// |
17 | |
17 | |
18 | #ifdef _WIN32 |
18 | #ifdef _WIN32 |
19 | typedef int ssize_t; |
|
|
20 | |
19 | |
21 | #define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls |
20 | //#define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls, fails with mingw |
22 | #define _WIN32_WINNT 0x400 |
21 | #define _WIN32_WINNT 0x400 // maybe working alternative for mingw |
23 | #include <stdio.h>//D |
22 | #include <stdio.h>//D |
24 | #include <fcntl.h> |
23 | #include <fcntl.h> |
25 | #include <io.h> |
24 | #include <io.h> |
26 | #include <time.h> |
25 | #include <time.h> |
27 | #include <winsock2.h> |
26 | #include <winsock2.h> |
28 | #include <process.h> |
27 | #include <process.h> |
29 | #include <windows.h> |
28 | #include <windows.h> |
|
|
29 | |
|
|
30 | /* work around some bugs in ptw32 */ |
|
|
31 | #if defined(__MINGW32__) && defined(_TIMESPEC_DEFINED) |
|
|
32 | #define HAVE_STRUCT_TIMESPEC 1 |
|
|
33 | #endif |
|
|
34 | |
30 | #include <pthread.h> |
35 | #include <pthread.h> |
31 | #define sigset_t int |
36 | #define sigset_t int |
32 | #define sigfillset(a) |
37 | #define sigfillset(a) |
33 | #define pthread_sigmask(a,b,c) |
38 | #define pthread_sigmask(a,b,c) |
34 | #define sigaddset(a,b) |
39 | #define sigaddset(a,b) |
35 | #define sigemptyset(s) |
40 | #define sigemptyset(s) |
36 | #define sigfillset(s) |
|
|
37 | |
41 | |
38 | typedef pthread_mutex_t xmutex_t; |
42 | typedef pthread_mutex_t xmutex_t; |
39 | #define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
43 | #define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
40 | #define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0) |
44 | #define X_MUTEX_CREATE(mutex) pthread_mutex_init (&(mutex), 0) |
41 | #define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) |
45 | #define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) |
… | |
… | |
47 | #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
51 | #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
48 | #define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) |
52 | #define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) |
49 | #define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) |
53 | #define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) |
50 | |
54 | |
51 | typedef pthread_t xthread_t; |
55 | typedef pthread_t xthread_t; |
52 | #define X_THREAD_PROC(name) void *name (void *thr_arg) |
56 | #define X_THREAD_PROC(name) static void *name (void *thr_arg) |
53 | #define X_THREAD_ATFORK(a,b,c) |
57 | #define X_THREAD_ATFORK(a,b,c) |
54 | |
58 | |
55 | static int |
59 | static int |
56 | thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) |
60 | xthread_create (xthread_t *tid, void *(*proc)(void *), void *arg) |
57 | { |
61 | { |
58 | int retval; |
62 | int retval; |
59 | pthread_attr_t attr; |
63 | pthread_attr_t attr; |
60 | |
64 | |
61 | pthread_attr_init (&attr); |
65 | pthread_attr_init (&attr); |
… | |
… | |
128 | #ifndef PTHREAD_STACK_MIN |
132 | #ifndef PTHREAD_STACK_MIN |
129 | # define PTHREAD_STACK_MIN 0 |
133 | # define PTHREAD_STACK_MIN 0 |
130 | #endif |
134 | #endif |
131 | |
135 | |
132 | #ifndef X_STACKSIZE |
136 | #ifndef X_STACKSIZE |
133 | # define X_STACKSIZE sizeof (long) * 4096 |
137 | # define X_STACKSIZE sizeof (void *) * 4096 |
134 | #endif |
138 | #endif |
135 | |
139 | |
136 | static int |
140 | static int |
137 | thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) |
141 | xthread_create (xthread_t *tid, void *(*proc)(void *), void *arg) |
138 | { |
142 | { |
139 | int retval; |
143 | int retval; |
140 | sigset_t fullsigset, oldsigset; |
144 | sigset_t fullsigset, oldsigset; |
141 | pthread_attr_t attr; |
145 | pthread_attr_t attr; |
142 | |
146 | |