… | |
… | |
35 | #define sigemptyset(s) |
35 | #define sigemptyset(s) |
36 | #define sigfillset(s) |
36 | #define sigfillset(s) |
37 | |
37 | |
38 | typedef pthread_mutex_t mutex_t; |
38 | typedef pthread_mutex_t mutex_t; |
39 | #define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
39 | #define X_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
40 | #define X_MUTEX_CHECK(mutex) |
|
|
41 | #define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) |
40 | #define X_LOCK(mutex) pthread_mutex_lock (&(mutex)) |
42 | #define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
41 | #define X_UNLOCK(mutex) pthread_mutex_unlock (&(mutex)) |
43 | |
42 | |
44 | typedef pthread_cond_t cond_t; |
43 | typedef pthread_cond_t cond_t; |
45 | #define X_COND_INIT PTHREAD_COND_INITIALIZER |
44 | #define X_COND_INIT PTHREAD_COND_INITIALIZER |
46 | #define X_COND_CHECK(cond) |
|
|
47 | #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
45 | #define X_COND_SIGNAL(cond) pthread_cond_signal (&(cond)) |
48 | #define X_COND_WAIT(cond,mutex) pthread_cond_wait (&(cond), &(mutex)) |
46 | #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)) |
47 | #define X_COND_TIMEDWAIT(cond,mutex,to) pthread_cond_timedwait (&(cond), &(mutex), &(to)) |
50 | |
48 | |
51 | typedef pthread_t thread_t; |
49 | typedef pthread_t thread_t; |
… | |
… | |
53 | #define X_THREAD_ATFORK(a,b,c) |
51 | #define X_THREAD_ATFORK(a,b,c) |
54 | |
52 | |
55 | static int |
53 | static int |
56 | thread_create (thread_t *tid, void *(*proc)(void *), void *arg) |
54 | thread_create (thread_t *tid, void *(*proc)(void *), void *arg) |
57 | { |
55 | { |
|
|
56 | int retval; |
58 | pthread_attr_t attr; |
57 | pthread_attr_t attr; |
59 | |
58 | |
60 | pthread_attr_init (&attr); |
59 | pthread_attr_init (&attr); |
61 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
60 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
62 | |
61 | |
63 | return pthread_create (tid, &attr, proc, arg) == 0; |
62 | retval = pthread_create (tid, &attr, proc, arg) == 0; |
|
|
63 | |
|
|
64 | pthread_attr_destroy (&attr); |
|
|
65 | |
|
|
66 | return retval; |
64 | } |
67 | } |
65 | |
68 | |
66 | #define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0) |
69 | #define respipe_read(a,b,c) PerlSock_recv ((a), (b), (c), 0) |
67 | #define respipe_write(a,b,c) send ((a), (b), (c), 0) |
70 | #define respipe_write(a,b,c) send ((a), (b), (c), 0) |
68 | #define respipe_close(a) PerlSock_closesocket ((a)) |
71 | #define respipe_close(a) PerlSock_closesocket ((a)) |
… | |
… | |
108 | |
111 | |
109 | typedef pthread_t thread_t; |
112 | typedef pthread_t thread_t; |
110 | #define X_THREAD_PROC(name) static void *name (void *thr_arg) |
113 | #define X_THREAD_PROC(name) static void *name (void *thr_arg) |
111 | #define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child) |
114 | #define X_THREAD_ATFORK(prepare,parent,child) pthread_atfork (prepare, parent, child) |
112 | |
115 | |
|
|
116 | // the broken bsd's once more |
|
|
117 | #ifndef PTHREAD_STACK_MIN |
|
|
118 | # define PTHREAD_STACK_MIN 0 |
|
|
119 | #endif |
|
|
120 | |
|
|
121 | #ifndef XTHREAD_STACKSIZE |
|
|
122 | # define XTHREAD_STACKSIZE sizeof (long) * 4096 |
|
|
123 | #endif |
|
|
124 | |
113 | static int |
125 | static int |
114 | thread_create (thread_t *tid, void *(*proc)(void *), void *arg) |
126 | thread_create (thread_t *tid, void *(*proc)(void *), void *arg) |
115 | { |
127 | { |
116 | int retval; |
128 | int retval; |
117 | sigset_t fullsigset, oldsigset; |
129 | sigset_t fullsigset, oldsigset; |
118 | pthread_attr_t attr; |
130 | pthread_attr_t attr; |
119 | |
131 | |
120 | pthread_attr_init (&attr); |
132 | pthread_attr_init (&attr); |
121 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
133 | pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); |
122 | pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN < sizeof (long) * 4096 |
134 | |
123 | ? sizeof (long) * 4096 : PTHREAD_STACK_MIN); |
135 | if (XTHREAD_STACKSIZE > 0) |
|
|
136 | pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN > (XTHREAD_STACKSIZE) |
|
|
137 | ? PTHREAD_STACK_MIN : (XTHREAD_STACKSIZE)); |
|
|
138 | |
124 | #ifdef PTHREAD_SCOPE_PROCESS |
139 | #ifdef PTHREAD_SCOPE_PROCESS |
125 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
140 | pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS); |
126 | #endif |
141 | #endif |
127 | |
142 | |
128 | sigfillset (&fullsigset); |
143 | sigfillset (&fullsigset); |
129 | |
144 | |
130 | pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset); |
145 | pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset); |
131 | retval = pthread_create (tid, &attr, proc, arg) == 0; |
146 | retval = pthread_create (tid, &attr, proc, arg) == 0; |
132 | pthread_sigmask (SIG_SETMASK, &oldsigset, 0); |
147 | pthread_sigmask (SIG_SETMASK, &oldsigset, 0); |
|
|
148 | |
|
|
149 | pthread_attr_destroy (&attr); |
133 | |
150 | |
134 | return retval; |
151 | return retval; |
135 | } |
152 | } |
136 | |
153 | |
137 | #define respipe_read(a,b,c) read ((a), (b), (c)) |
154 | #define respipe_read(a,b,c) read ((a), (b), (c)) |