… | |
… | |
9 | |
9 | |
10 | #include <pthread.h> |
10 | #include <pthread.h> |
11 | |
11 | |
12 | #include <stddef.h> |
12 | #include <stddef.h> |
13 | #include <errno.h> |
13 | #include <errno.h> |
|
|
14 | #include <sys/time.h> |
|
|
15 | #include <sys/select.h> |
14 | #include <sys/types.h> |
16 | #include <sys/types.h> |
15 | #include <sys/stat.h> |
17 | #include <sys/stat.h> |
16 | #include <limits.h> |
18 | #include <limits.h> |
17 | #include <unistd.h> |
19 | #include <unistd.h> |
18 | #include <fcntl.h> |
20 | #include <fcntl.h> |
… | |
… | |
53 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
55 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
54 | REQ_FSYNC, REQ_FDATASYNC, |
56 | REQ_FSYNC, REQ_FDATASYNC, |
55 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
57 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
56 | REQ_READDIR, |
58 | REQ_READDIR, |
57 | REQ_LINK, REQ_SYMLINK, |
59 | REQ_LINK, REQ_SYMLINK, |
|
|
60 | REQ_SLEEP, |
58 | REQ_GROUP, |
61 | REQ_GROUP, |
59 | }; |
62 | }; |
60 | |
63 | |
61 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
64 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
62 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
65 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
… | |
… | |
99 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
102 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
100 | |
103 | |
101 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
104 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
102 | static volatile aio_req ress, rese; /* queue start, queue end */ |
105 | static volatile aio_req ress, rese; /* queue start, queue end */ |
103 | |
106 | |
|
|
107 | static void req_free (aio_req req); |
|
|
108 | |
104 | /* must be called at most once */ |
109 | /* must be called at most once */ |
105 | static SV *req_sv (aio_req req, const char *klass) |
110 | static SV *req_sv (aio_req req, const char *klass) |
106 | { |
111 | { |
107 | req->self = (SV *)newHV (); |
112 | req->self = (SV *)newHV (); |
108 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
113 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
109 | |
114 | |
110 | return sv_2mortal (sv_bless (newRV_noinc (req->self), gv_stashpv (klass, 1))); |
115 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
111 | } |
116 | } |
112 | |
117 | |
113 | static aio_req SvAIO_REQ (SV *sv, const char *klass) |
118 | static aio_req SvAIO_REQ (SV *sv) |
114 | { |
119 | { |
115 | if (!sv_derived_from (sv, klass) || !SvROK (sv)) |
120 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
116 | croak ("object of class %s expected", klass); |
121 | croak ("object of class " AIO_REQ_KLASS " expected"); |
117 | |
122 | |
118 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
123 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
119 | |
124 | |
120 | return mg ? (aio_req)mg->mg_ptr : 0; |
125 | return mg ? (aio_req)mg->mg_ptr : 0; |
121 | } |
126 | } |
122 | |
127 | |
123 | static void req_free (aio_req req) |
128 | static void poll_wait () |
124 | { |
|
|
125 | if (req->self) |
|
|
126 | { |
|
|
127 | sv_unmagic (req->self, PERL_MAGIC_ext); |
|
|
128 | SvREFCNT_dec (req->self); |
|
|
129 | } |
|
|
130 | |
|
|
131 | if (req->data) |
|
|
132 | SvREFCNT_dec (req->data); |
|
|
133 | |
|
|
134 | if (req->fh) |
|
|
135 | SvREFCNT_dec (req->fh); |
|
|
136 | |
|
|
137 | if (req->fh2) |
|
|
138 | SvREFCNT_dec (req->fh2); |
|
|
139 | |
|
|
140 | if (req->statdata) |
|
|
141 | Safefree (req->statdata); |
|
|
142 | |
|
|
143 | if (req->callback) |
|
|
144 | SvREFCNT_dec (req->callback); |
|
|
145 | |
|
|
146 | if (req->type == REQ_READDIR && req->result >= 0) |
|
|
147 | free (req->data2ptr); |
|
|
148 | |
|
|
149 | Safefree (req); |
|
|
150 | } |
|
|
151 | |
|
|
152 | static void |
|
|
153 | poll_wait () |
|
|
154 | { |
129 | { |
155 | if (nreqs && !ress) |
130 | if (nreqs && !ress) |
156 | { |
131 | { |
157 | fd_set rfd; |
132 | fd_set rfd; |
158 | FD_ZERO(&rfd); |
133 | FD_ZERO(&rfd); |
… | |
… | |
160 | |
135 | |
161 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
136 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
162 | } |
137 | } |
163 | } |
138 | } |
164 | |
139 | |
165 | static int |
140 | static void req_invoke (aio_req req) |
166 | poll_cb () |
141 | { |
|
|
142 | dSP; |
|
|
143 | int errorno = errno; |
|
|
144 | |
|
|
145 | if (req->cancelled || !SvOK (req->callback)) |
|
|
146 | return; |
|
|
147 | |
|
|
148 | errno = req->errorno; |
|
|
149 | |
|
|
150 | ENTER; |
|
|
151 | PUSHMARK (SP); |
|
|
152 | |
|
|
153 | switch (req->type) |
|
|
154 | { |
|
|
155 | case REQ_READDIR: |
|
|
156 | { |
|
|
157 | SV *rv = &PL_sv_undef; |
|
|
158 | |
|
|
159 | if (req->result >= 0) |
|
|
160 | { |
|
|
161 | char *buf = req->data2ptr; |
|
|
162 | AV *av = newAV (); |
|
|
163 | |
|
|
164 | while (req->result) |
|
|
165 | { |
|
|
166 | SV *sv = newSVpv (buf, 0); |
|
|
167 | |
|
|
168 | av_push (av, sv); |
|
|
169 | buf += SvCUR (sv) + 1; |
|
|
170 | req->result--; |
|
|
171 | } |
|
|
172 | |
|
|
173 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
|
|
174 | } |
|
|
175 | |
|
|
176 | XPUSHs (rv); |
|
|
177 | } |
|
|
178 | break; |
|
|
179 | |
|
|
180 | case REQ_OPEN: |
|
|
181 | { |
|
|
182 | /* convert fd to fh */ |
|
|
183 | SV *fh; |
|
|
184 | |
|
|
185 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
186 | PUTBACK; |
|
|
187 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
188 | SPAGAIN; |
|
|
189 | |
|
|
190 | fh = SvREFCNT_inc (POPs); |
|
|
191 | |
|
|
192 | PUSHMARK (SP); |
|
|
193 | XPUSHs (sv_2mortal (fh)); |
|
|
194 | } |
|
|
195 | break; |
|
|
196 | |
|
|
197 | case REQ_SLEEP: |
|
|
198 | case REQ_GROUP: |
|
|
199 | break; |
|
|
200 | |
|
|
201 | default: |
|
|
202 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
203 | break; |
|
|
204 | } |
|
|
205 | |
|
|
206 | |
|
|
207 | PUTBACK; |
|
|
208 | call_sv (req->callback, G_VOID | G_EVAL); |
|
|
209 | SPAGAIN; |
|
|
210 | |
|
|
211 | if (SvTRUE (ERRSV)) |
|
|
212 | { |
|
|
213 | req_free (req); |
|
|
214 | croak (0); |
|
|
215 | } |
|
|
216 | |
|
|
217 | LEAVE; |
|
|
218 | |
|
|
219 | errno = errorno; |
|
|
220 | } |
|
|
221 | |
|
|
222 | static void req_free (aio_req req) |
|
|
223 | { |
|
|
224 | if (req->grp) |
|
|
225 | { |
|
|
226 | aio_req grp = req->grp; |
|
|
227 | |
|
|
228 | /* unlink request */ |
|
|
229 | req->grp_next->grp_prev = req->grp_prev; |
|
|
230 | req->grp_prev->grp_next = req->grp_next; |
|
|
231 | |
|
|
232 | if (grp->grp_next == grp) |
|
|
233 | { |
|
|
234 | req_invoke (grp); |
|
|
235 | req_free (grp); |
|
|
236 | } |
|
|
237 | } |
|
|
238 | |
|
|
239 | if (req->self) |
|
|
240 | { |
|
|
241 | sv_unmagic (req->self, PERL_MAGIC_ext); |
|
|
242 | SvREFCNT_dec (req->self); |
|
|
243 | } |
|
|
244 | |
|
|
245 | if (req->data) |
|
|
246 | SvREFCNT_dec (req->data); |
|
|
247 | |
|
|
248 | if (req->fh) |
|
|
249 | SvREFCNT_dec (req->fh); |
|
|
250 | |
|
|
251 | if (req->fh2) |
|
|
252 | SvREFCNT_dec (req->fh2); |
|
|
253 | |
|
|
254 | if (req->statdata) |
|
|
255 | Safefree (req->statdata); |
|
|
256 | |
|
|
257 | if (req->callback) |
|
|
258 | SvREFCNT_dec (req->callback); |
|
|
259 | |
|
|
260 | if (req->type == REQ_READDIR && req->result >= 0) |
|
|
261 | free (req->data2ptr); |
|
|
262 | |
|
|
263 | Safefree (req); |
|
|
264 | } |
|
|
265 | |
|
|
266 | static void req_cancel (aio_req req) |
|
|
267 | { |
|
|
268 | req->cancelled = 1; |
|
|
269 | |
|
|
270 | if (req->type == REQ_GROUP) |
|
|
271 | { |
|
|
272 | aio_req sub; |
|
|
273 | |
|
|
274 | for (sub = req->grp_next; sub != req; sub = sub->grp_next) |
|
|
275 | req_cancel (sub); |
|
|
276 | } |
|
|
277 | } |
|
|
278 | |
|
|
279 | static int poll_cb () |
167 | { |
280 | { |
168 | dSP; |
281 | dSP; |
169 | int count = 0; |
282 | int count = 0; |
170 | int do_croak = 0; |
283 | int do_croak = 0; |
171 | aio_req req; |
284 | aio_req req; |
… | |
… | |
197 | |
310 | |
198 | nreqs--; |
311 | nreqs--; |
199 | |
312 | |
200 | if (req->type == REQ_QUIT) |
313 | if (req->type == REQ_QUIT) |
201 | started--; |
314 | started--; |
|
|
315 | else if (req->type == REQ_GROUP && req->grp_next != req) |
|
|
316 | continue; |
202 | else |
317 | else |
203 | { |
318 | { |
204 | int errorno = errno; |
|
|
205 | errno = req->errorno; |
|
|
206 | |
|
|
207 | if (req->type == REQ_READ) |
319 | if (req->type == REQ_READ) |
208 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
320 | SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0)); |
209 | |
321 | |
210 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
322 | if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE)) |
211 | SvREADONLY_off (req->data); |
323 | SvREADONLY_off (req->data); |
… | |
… | |
215 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
327 | PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT; |
216 | PL_laststatval = req->result; |
328 | PL_laststatval = req->result; |
217 | PL_statcache = *(req->statdata); |
329 | PL_statcache = *(req->statdata); |
218 | } |
330 | } |
219 | |
331 | |
220 | ENTER; |
332 | req_invoke (req); |
221 | PUSHMARK (SP); |
|
|
222 | |
333 | |
223 | if (req->type == REQ_READDIR) |
|
|
224 | { |
|
|
225 | SV *rv = &PL_sv_undef; |
|
|
226 | |
|
|
227 | if (req->result >= 0) |
|
|
228 | { |
|
|
229 | char *buf = req->data2ptr; |
|
|
230 | AV *av = newAV (); |
|
|
231 | |
|
|
232 | while (req->result) |
|
|
233 | { |
|
|
234 | SV *sv = newSVpv (buf, 0); |
|
|
235 | |
|
|
236 | av_push (av, sv); |
|
|
237 | buf += SvCUR (sv) + 1; |
|
|
238 | req->result--; |
|
|
239 | } |
|
|
240 | |
|
|
241 | rv = sv_2mortal (newRV_noinc ((SV *)av)); |
|
|
242 | } |
|
|
243 | |
|
|
244 | XPUSHs (rv); |
|
|
245 | } |
|
|
246 | else |
|
|
247 | { |
|
|
248 | XPUSHs (sv_2mortal (newSViv (req->result))); |
|
|
249 | |
|
|
250 | if (req->type == REQ_OPEN) |
|
|
251 | { |
|
|
252 | /* convert fd to fh */ |
|
|
253 | SV *fh; |
|
|
254 | |
|
|
255 | PUTBACK; |
|
|
256 | call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); |
|
|
257 | SPAGAIN; |
|
|
258 | |
|
|
259 | fh = SvREFCNT_inc (POPs); |
|
|
260 | |
|
|
261 | PUSHMARK (SP); |
|
|
262 | XPUSHs (sv_2mortal (fh)); |
|
|
263 | } |
|
|
264 | } |
|
|
265 | |
|
|
266 | if (SvOK (req->callback) && !req->cancelled) |
|
|
267 | { |
|
|
268 | PUTBACK; |
|
|
269 | call_sv (req->callback, G_VOID | G_EVAL); |
|
|
270 | SPAGAIN; |
|
|
271 | |
|
|
272 | if (SvTRUE (ERRSV)) |
|
|
273 | { |
|
|
274 | req_free (req); |
|
|
275 | croak (0); |
|
|
276 | } |
|
|
277 | } |
|
|
278 | |
|
|
279 | LEAVE; |
|
|
280 | |
|
|
281 | errno = errorno; |
|
|
282 | count++; |
334 | count++; |
283 | } |
335 | } |
284 | |
336 | |
285 | req_free (req); |
337 | req_free (req); |
286 | } |
338 | } |
… | |
… | |
288 | return count; |
340 | return count; |
289 | } |
341 | } |
290 | |
342 | |
291 | static void *aio_proc(void *arg); |
343 | static void *aio_proc(void *arg); |
292 | |
344 | |
293 | static void |
|
|
294 | start_thread (void) |
345 | static void start_thread (void) |
295 | { |
346 | { |
296 | sigset_t fullsigset, oldsigset; |
347 | sigset_t fullsigset, oldsigset; |
297 | pthread_t tid; |
348 | pthread_t tid; |
298 | pthread_attr_t attr; |
349 | pthread_attr_t attr; |
299 | |
350 | |
… | |
… | |
308 | started++; |
359 | started++; |
309 | |
360 | |
310 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
361 | sigprocmask (SIG_SETMASK, &oldsigset, 0); |
311 | } |
362 | } |
312 | |
363 | |
313 | static void |
|
|
314 | req_send (aio_req req) |
364 | static void req_send (aio_req req) |
315 | { |
365 | { |
316 | while (started < wanted && nreqs >= started) |
366 | while (started < wanted && nreqs >= started) |
317 | start_thread (); |
367 | start_thread (); |
318 | |
368 | |
319 | nreqs++; |
369 | nreqs++; |
… | |
… | |
343 | |
393 | |
344 | poll_wait (); |
394 | poll_wait (); |
345 | } |
395 | } |
346 | } |
396 | } |
347 | |
397 | |
348 | static void |
398 | static void end_thread (void) |
349 | end_thread (void) |
|
|
350 | { |
399 | { |
351 | aio_req req; |
400 | aio_req req; |
352 | Newz (0, req, 1, aio_cb); |
401 | Newz (0, req, 1, aio_cb); |
353 | req->type = REQ_QUIT; |
402 | req->type = REQ_QUIT; |
354 | |
403 | |
… | |
… | |
405 | * normal read/write by using a mutex. slows down execution a lot, |
454 | * normal read/write by using a mutex. slows down execution a lot, |
406 | * but that's your problem, not mine. |
455 | * but that's your problem, not mine. |
407 | */ |
456 | */ |
408 | static pthread_mutex_t preadwritelock = PTHREAD_MUTEX_INITIALIZER; |
457 | static pthread_mutex_t preadwritelock = PTHREAD_MUTEX_INITIALIZER; |
409 | |
458 | |
410 | static ssize_t |
459 | static ssize_t pread (int fd, void *buf, size_t count, off_t offset) |
411 | pread (int fd, void *buf, size_t count, off_t offset) |
|
|
412 | { |
460 | { |
413 | ssize_t res; |
461 | ssize_t res; |
414 | off_t ooffset; |
462 | off_t ooffset; |
415 | |
463 | |
416 | pthread_mutex_lock (&preadwritelock); |
464 | pthread_mutex_lock (&preadwritelock); |
… | |
… | |
421 | pthread_mutex_unlock (&preadwritelock); |
469 | pthread_mutex_unlock (&preadwritelock); |
422 | |
470 | |
423 | return res; |
471 | return res; |
424 | } |
472 | } |
425 | |
473 | |
426 | static ssize_t |
|
|
427 | pwrite (int fd, void *buf, size_t count, off_t offset) |
474 | static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset) |
428 | { |
475 | { |
429 | ssize_t res; |
476 | ssize_t res; |
430 | off_t ooffset; |
477 | off_t ooffset; |
431 | |
478 | |
432 | pthread_mutex_lock (&preadwritelock); |
479 | pthread_mutex_lock (&preadwritelock); |
… | |
… | |
445 | #endif |
492 | #endif |
446 | |
493 | |
447 | #if !HAVE_READAHEAD |
494 | #if !HAVE_READAHEAD |
448 | # define readahead aio_readahead |
495 | # define readahead aio_readahead |
449 | |
496 | |
450 | static ssize_t |
|
|
451 | readahead (int fd, off_t offset, size_t count) |
497 | static ssize_t readahead (int fd, off_t offset, size_t count) |
452 | { |
498 | { |
453 | char readahead_buf[4096]; |
499 | char readahead_buf[4096]; |
454 | |
500 | |
455 | while (count > 0) |
501 | while (count > 0) |
456 | { |
502 | { |
… | |
… | |
468 | #if !HAVE_READDIR_R |
514 | #if !HAVE_READDIR_R |
469 | # define readdir_r aio_readdir_r |
515 | # define readdir_r aio_readdir_r |
470 | |
516 | |
471 | static pthread_mutex_t readdirlock = PTHREAD_MUTEX_INITIALIZER; |
517 | static pthread_mutex_t readdirlock = PTHREAD_MUTEX_INITIALIZER; |
472 | |
518 | |
473 | static int |
|
|
474 | readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) |
519 | static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) |
475 | { |
520 | { |
476 | struct dirent *e; |
521 | struct dirent *e; |
477 | int errorno; |
522 | int errorno; |
478 | |
523 | |
479 | pthread_mutex_lock (&readdirlock); |
524 | pthread_mutex_lock (&readdirlock); |
… | |
… | |
495 | return e ? 0 : -1; |
540 | return e ? 0 : -1; |
496 | } |
541 | } |
497 | #endif |
542 | #endif |
498 | |
543 | |
499 | /* sendfile always needs emulation */ |
544 | /* sendfile always needs emulation */ |
500 | static ssize_t |
|
|
501 | sendfile_ (int ofd, int ifd, off_t offset, size_t count) |
545 | static ssize_t sendfile_ (int ofd, int ifd, off_t offset, size_t count) |
502 | { |
546 | { |
503 | ssize_t res; |
547 | ssize_t res; |
504 | |
548 | |
505 | if (!count) |
549 | if (!count) |
506 | return 0; |
550 | return 0; |
… | |
… | |
588 | |
632 | |
589 | return res; |
633 | return res; |
590 | } |
634 | } |
591 | |
635 | |
592 | /* read a full directory */ |
636 | /* read a full directory */ |
593 | static int |
|
|
594 | scandir_ (const char *path, void **namesp) |
637 | static int scandir_ (const char *path, void **namesp) |
595 | { |
638 | { |
596 | DIR *dirp = opendir (path); |
639 | DIR *dirp = opendir (path); |
597 | union |
640 | union |
598 | { |
641 | { |
599 | struct dirent d; |
642 | struct dirent d; |
… | |
… | |
653 | return res; |
696 | return res; |
654 | } |
697 | } |
655 | |
698 | |
656 | /*****************************************************************************/ |
699 | /*****************************************************************************/ |
657 | |
700 | |
658 | static void * |
|
|
659 | aio_proc (void *thr_arg) |
701 | static void *aio_proc (void *thr_arg) |
660 | { |
702 | { |
661 | aio_req req; |
703 | aio_req req; |
662 | int type; |
704 | int type; |
663 | |
705 | |
664 | do |
706 | do |
… | |
… | |
707 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
749 | case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; |
708 | |
750 | |
709 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
751 | case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; |
710 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
752 | case REQ_FSYNC: req->result = fsync (req->fd); break; |
711 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
753 | case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; |
|
|
754 | |
|
|
755 | case REQ_SLEEP: |
|
|
756 | { |
|
|
757 | struct timeval tv; |
|
|
758 | |
|
|
759 | tv.tv_sec = req->fd; |
|
|
760 | tv.tv_usec = req->fd2; |
|
|
761 | |
|
|
762 | req->result = select (0, 0, 0, 0, &tv); |
|
|
763 | } |
712 | |
764 | |
713 | case REQ_QUIT: |
765 | case REQ_QUIT: |
714 | break; |
766 | break; |
715 | |
767 | |
716 | default: |
768 | default: |
… | |
… | |
1073 | |
1125 | |
1074 | REQ_SEND; |
1126 | REQ_SEND; |
1075 | } |
1127 | } |
1076 | |
1128 | |
1077 | void |
1129 | void |
|
|
1130 | aio_sleep (delay,callback=&PL_sv_undef) |
|
|
1131 | double delay |
|
|
1132 | SV * callback |
|
|
1133 | PPCODE: |
|
|
1134 | { |
|
|
1135 | dREQ; |
|
|
1136 | |
|
|
1137 | req->type = REQ_SLEEP; |
|
|
1138 | req->fd = delay < 0. ? 0 : delay; |
|
|
1139 | req->fd2 = delay < 0. ? 0 : 1000. * (delay - req->fd); |
|
|
1140 | |
|
|
1141 | REQ_SEND; |
|
|
1142 | } |
|
|
1143 | |
|
|
1144 | void |
1078 | aio_group (callback=&PL_sv_undef) |
1145 | aio_group (callback=&PL_sv_undef) |
1079 | SV * callback |
1146 | SV * callback |
1080 | PROTOTYPE: ;& |
1147 | PROTOTYPE: ;& |
1081 | PPCODE: |
1148 | PPCODE: |
1082 | { |
1149 | { |
1083 | dREQ; |
1150 | dREQ; |
1084 | req->type = REQ_GROUP; |
1151 | req->type = REQ_GROUP; |
|
|
1152 | req->grp_next = req; |
|
|
1153 | req->grp_prev = req; |
|
|
1154 | |
|
|
1155 | req_send (req); |
1085 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1156 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1086 | } |
1157 | } |
1087 | |
1158 | |
1088 | void |
1159 | void |
1089 | flush () |
1160 | flush () |
… | |
… | |
1140 | |
1211 | |
1141 | void |
1212 | void |
1142 | cancel (aio_req_ornot req) |
1213 | cancel (aio_req_ornot req) |
1143 | PROTOTYPE: |
1214 | PROTOTYPE: |
1144 | CODE: |
1215 | CODE: |
1145 | req->cancelled = 1; |
1216 | req_cancel (req); |
1146 | |
1217 | |
|
|
1218 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
|
|
1219 | |
|
|
1220 | void |
|
|
1221 | add (aio_req grp, ...) |
|
|
1222 | PROTOTYPE: $;@ |
|
|
1223 | PPCODE: |
|
|
1224 | { |
|
|
1225 | int i; |
|
|
1226 | |
|
|
1227 | for (i = 1; i < items; ++i ) |
|
|
1228 | { |
|
|
1229 | aio_req req = SvAIO_REQ (ST (i)); |
|
|
1230 | |
|
|
1231 | req->grp_prev = grp; |
|
|
1232 | req->grp_next = grp->grp_next; |
|
|
1233 | grp->grp_next->grp_prev = req; |
|
|
1234 | grp->grp_next = req; |
|
|
1235 | |
|
|
1236 | req->grp = grp; |
|
|
1237 | |
|
|
1238 | if (GIMME_V != G_VOID) |
|
|
1239 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
|
|
1240 | } |
|
|
1241 | } |
|
|
1242 | |