1 | /* solaris */ |
|
|
2 | #define _POSIX_PTHREAD_SEMANTICS 1 |
|
|
3 | |
|
|
4 | #if __linux && !defined(_GNU_SOURCE) |
|
|
5 | # define _GNU_SOURCE |
|
|
6 | #endif |
|
|
7 | |
|
|
8 | /* just in case */ |
|
|
9 | #define _REENTRANT 1 |
|
|
10 | |
|
|
11 | #include <signal.h> |
|
|
12 | #include <pthread.h> |
|
|
13 | |
|
|
14 | #ifndef PTHREAD_STACK_MIN |
|
|
15 | /* care for broken platforms, e.g. windows */ |
|
|
16 | # define PTHREAD_STACK_MIN 16384 |
|
|
17 | #endif |
|
|
18 | |
|
|
19 | #if __ia64 |
|
|
20 | # define STACKSIZE 65536 |
|
|
21 | #elif __i386 || __x86_64 /* 16k is unreasonably high :( */ |
|
|
22 | # define STACKSIZE PTHREAD_STACK_MIN |
|
|
23 | #else |
|
|
24 | # define STACKSIZE 16384 |
|
|
25 | #endif |
|
|
26 | |
|
|
27 | /* wether word reads are potentially non-atomic. |
1 | /* wether word reads are potentially non-atomic. |
28 | * this is conservatice, likely most arches this runs |
2 | * this is conservatice, likely most arches this runs |
29 | * on have atomic word read/writes. |
3 | * on have atomic word read/writes. |
30 | */ |
4 | */ |
31 | #ifndef WORDACCESS_UNSAFE |
5 | #ifndef WORDACCESS_UNSAFE |
… | |
… | |
34 | # else |
8 | # else |
35 | # define WORDACCESS_UNSAFE 1 |
9 | # define WORDACCESS_UNSAFE 1 |
36 | # endif |
10 | # endif |
37 | #endif |
11 | #endif |
38 | |
12 | |
|
|
13 | ///////////////////////////////////////////////////////////////////////////// |
|
|
14 | |
|
|
15 | #ifdef _WIN32 |
|
|
16 | typedef int ssize_t; |
|
|
17 | |
|
|
18 | #define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls |
|
|
19 | #define _WIN32_WINNT 0x400 |
|
|
20 | #include <stdio.h>//D |
|
|
21 | #include <fcntl.h> |
|
|
22 | #include <io.h> |
|
|
23 | #include <time.h> |
|
|
24 | #include <winsock2.h> |
|
|
25 | #include <process.h> |
|
|
26 | #include <windows.h> |
|
|
27 | #include <pthread.h> |
|
|
28 | #define sigset_t int |
|
|
29 | #define sigfillset(a) |
|
|
30 | #define pthread_sigmask(a,b,c) |
|
|
31 | #define sigaddset(a,b) |
|
|
32 | #define sigemptyset(s) |
|
|
33 | #define sigfillset(s) |
|
|
34 | |
|
|
35 | typedef pthread_mutex_t mutex_t; |
|
|
36 | #define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
|
|
37 | #define X_MUTEX_CHECK(mutex) |
|
|
38 | #define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) |
|
|
39 | #define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
|
|
40 | |
|
|
41 | typedef pthread_cond_t cond_t; |
|
|
42 | #define X_COND_INIT PTHREAD_COND_INITIALIZER |
|
|
43 | #define X_COND_CHECK(cond) |
|
|
44 | #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
|
|
45 | #define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) |
|
|
46 | #define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) |
|
|
47 | |
|
|
48 | typedef pthread_t thread_t; |
|
|
49 | #define X_THREAD_PROC(name) void *name (void *thr_arg) |
|
|
50 | #define X_THREAD_ATFORK(a,b,c) |
|
|
51 | |
|
|
52 | static int |
|
|
53 | thread_create (thread_t *tid, void *(*proc)(void *), void *arg) |
|
|
54 | { |
|
|
55 | pthread_attr_t attr; |
|
|
56 | |
|
|
57 | pthread_attr_init (&attr); |
|
|
58 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
|
|
59 | |
|
|
60 | return pthread_create (tid, &attr, proc, arg) == 0; |
|
|
61 | } |
|
|
62 | |
|
|
63 | #define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0) |
|
|
64 | #define respipe_write(a,b,c) send ((a), (b), (c), 0) |
|
|
65 | #define respipe_close(a) PerlSock_closesocket ((a)) |
|
|
66 | |
|
|
67 | #else |
|
|
68 | ///////////////////////////////////////////////////////////////////////////// |
|
|
69 | |
|
|
70 | /* solaris */ |
|
|
71 | #define _POSIX_PTHREAD_SEMANTICS 1 |
|
|
72 | |
|
|
73 | #if __linux && !defined(_GNU_SOURCE) |
|
|
74 | # define _GNU_SOURCE |
|
|
75 | #endif |
|
|
76 | |
|
|
77 | /* just in case */ |
|
|
78 | #define _REENTRANT 1 |
|
|
79 | |
|
|
80 | #if __solaris |
|
|
81 | /* try to bribe solaris headers into providing a current pthread API |
|
|
82 | * despite perl being configured for an older version. |
|
|
83 | */ |
|
|
84 | # define __EXTENSIONS__ 1 |
|
|
85 | #endif |
|
|
86 | |
|
|
87 | #include <unistd.h> |
|
|
88 | #include <fcntl.h> |
|
|
89 | #include <signal.h> |
|
|
90 | #include <limits.h> |
|
|
91 | #include <pthread.h> |
|
|
92 | |
39 | typedef pthread_mutex_t mutex_t; |
93 | typedef pthread_mutex_t mutex_t; |
40 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
94 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
41 | # define MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
95 | # define X_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
42 | #else |
96 | #else |
43 | # define MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
97 | # define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
44 | #endif |
98 | #endif |
|
|
99 | #define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) |
|
|
100 | #define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
45 | |
101 | |
46 | typedef pthread_cond_t cond_t; |
102 | typedef pthread_cond_t cond_t; |
47 | #define COND_INIT PTHREAD_COND_INITIALIZER |
103 | #define X_COND_INIT PTHREAD_COND_INITIALIZER |
48 | |
|
|
49 | #define LOCK(mutex) pthread_mutex_lock (&(mutex)) |
|
|
50 | #define UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
|
|
51 | |
|
|
52 | #define COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
104 | #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
53 | #define COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) |
105 | #define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) |
54 | #define COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) |
106 | #define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) |
55 | |
107 | |
56 | typedef pthread_t thread_t; |
108 | typedef pthread_t thread_t; |
|
|
109 | #define X_THREAD_PROC(name) static void *name (void *thr_arg) |
|
|
110 | #define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child) |
57 | |
111 | |
|
|
112 | static int |
58 | static int thread_create (thread_t *tid, void *(*proc)(void *), void *arg) |
113 | thread_create (thread_t *tid, void *(*proc)(void *), void *arg) |
59 | { |
114 | { |
60 | int retval; |
115 | int retval; |
61 | sigset_t fullsigset, oldsigset; |
116 | sigset_t fullsigset, oldsigset; |
62 | pthread_attr_t attr; |
117 | pthread_attr_t attr; |
63 | |
118 | |
64 | pthread_attr_init (&attr); |
119 | pthread_attr_init (&attr); |
65 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
120 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
|
|
121 | pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < sizeof (long) * 4096 |
|
|
122 | ? sizeof (long) * 4096 : PTHREAD_STACK_MIN); |
66 | #ifdef PTHREAD_SCOPE_PROCESS |
123 | #ifdef PTHREAD_SCOPE_PROCESS |
67 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
124 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
68 | #endif |
125 | #endif |
69 | |
126 | |
70 | sigfillset (&fullsigset); |
127 | sigfillset (&fullsigset); |
… | |
… | |
74 | pthread_sigmask (SIG_SETMASK, &oldsigset, 0); |
131 | pthread_sigmask (SIG_SETMASK, &oldsigset, 0); |
75 | |
132 | |
76 | return retval; |
133 | return retval; |
77 | } |
134 | } |
78 | |
135 | |
79 | #define ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child) |
136 | #define respipe_read(a,b,c) read ((a), (b), (c)) |
|
|
137 | #define respipe_write(a,b,c) write ((a), (b), (c)) |
|
|
138 | #define respipe_close(a) close ((a)) |
80 | |
139 | |
|
|
140 | #endif |
|
|
141 | |
|
|
142 | |
|
|
143 | |