… | |
… | |
86 | static int |
86 | static int |
87 | poll_cb () |
87 | poll_cb () |
88 | { |
88 | { |
89 | dSP; |
89 | dSP; |
90 | int count = 0; |
90 | int count = 0; |
|
|
91 | int do_croak = 0; |
91 | aio_req req, prv; |
92 | aio_req req, prv; |
92 | |
93 | |
93 | pthread_mutex_lock (&reslock); |
94 | pthread_mutex_lock (&reslock); |
94 | |
95 | |
95 | { |
96 | { |
… | |
… | |
158 | PUTBACK; |
159 | PUTBACK; |
159 | call_sv (req->callback, G_VOID | G_EVAL); |
160 | call_sv (req->callback, G_VOID | G_EVAL); |
160 | SPAGAIN; |
161 | SPAGAIN; |
161 | } |
162 | } |
162 | |
163 | |
|
|
164 | do_croak = SvTRUE (ERRSV); |
|
|
165 | |
163 | LEAVE; |
166 | LEAVE; |
164 | |
167 | |
165 | if (req->callback) |
168 | if (req->callback) |
166 | SvREFCNT_dec (req->callback); |
169 | SvREFCNT_dec (req->callback); |
167 | |
170 | |
… | |
… | |
171 | |
174 | |
172 | prv = req; |
175 | prv = req; |
173 | req = req->next; |
176 | req = req->next; |
174 | Safefree (prv); |
177 | Safefree (prv); |
175 | |
178 | |
176 | /* TODO: croak on errors? */ |
179 | if (do_croak) |
|
|
180 | croak (0); |
177 | } |
181 | } |
178 | |
182 | |
179 | return count; |
183 | return count; |
180 | } |
184 | } |
181 | |
185 | |
… | |
… | |
263 | |
267 | |
264 | static int fork_started; |
268 | static int fork_started; |
265 | |
269 | |
266 | static void atfork_prepare (void) |
270 | static void atfork_prepare (void) |
267 | { |
271 | { |
268 | pthread_mutex_lock (&frklock); |
272 | int nstarted; |
269 | |
|
|
270 | fork_started = started; |
|
|
271 | |
273 | |
272 | for (;;) { |
274 | for (;;) { |
273 | while (nreqs) |
275 | while (nreqs) |
274 | { |
276 | { |
275 | poll_wait (); |
277 | poll_wait (); |
276 | poll_cb (); |
278 | poll_cb (); |
277 | } |
279 | } |
278 | |
280 | |
|
|
281 | nstarted = started; |
279 | max_parallel (0); |
282 | max_parallel (0); |
280 | |
283 | |
281 | pthread_mutex_lock (&reqlock); |
284 | pthread_mutex_lock (&reqlock); |
282 | |
285 | |
283 | if (!nreqs && !started) |
286 | if (!nreqs && !started) |
… | |
… | |
286 | pthread_mutex_unlock (&reqlock); |
289 | pthread_mutex_unlock (&reqlock); |
287 | |
290 | |
288 | min_parallel (fork_started); |
291 | min_parallel (fork_started); |
289 | } |
292 | } |
290 | |
293 | |
|
|
294 | pthread_mutex_lock (&frklock); |
|
|
295 | fork_started = nstarted; |
291 | pthread_mutex_lock (&reslock); |
296 | pthread_mutex_lock (&reslock); |
292 | |
297 | |
293 | assert (!started); |
298 | assert (!started); |
294 | assert (!nreqs); |
299 | assert (!nreqs); |
295 | assert (!reqs && !reqe); |
300 | assert (!reqs && !reqe); |
… | |
… | |
297 | } |
302 | } |
298 | |
303 | |
299 | static void atfork_parent (void) |
304 | static void atfork_parent (void) |
300 | { |
305 | { |
301 | pthread_mutex_unlock (&reslock); |
306 | pthread_mutex_unlock (&reslock); |
|
|
307 | pthread_mutex_unlock (&frklock); |
|
|
308 | pthread_mutex_unlock (&reqlock); |
|
|
309 | |
302 | min_parallel (fork_started); |
310 | min_parallel (fork_started); |
303 | pthread_mutex_unlock (&reqlock); |
|
|
304 | pthread_mutex_unlock (&frklock); |
|
|
305 | } |
311 | } |
306 | |
312 | |
307 | static void atfork_child (void) |
313 | #define atfork_child atfork_parent |
308 | { |
|
|
309 | reqs = reqe = 0; |
|
|
310 | |
|
|
311 | atfork_parent (); |
|
|
312 | } |
|
|
313 | |
314 | |
314 | /*****************************************************************************/ |
315 | /*****************************************************************************/ |
315 | /* work around various missing functions */ |
316 | /* work around various missing functions */ |
316 | |
317 | |
317 | #if !HAVE_PREADWRITE |
318 | #if !HAVE_PREADWRITE |