ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.27 by root, Wed Aug 17 04:47:02 2005 UTC vs.
Revision 1.117 by root, Sat May 10 20:02:09 2008 UTC

1#define _REENTRANT 1 1#include "libeio/xthread.h"
2
2#include <errno.h> 3#include <errno.h>
3 4
4#include "EXTERN.h" 5#include "EXTERN.h"
5#include "perl.h" 6#include "perl.h"
6#include "XSUB.h" 7#include "XSUB.h"
7 8
8#include "autoconf/config.h" 9#include <stddef.h>
9 10#include <stdlib.h>
11#include <errno.h>
10#include <sys/types.h> 12#include <sys/types.h>
11#include <sys/stat.h> 13#include <sys/stat.h>
12
13#include <unistd.h> 14#include <limits.h>
14#include <fcntl.h> 15#include <fcntl.h>
15#include <signal.h>
16#include <sched.h> 16#include <sched.h>
17 17
18#include <pthread.h> 18#ifdef _WIN32
19 19
20typedef void *InputStream; /* hack, but 5.6.1 is simply toooo old ;) */ 20# define EIO_STRUCT_DIRENT Direntry_t
21typedef void *OutputStream; /* hack, but 5.6.1 is simply toooo old ;) */ 21# undef malloc
22typedef void *InOutStream; /* hack, but 5.6.1 is simply toooo old ;) */ 22# undef free
23 23
24#if __ia64 24// perl overrides all those nice win32 functions
25# define STACKSIZE 65536 25# undef open
26# undef read
27# undef write
28# undef send
29# undef recv
30# undef stat
31# undef fstat
32# define lstat stat
33# undef truncate
34# undef ftruncate
35# undef open
36# undef close
37# undef unlink
38# undef rmdir
39# undef rename
40# undef lseek
41
42# define chown(a,b,c) (errno = ENOSYS, -1)
43# define fchown(a,b,c) (errno = ENOSYS, -1)
44# define fchmod(a,b) (errno = ENOSYS, -1)
45# define symlink(a,b) (errno = ENOSYS, -1)
46# define readlink(a,b,c) (errno = ENOSYS, -1)
47# define mknod(a,b,c) (errno = ENOSYS, -1)
48# define truncate(a,b) (errno = ENOSYS, -1)
49# define ftruncate(fd,o) chsize ((fd), (o))
50# define fsync(fd) _commit (fd)
51# define opendir(fd) (errno = ENOSYS, 0)
52# define readdir(fd) (errno = ENOSYS, -1)
53# define closedir(fd) (errno = ENOSYS, -1)
54# define mkdir(a,b) mkdir (a)
55
26#else 56#else
27# define STACKSIZE 4096 57
58# include <sys/time.h>
59# include <sys/select.h>
60# include <unistd.h>
61# include <utime.h>
62# include <signal.h>
63# define EIO_STRUCT_DIRENT struct dirent
64
28#endif 65#endif
29 66
67#define EIO_STRUCT_STAT Stat_t
68
69/* use NV for 32 bit perls as it allows larger offsets */
70#if IVSIZE >= 8
71# define SvVAL64 SvIV
72#else
73# define SvVAL64 SvNV
74#endif
75
76static HV *stash;
77typedef SV SV8; /* byte-sv, used for argument-checking */
78
79#define AIO_REQ_KLASS "IO::AIO::REQ"
80#define AIO_GRP_KLASS "IO::AIO::GRP"
81
82#define EIO_COMMON \
83 SV *callback; \
84 SV *sv1, *sv2; \
85 STRLEN stroffset; \
86 SV *self
87
88#include "libeio/eio.h"
89
90static int req_invoke (eio_req *req);
91#define EIO_FINISH(req) req_invoke (req)
92static void aio_grp_feed (eio_req *grp);
93#define EIO_FEED(req) aio_grp_feed (req)
94static void req_destroy (eio_req *grp);
95#define EIO_DESTROY(req) req_destroy (req)
96
30enum { 97enum {
31 REQ_QUIT, 98 FLAG_SV2_RO_OFF = 0x40, /* data was set readonly */
32 REQ_OPEN, REQ_CLOSE,
33 REQ_READ, REQ_WRITE, REQ_READAHEAD,
34 REQ_STAT, REQ_LSTAT, REQ_FSTAT,
35 REQ_FSYNC, REQ_FDATASYNC,
36 REQ_UNLINK, REQ_RMDIR,
37 REQ_SYMLINK,
38}; 99};
39 100
40typedef struct aio_cb { 101#include "libeio/eio.c"
41 struct aio_cb *volatile next;
42 102
43 int type;
44
45 int fd;
46 off_t offset;
47 size_t length;
48 ssize_t result;
49 mode_t mode; /* open */
50 int errorno;
51 SV *data, *callback, *fh;
52 void *dataptr, *data2ptr;
53 STRLEN dataoffset;
54
55 Stat_t *statdata;
56} aio_cb;
57
58typedef aio_cb *aio_req; 103typedef eio_req *aio_req;
104typedef eio_req *aio_req_ornot;
59 105
60static int started; 106static SV *on_next_submit;
61static volatile int nreqs; 107static int next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS;
62static int max_outstanding = 1<<30; 108static int max_outstanding;
63static int respipe [2];
64 109
65static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; 110static int respipe_osf [2], respipe [2] = { -1, -1 };
66static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER;
67static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER;
68 111
69static volatile aio_req reqs, reqe; /* queue start, queue end */ 112static void req_destroy (aio_req req);
70static volatile aio_req ress, rese; /* queue start, queue end */
71
72static void free_req (aio_req req) 113static void req_cancel (aio_req req);
73{
74 if (req->data)
75 SvREFCNT_dec (req->data);
76 114
115static void want_poll (void)
116{
117 /* write a dummy byte to the pipe so fh becomes ready */
118 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
119}
120
121static void done_poll (void)
122{
123 /* read any signals sent by the worker threads */
124 char buf [4];
125 while (respipe_read (respipe [0], buf, 4) == 4)
126 ;
127}
128
129/* must be called at most once */
130static SV *req_sv (aio_req req, const char *klass)
131{
77 if (req->fh) 132 if (!req->self)
78 SvREFCNT_dec (req->fh);
79
80 if (req->statdata)
81 Safefree (req->statdata);
82
83 if (req->callback)
84 SvREFCNT_dec (req->callback);
85
86 Safefree (req);
87}
88
89static void
90poll_wait ()
91{
92 if (nreqs && !ress)
93 { 133 {
94 fd_set rfd; 134 req->self = (SV *)newHV ();
95 FD_ZERO(&rfd); 135 sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0);
96 FD_SET(respipe [0], &rfd);
97
98 select (respipe [0] + 1, &rfd, 0, 0, 0);
99 } 136 }
100}
101 137
102static int 138 return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1)));
103poll_cb () 139}
140
141static aio_req SvAIO_REQ (SV *sv)
142{
143 MAGIC *mg;
144
145 if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv))
146 croak ("object of class " AIO_REQ_KLASS " expected");
147
148 mg = mg_find (SvRV (sv), PERL_MAGIC_ext);
149
150 return mg ? (aio_req)mg->mg_ptr : 0;
151}
152
153static void aio_grp_feed (aio_req grp)
154{
155 if (grp->sv2 && SvOK (grp->sv2))
156 {
157 dSP;
158
159 ENTER;
160 SAVETMPS;
161 PUSHMARK (SP);
162 XPUSHs (req_sv (grp, AIO_GRP_KLASS));
163 PUTBACK;
164 call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR);
165 SPAGAIN;
166 FREETMPS;
167 LEAVE;
168 }
169}
170
171static void req_submit (eio_req *req)
172{
173 eio_submit (req);
174
175 if (on_next_submit)
176 {
177 dSP;
178 SV *cb = sv_2mortal (on_next_submit);
179
180 on_next_submit = 0;
181
182 PUSHMARK (SP);
183 PUTBACK;
184 call_sv (cb, G_DISCARD | G_EVAL);
185 }
186}
187
188static int req_invoke (eio_req *req)
104{ 189{
105 dSP; 190 dSP;
106 int count = 0;
107 int do_croak = 0;
108 aio_req req;
109 191
110 for (;;) 192 if (req->flags & FLAG_SV2_RO_OFF)
193 SvREADONLY_off (req->sv2);
194
195 if (!EIO_CANCELLED (req) && SvOK (req->callback))
111 { 196 {
112 pthread_mutex_lock (&reslock); 197 ENTER;
113 req = ress; 198 SAVETMPS;
199 PUSHMARK (SP);
200 EXTEND (SP, 1);
114 201
115 if (req) 202 switch (req->type)
116 { 203 {
117 ress = req->next; 204 case EIO_READDIR:
118
119 if (!ress)
120 { 205 {
121 rese = 0; 206 SV *rv = &PL_sv_undef;
122 207
123 /* read any signals sent by the worker threads */ 208 if (req->result >= 0)
124 char buf [32];
125 while (read (respipe [0], buf, 32) == 32)
126 ; 209 {
210 int i;
211 char *buf = req->ptr2;
212 AV *av = newAV ();
213
214 av_extend (av, req->result - 1);
215
216 for (i = 0; i < req->result; ++i)
217 {
218 SV *sv = newSVpv (buf, 0);
219
220 av_store (av, i, sv);
221 buf += SvCUR (sv) + 1;
222 }
223
224 rv = sv_2mortal (newRV_noinc ((SV *)av));
225 }
226
227 PUSHs (rv);
127 } 228 }
128 }
129
130 pthread_mutex_unlock (&reslock);
131
132 if (!req)
133 break; 229 break;
134 230
135 nreqs--; 231 case EIO_OPEN:
136
137 if (req->type == REQ_QUIT)
138 started--;
139 else
140 {
141 int errorno = errno;
142 errno = req->errorno;
143
144 if (req->type == REQ_READ)
145 SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0));
146
147 if (req->statdata)
148 {
149 PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT;
150 PL_laststatval = req->result;
151 PL_statcache = *(req->statdata);
152 }
153
154 ENTER;
155 PUSHMARK (SP);
156 XPUSHs (sv_2mortal (newSViv (req->result)));
157
158 if (req->type == REQ_OPEN)
159 { 232 {
160 /* convert fd to fh */ 233 /* convert fd to fh */
161 SV *fh; 234 SV *fh = &PL_sv_undef;
162 235
163 PUTBACK; 236 if (req->result >= 0)
164 call_pv ("IO::AIO::_fd2fh", G_SCALAR | G_EVAL); 237 {
165 SPAGAIN; 238 GV *gv = (GV *)sv_newmortal ();
239 int flags = req->int1 & (O_RDONLY | O_WRONLY | O_RDWR);
240 char sym [64];
241 int symlen;
242
243 symlen = snprintf (sym, sizeof (sym), "fd#%d", req->result);
244 gv_init (gv, stash, sym, symlen, 0);
166 245
167 fh = SvREFCNT_inc (POPs); 246 symlen = snprintf (
247 sym,
248 sizeof (sym),
249 "%s&=%d",
250 flags == O_RDONLY ? "<" : flags == O_WRONLY ? ">" : "+<",
251 req->result
252 );
168 253
254 if (do_open (gv, sym, symlen, 0, 0, 0, 0))
255 fh = (SV *)gv;
256 }
257
169 PUSHMARK (SP); 258 PUSHs (fh);
170 XPUSHs (sv_2mortal (fh));
171 } 259 }
172
173 if (SvOK (req->callback))
174 {
175 PUTBACK;
176 call_sv (req->callback, G_VOID | G_EVAL);
177 SPAGAIN;
178
179 if (SvTRUE (ERRSV))
180 {
181 free_req (req);
182 croak (0);
183 }
184 }
185
186 LEAVE;
187
188 errno = errorno;
189 count++;
190 }
191
192 free_req (req);
193 }
194
195 return count;
196}
197
198static void *aio_proc(void *arg);
199
200static void
201start_thread (void)
202{
203 sigset_t fullsigset, oldsigset;
204 pthread_t tid;
205 pthread_attr_t attr;
206
207 pthread_attr_init (&attr);
208 pthread_attr_setstacksize (&attr, STACKSIZE);
209 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
210
211 sigfillset (&fullsigset);
212 sigprocmask (SIG_SETMASK, &fullsigset, &oldsigset);
213
214 if (pthread_create (&tid, &attr, aio_proc, 0) == 0)
215 started++;
216
217 sigprocmask (SIG_SETMASK, &oldsigset, 0);
218}
219
220static void
221send_req (aio_req req)
222{
223 nreqs++;
224
225 pthread_mutex_lock (&reqlock);
226
227 req->next = 0;
228
229 if (reqe)
230 {
231 reqe->next = req;
232 reqe = req;
233 }
234 else
235 reqe = reqs = req;
236
237 pthread_cond_signal (&reqwait);
238 pthread_mutex_unlock (&reqlock);
239
240 if (nreqs > max_outstanding)
241 for (;;)
242 {
243 poll_cb ();
244
245 if (nreqs <= max_outstanding)
246 break;
247
248 poll_wait ();
249 }
250}
251
252static void
253end_thread (void)
254{
255 aio_req req;
256 Newz (0, req, 1, aio_cb);
257 req->type = REQ_QUIT;
258
259 send_req (req);
260}
261
262static void min_parallel (int nthreads)
263{
264 while (nthreads > started)
265 start_thread ();
266}
267
268static void max_parallel (int nthreads)
269{
270 int cur = started;
271
272 while (cur > nthreads)
273 {
274 end_thread ();
275 cur--;
276 }
277
278 while (started > nthreads)
279 {
280 poll_wait ();
281 poll_cb ();
282 }
283}
284
285static void create_pipe ()
286{
287 if (pipe (respipe))
288 croak ("unable to initialize result pipe");
289
290 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK))
291 croak ("cannot set result pipe to nonblocking mode");
292
293 if (fcntl (respipe [1], F_SETFL, O_NONBLOCK))
294 croak ("cannot set result pipe to nonblocking mode");
295}
296
297static void atfork_prepare (void)
298{
299 for (;;) {
300
301 for (;;)
302 {
303 poll_cb ();
304
305 if (!nreqs)
306 break;
307
308 poll_wait ();
309 }
310
311 pthread_mutex_lock (&reqlock);
312
313 if (!nreqs)
314 break;
315
316 pthread_mutex_unlock (&reqlock);
317 }
318
319 pthread_mutex_lock (&reslock);
320
321 assert (!nreqs && !reqs && !ress);
322}
323
324static void atfork_parent (void)
325{
326 pthread_mutex_unlock (&reslock);
327 pthread_mutex_unlock (&reqlock);
328}
329
330static void atfork_child (void)
331{
332 int restart = started;
333 started = 0;
334
335 atfork_parent ();
336
337 min_parallel (restart);
338}
339
340/*****************************************************************************/
341/* work around various missing functions */
342
343#if !HAVE_PREADWRITE
344# define pread aio_pread
345# define pwrite aio_pwrite
346
347/*
348 * make our pread/pwrite safe against themselves, but not against
349 * normal read/write by using a mutex. slows down execution a lot,
350 * but that's your problem, not mine.
351 */
352static pthread_mutex_t iolock = PTHREAD_MUTEX_INITIALIZER;
353
354static ssize_t
355pread (int fd, void *buf, size_t count, off_t offset)
356{
357 ssize_t res;
358 off_t ooffset;
359
360 pthread_mutex_lock (&iolock);
361 ooffset = lseek (fd, 0, SEEK_CUR);
362 lseek (fd, offset, SEEK_SET);
363 res = read (fd, buf, count);
364 lseek (fd, ooffset, SEEK_SET);
365 pthread_mutex_unlock (&iolock);
366
367 return res;
368}
369
370static ssize_t
371pwrite (int fd, void *buf, size_t count, off_t offset)
372{
373 ssize_t res;
374 off_t ooffset;
375
376 pthread_mutex_lock (&iolock);
377 ooffset = lseek (fd, 0, SEEK_CUR);
378 lseek (fd, offset, SEEK_SET);
379 res = write (fd, buf, count);
380 lseek (fd, offset, SEEK_SET);
381 pthread_mutex_unlock (&iolock);
382
383 return res;
384}
385#endif
386
387#if !HAVE_FDATASYNC
388# define fdatasync fsync
389#endif
390
391#if !HAVE_READAHEAD
392# define readahead aio_readahead
393
394static char readahead_buf[4096];
395
396static ssize_t
397readahead (int fd, off_t offset, size_t count)
398{
399 while (count > 0)
400 {
401 size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf);
402
403 pread (fd, readahead_buf, len, offset);
404 offset += len;
405 count -= len;
406 }
407
408 errno = 0;
409}
410#endif
411
412/*****************************************************************************/
413
414static void *
415aio_proc (void *thr_arg)
416{
417 aio_req req;
418 int type;
419
420 do
421 {
422 pthread_mutex_lock (&reqlock);
423
424 for (;;)
425 {
426 req = reqs;
427
428 if (reqs)
429 {
430 reqs = reqs->next;
431 if (!reqs) reqe = 0;
432 }
433
434 if (req)
435 break; 260 break;
436 261
437 pthread_cond_wait (&reqwait, &reqlock); 262 case EIO_GROUP:
438 } 263 req->int1 = 2; /* mark group as finished */
439 264
440 pthread_mutex_unlock (&reqlock); 265 if (req->sv1)
441
442 errno = 0; /* strictly unnecessary */
443
444 type = req->type;
445
446 switch (type)
447 { 266 {
448 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; 267 int i;
449 case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; 268 AV *av = (AV *)req->sv1;
450 269
451 case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; 270 EXTEND (SP, AvFILL (av) + 1);
452 271 for (i = 0; i <= AvFILL (av); ++i)
453 case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; 272 PUSHs (*av_fetch (av, i, 0));
454 case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; 273 }
455 case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break;
456
457 case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break;
458 case REQ_CLOSE: req->result = close (req->fd); break;
459 case REQ_UNLINK: req->result = unlink (req->dataptr); break;
460 case REQ_RMDIR: req->result = rmdir (req->dataptr); break;
461 case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break;
462
463 case REQ_FDATASYNC: req->result = fdatasync (req->fd); break;
464 case REQ_FSYNC: req->result = fsync (req->fd); break;
465
466 case REQ_QUIT:
467 break; 274 break;
468 275
276 case EIO_NOP:
277 case EIO_BUSY:
278 break;
279
280 case EIO_READLINK:
281 if (req->result > 0)
282 {
283 SvCUR_set (req->sv2, req->result);
284 *SvEND (req->sv2) = 0;
285 PUSHs (req->sv2);
286 }
287 break;
288
289 case EIO_STAT:
290 case EIO_LSTAT:
291 case EIO_FSTAT:
292 PL_laststype = req->type == EIO_LSTAT ? OP_LSTAT : OP_STAT;
293 PL_laststatval = req->result;
294 PL_statcache = *(EIO_STRUCT_STAT *)(req->ptr2);
295 PUSHs (sv_2mortal (newSViv (req->result)));
296 break;
297
298 case EIO_READ:
299 SvCUR_set (req->sv2, req->stroffset + (req->result > 0 ? req->result : 0));
300 *SvEND (req->sv2) = 0;
301 PUSHs (sv_2mortal (newSViv (req->result)));
302 break;
303
304 case EIO_DUP2:
305 if (req->result > 0)
306 req->result = 0;
307 /* FALLTHROUGH */
308
469 default: 309 default:
470 req->result = ENOSYS; 310 PUSHs (sv_2mortal (newSViv (req->result)));
471 break; 311 break;
472 } 312 }
473 313
474 req->errorno = errno; 314 errno = req->errorno;
475 315
476 pthread_mutex_lock (&reslock); 316 PUTBACK;
317 call_sv (req->callback, G_VOID | G_EVAL | G_DISCARD);
318 SPAGAIN;
477 319
478 req->next = 0; 320 FREETMPS;
321 LEAVE;
479 322
480 if (rese) 323 PUTBACK;
481 {
482 rese->next = req;
483 rese = req;
484 }
485 else
486 {
487 rese = ress = req;
488
489 /* write a dummy byte to the pipe so fh becomes ready */
490 write (respipe [1], &respipe, 1);
491 }
492
493 pthread_mutex_unlock (&reslock);
494 } 324 }
495 while (type != REQ_QUIT);
496 325
326 return !!SvTRUE (ERRSV);
327}
328
329static void req_destroy (aio_req req)
330{
331 if (req->self)
332 {
333 sv_unmagic (req->self, PERL_MAGIC_ext);
334 SvREFCNT_dec (req->self);
335 }
336
337 SvREFCNT_dec (req->sv1);
338 SvREFCNT_dec (req->sv2);
339 SvREFCNT_dec (req->callback);
340
341 Safefree (req);
342}
343
344static void req_cancel_subs (aio_req grp)
345{
346 aio_req sub;
347
348 if (grp->type != EIO_GROUP)
349 return;
350
351 SvREFCNT_dec (grp->sv2);
352 grp->sv2 = 0;
353
354 eio_grp_cancel (grp);
355}
356
357#ifdef USE_SOCKETS_AS_HANDLES
358# define TO_SOCKET(x) (win32_get_osfhandle (x))
359#else
360# define TO_SOCKET(x) (x)
361#endif
362
363static void
364create_respipe (void)
365{
366 int old_readfd = respipe [0];
367
368 if (respipe [1] >= 0)
369 respipe_close (TO_SOCKET (respipe [1]));
370
371#ifdef _WIN32
372 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
373#else
374 if (pipe (respipe))
375#endif
376 croak ("unable to initialize result pipe");
377
378 if (old_readfd >= 0)
379 {
380 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
381 croak ("unable to initialize result pipe(2)");
382
383 respipe_close (respipe [0]);
384 respipe [0] = old_readfd;
385 }
386
387#ifdef _WIN32
388 int arg = 1;
389 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
390 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
391#else
392 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
393 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
394#endif
395 croak ("unable to initialize result pipe(3)");
396
397 respipe_osf [0] = TO_SOCKET (respipe [0]);
398 respipe_osf [1] = TO_SOCKET (respipe [1]);
399}
400
401static void poll_wait (void)
402{
403 fd_set rfd;
404
405 while (eio_nreqs ())
406 {
407 int size;
408
409 X_LOCK (reslock);
410 size = res_queue.size;
411 X_UNLOCK (reslock);
412
413 if (size)
414 return;
415
416 maybe_start_thread ();
417
418 FD_ZERO (&rfd);
419 FD_SET (respipe [0], &rfd);
420
421 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
422 }
423}
424
425static int poll_cb (void)
426{
427 int res;
428
429 do
430 {
431 res = eio_poll ();
432
433 if (res > 0)
434 croak (0);
435 }
436 while (max_outstanding && max_outstanding <= eio_nreqs ());
437
497 return 0; 438 return res;
439}
440
441static void atfork_child (void)
442{
443 create_respipe ();
498} 444}
499 445
500#define dREQ \ 446#define dREQ \
501 aio_req req; \ 447 aio_req req; \
448 int req_pri = next_pri; \
449 next_pri = EIO_DEFAULT_PRI + EIO_PRI_BIAS; \
502 \ 450 \
503 if (SvOK (callback) && !SvROK (callback)) \ 451 if (SvOK (callback) && !SvROK (callback)) \
504 croak ("clalback must be undef or of reference type"); \ 452 croak ("callback must be undef or of reference type"); \
505 \ 453 \
506 Newz (0, req, 1, aio_cb); \ 454 Newz (0, req, 1, eio_req); \
507 if (!req) \ 455 if (!req) \
508 croak ("out of memory during aio_req allocation"); \ 456 croak ("out of memory during eio_req allocation"); \
509 \ 457 \
510 req->callback = newSVsv (callback); 458 req->callback = newSVsv (callback); \
459 req->pri = req_pri
460
461#define REQ_SEND \
462 req_submit (req); \
463 \
464 if (GIMME_V != G_VOID) \
465 XPUSHs (req_sv (req, AIO_REQ_KLASS));
511 466
512MODULE = IO::AIO PACKAGE = IO::AIO 467MODULE = IO::AIO PACKAGE = IO::AIO
513 468
514PROTOTYPES: ENABLE 469PROTOTYPES: ENABLE
515 470
516BOOT: 471BOOT:
517{ 472{
518 create_pipe (); 473 stash = gv_stashpv ("IO::AIO", 1);
519 pthread_atfork (atfork_prepare, atfork_parent, atfork_child);
520}
521 474
475 newCONSTSUB (stash, "EXDEV", newSViv (EXDEV));
476 newCONSTSUB (stash, "O_RDONLY", newSViv (O_RDONLY));
477 newCONSTSUB (stash, "O_WRONLY", newSViv (O_WRONLY));
478 newCONSTSUB (stash, "O_CREAT", newSViv (O_CREAT));
479 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC));
480#ifdef _WIN32
481 X_MUTEX_CHECK (wrklock);
482 X_MUTEX_CHECK (reslock);
483 X_MUTEX_CHECK (reqlock);
484 X_MUTEX_CHECK (reqwait);
485 X_MUTEX_CHECK (preadwritelock);
486 X_MUTEX_CHECK (readdirlock);
487
488 X_COND_CHECK (reqwait);
489#else
490 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO));
491#endif
492
493 create_respipe ();
494
495 if (eio_init (want_poll, done_poll) < 0)
496 croak ("IO::AIO: unable to initialise eio library");
497
498 /* atfork child called in fifo order, so before eio's handler */
499 X_THREAD_ATFORK (0, 0, atfork_child);
500}
501
522void 502void
523min_parallel(nthreads) 503max_poll_reqs (int nreqs)
524 int nthreads
525 PROTOTYPE: $ 504 PROTOTYPE: $
505 CODE:
506 eio_set_max_poll_reqs (nreqs);
526 507
527void 508void
528max_parallel(nthreads) 509max_poll_time (double nseconds)
529 int nthreads
530 PROTOTYPE: $ 510 PROTOTYPE: $
531
532int
533max_outstanding(nreqs)
534 int nreqs
535 PROTOTYPE: $
536 CODE: 511 CODE:
537 RETVAL = max_outstanding; 512 eio_set_max_poll_time (nseconds);
513
514void
515min_parallel (int nthreads)
516 PROTOTYPE: $
517 CODE:
518 eio_set_min_parallel (nthreads);
519
520void
521max_parallel (int nthreads)
522 PROTOTYPE: $
523 CODE:
524 eio_set_max_parallel (nthreads);
525
526void
527max_idle (int nthreads)
528 PROTOTYPE: $
529 CODE:
530 eio_set_max_idle (nthreads);
531
532void
533max_outstanding (int maxreqs)
534 PROTOTYPE: $
535 CODE:
538 max_outstanding = nreqs; 536 max_outstanding = maxreqs;
539 537
540void 538void
541aio_open(pathname,flags,mode,callback=&PL_sv_undef) 539aio_open (SV8 *pathname, int flags, int mode, SV *callback=&PL_sv_undef)
542 SV * pathname
543 int flags
544 int mode
545 SV * callback
546 PROTOTYPE: $$$;$ 540 PROTOTYPE: $$$;$
547 CODE: 541 PPCODE:
548{ 542{
549 dREQ; 543 dREQ;
550 544
551 req->type = REQ_OPEN; 545 req->type = EIO_OPEN;
552 req->data = newSVsv (pathname); 546 req->sv1 = newSVsv (pathname);
553 req->dataptr = SvPVbyte_nolen (req->data); 547 req->ptr1 = SvPVbyte_nolen (req->sv1);
554 req->fd = flags; 548 req->int1 = flags;
555 req->mode = mode; 549 req->int2 = mode;
556 550
557 send_req (req); 551 REQ_SEND;
558} 552}
559 553
560void 554void
561aio_close(fh,callback=&PL_sv_undef) 555aio_fsync (SV *fh, SV *callback=&PL_sv_undef)
562 SV * fh
563 SV * callback
564 PROTOTYPE: $;$ 556 PROTOTYPE: $;$
565 ALIAS: 557 ALIAS:
566 aio_close = REQ_CLOSE
567 aio_fsync = REQ_FSYNC 558 aio_fsync = EIO_FSYNC
568 aio_fdatasync = REQ_FDATASYNC 559 aio_fdatasync = EIO_FDATASYNC
569 CODE: 560 PPCODE:
570{ 561{
571 dREQ; 562 dREQ;
572 563
573 req->type = ix; 564 req->type = ix;
574 req->fh = newSVsv (fh); 565 req->sv1 = newSVsv (fh);
575 req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); 566 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh)));
576 567
577 send_req (req); 568 REQ_SEND (req);
578} 569}
579 570
580void 571void
572aio_close (SV *fh, SV *callback=&PL_sv_undef)
573 PROTOTYPE: $;$
574 PPCODE:
575{
576 static int close_pipe = -1; /* dummy fd to close fds via dup2 */
577 dREQ;
578
579 if (close_pipe < 0)
580 {
581 int pipefd [2];
582
583 if (pipe (pipefd) < 0
584 || close (pipefd [1]) < 0
585 || fcntl (pipefd [0], F_SETFD, FD_CLOEXEC) < 0)
586 abort (); /*D*/
587
588 close_pipe = pipefd [0];
589 }
590
591 req->type = EIO_DUP2;
592 req->int1 = close_pipe;
593 req->sv2 = newSVsv (fh);
594 req->int2 = PerlIO_fileno (IoIFP (sv_2io (fh)));
595
596 REQ_SEND (req);
597}
598
599void
581aio_read(fh,offset,length,data,dataoffset,callback=&PL_sv_undef) 600aio_read (SV *fh, SV *offset, SV *length, SV8 *data, IV dataoffset, SV *callback=&PL_sv_undef)
582 SV * fh
583 UV offset
584 IV length
585 SV * data
586 IV dataoffset
587 SV * callback
588 ALIAS: 601 ALIAS:
589 aio_read = REQ_READ 602 aio_read = EIO_READ
590 aio_write = REQ_WRITE 603 aio_write = EIO_WRITE
591 PROTOTYPE: $$$$$;$ 604 PROTOTYPE: $$$$$;$
592 CODE: 605 PPCODE:
593{ 606{
594 aio_req req;
595 STRLEN svlen; 607 STRLEN svlen;
596 char *svptr = SvPVbyte (data, svlen); 608 char *svptr = SvPVbyte (data, svlen);
609 UV len = SvUV (length);
597 610
598 SvUPGRADE (data, SVt_PV); 611 SvUPGRADE (data, SVt_PV);
599 SvPOK_on (data); 612 SvPOK_on (data);
600 613
601 if (dataoffset < 0) 614 if (dataoffset < 0)
602 dataoffset += svlen; 615 dataoffset += svlen;
603 616
604 if (dataoffset < 0 || dataoffset > svlen) 617 if (dataoffset < 0 || dataoffset > svlen)
605 croak ("data offset outside of string"); 618 croak ("dataoffset outside of data scalar");
606 619
607 if (ix == REQ_WRITE) 620 if (ix == EIO_WRITE)
608 { 621 {
609 /* write: check length and adjust. */ 622 /* write: check length and adjust. */
610 if (length < 0 || length + dataoffset > svlen) 623 if (!SvOK (length) || len + dataoffset > svlen)
611 length = svlen - dataoffset; 624 len = svlen - dataoffset;
612 } 625 }
613 else 626 else
614 { 627 {
615 /* read: grow scalar as necessary */ 628 /* read: grow scalar as necessary */
616 svptr = SvGROW (data, length + dataoffset); 629 svptr = SvGROW (data, len + dataoffset + 1);
617 } 630 }
618 631
619 if (length < 0) 632 if (len < 0)
620 croak ("length must not be negative"); 633 croak ("length must not be negative");
621 634
622 { 635 {
623 dREQ; 636 dREQ;
624 637
625 req->type = ix; 638 req->type = ix;
626 req->fh = newSVsv (fh); 639 req->sv1 = newSVsv (fh);
627 req->fd = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh)) 640 req->int1 = PerlIO_fileno (ix == EIO_READ ? IoIFP (sv_2io (fh))
628 : IoOFP (sv_2io (fh))); 641 : IoOFP (sv_2io (fh)));
642 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
629 req->offset = offset; 643 req->size = len;
630 req->length = length;
631 req->data = SvREFCNT_inc (data); 644 req->sv2 = SvREFCNT_inc (data);
632 req->dataptr = (char *)svptr + dataoffset; 645 req->ptr2 = (char *)svptr + dataoffset;
646 req->stroffset = dataoffset;
633 647
634 send_req (req); 648 if (!SvREADONLY (data))
649 {
650 SvREADONLY_on (data);
651 req->flags |= FLAG_SV2_RO_OFF;
652 }
653
654 REQ_SEND;
635 } 655 }
636} 656}
637 657
638void 658void
659aio_readlink (SV8 *path, SV *callback=&PL_sv_undef)
660 PROTOTYPE: $$;$
661 PPCODE:
662{
663 SV *data;
664 dREQ;
665
666 data = newSV (NAME_MAX);
667 SvPOK_on (data);
668
669 req->type = EIO_READLINK;
670 req->sv1 = newSVsv (path);
671 req->ptr1 = SvPVbyte_nolen (req->sv1);
672 req->sv2 = data;
673 req->ptr2 = SvPVbyte_nolen (data);
674
675 REQ_SEND;
676}
677
678void
679aio_sendfile (SV *out_fh, SV *in_fh, SV *in_offset, UV length, SV *callback=&PL_sv_undef)
680 PROTOTYPE: $$$$;$
681 PPCODE:
682{
683 dREQ;
684
685 req->type = EIO_SENDFILE;
686 req->sv1 = newSVsv (out_fh);
687 req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh)));
688 req->sv2 = newSVsv (in_fh);
689 req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh)));
690 req->offs = SvVAL64 (in_offset);
691 req->size = length;
692
693 REQ_SEND;
694}
695
696void
639aio_readahead(fh,offset,length,callback=&PL_sv_undef) 697aio_readahead (SV *fh, SV *offset, IV length, SV *callback=&PL_sv_undef)
640 SV * fh
641 UV offset
642 IV length
643 SV * callback
644 PROTOTYPE: $$$;$ 698 PROTOTYPE: $$$;$
645 CODE: 699 PPCODE:
646{ 700{
647 dREQ; 701 dREQ;
648 702
649 req->type = REQ_READAHEAD; 703 req->type = EIO_READAHEAD;
650 req->fh = newSVsv (fh); 704 req->sv1 = newSVsv (fh);
651 req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); 705 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh)));
652 req->offset = offset; 706 req->offs = SvVAL64 (offset);
653 req->length = length; 707 req->size = length;
654 708
655 send_req (req); 709 REQ_SEND;
656} 710}
657 711
658void 712void
659aio_stat(fh_or_path,callback=&PL_sv_undef) 713aio_stat (SV8 *fh_or_path, SV *callback=&PL_sv_undef)
660 SV * fh_or_path
661 SV * callback
662 ALIAS: 714 ALIAS:
663 aio_stat = REQ_STAT 715 aio_stat = EIO_STAT
664 aio_lstat = REQ_LSTAT 716 aio_lstat = EIO_LSTAT
665 CODE: 717 PPCODE:
666{ 718{
667 dREQ; 719 dREQ;
668 720
669 New (0, req->statdata, 1, Stat_t); 721 req->ptr2 = malloc (sizeof (EIO_STRUCT_STAT));
670 if (!req->statdata) 722 if (!req->ptr2)
671 { 723 {
672 free_req (req); 724 req_destroy (req);
673 croak ("out of memory during aio_req->statdata allocation"); 725 croak ("out of memory during aio_stat statdata allocation");
674 } 726 }
727
728 req->flags |= EIO_FLAG_PTR2_FREE;
729 req->sv1 = newSVsv (fh_or_path);
675 730
676 if (SvPOK (fh_or_path)) 731 if (SvPOK (fh_or_path))
677 { 732 {
678 req->type = ix; 733 req->type = ix;
679 req->data = newSVsv (fh_or_path);
680 req->dataptr = SvPVbyte_nolen (req->data); 734 req->ptr1 = SvPVbyte_nolen (req->sv1);
681 } 735 }
682 else 736 else
683 { 737 {
684 req->type = REQ_FSTAT; 738 req->type = EIO_FSTAT;
685 req->fh = newSVsv (fh_or_path);
686 req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); 739 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
740 }
741
742 REQ_SEND;
743}
744
745void
746aio_utime (SV8 *fh_or_path, SV *atime, SV *mtime, SV *callback=&PL_sv_undef)
747 PPCODE:
748{
749 dREQ;
750
751 req->nv1 = SvOK (atime) ? SvNV (atime) : -1.;
752 req->nv2 = SvOK (mtime) ? SvNV (mtime) : -1.;
753 req->sv1 = newSVsv (fh_or_path);
754
755 if (SvPOK (fh_or_path))
687 } 756 {
757 req->type = EIO_UTIME;
758 req->ptr1 = SvPVbyte_nolen (req->sv1);
759 }
760 else
761 {
762 req->type = EIO_FUTIME;
763 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
764 }
688 765
689 send_req (req); 766 REQ_SEND;
690} 767}
691 768
692void 769void
770aio_truncate (SV8 *fh_or_path, SV *offset, SV *callback=&PL_sv_undef)
771 PPCODE:
772{
773 dREQ;
774
775 req->sv1 = newSVsv (fh_or_path);
776 req->offs = SvOK (offset) ? SvVAL64 (offset) : -1;
777
778 if (SvPOK (fh_or_path))
779 {
780 req->type = EIO_TRUNCATE;
781 req->ptr1 = SvPVbyte_nolen (req->sv1);
782 }
783 else
784 {
785 req->type = EIO_FTRUNCATE;
786 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
787 }
788
789 REQ_SEND;
790}
791
792void
793aio_chmod (SV8 *fh_or_path, int mode, SV *callback=&PL_sv_undef)
794 ALIAS:
795 aio_chmod = EIO_CHMOD
796 aio_fchmod = EIO_FCHMOD
797 aio_mkdir = EIO_MKDIR
798 PPCODE:
799{
800 dREQ;
801
802 req->type = ix;
803 req->int2 = mode;
804 req->sv1 = newSVsv (fh_or_path);
805
806 if (ix == EIO_FCHMOD)
807 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
808 else
809 req->ptr1 = SvPVbyte_nolen (req->sv1);
810
811 REQ_SEND;
812}
813
814void
815aio_chown (SV8 *fh_or_path, SV *uid, SV *gid, SV *callback=&PL_sv_undef)
816 PPCODE:
817{
818 dREQ;
819
820 req->int2 = SvOK (uid) ? SvIV (uid) : -1;
821 req->int3 = SvOK (gid) ? SvIV (gid) : -1;
822 req->sv1 = newSVsv (fh_or_path);
823
824 if (SvPOK (fh_or_path))
825 {
826 req->type = EIO_CHOWN;
827 req->ptr1 = SvPVbyte_nolen (req->sv1);
828 }
829 else
830 {
831 req->type = EIO_FCHOWN;
832 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
833 }
834
835 REQ_SEND;
836}
837
838void
693aio_unlink(pathname,callback=&PL_sv_undef) 839aio_unlink (SV8 *pathname, SV *callback=&PL_sv_undef)
694 SV * pathname
695 SV * callback
696 ALIAS: 840 ALIAS:
697 aio_unlink = REQ_UNLINK 841 aio_unlink = EIO_UNLINK
698 aio_rmdir = REQ_RMDIR 842 aio_rmdir = EIO_RMDIR
843 aio_readdir = EIO_READDIR
699 CODE: 844 PPCODE:
700{ 845{
701 dREQ; 846 dREQ;
702 847
703 req->type = ix; 848 req->type = ix;
704 req->data = newSVsv (pathname); 849 req->sv1 = newSVsv (pathname);
705 req->dataptr = SvPVbyte_nolen (req->data); 850 req->ptr1 = SvPVbyte_nolen (req->sv1);
851
852 REQ_SEND;
853}
854
855void
856aio_link (SV8 *oldpath, SV8 *newpath, SV *callback=&PL_sv_undef)
857 ALIAS:
858 aio_link = EIO_LINK
859 aio_symlink = EIO_SYMLINK
860 aio_rename = EIO_RENAME
861 PPCODE:
862{
863 dREQ;
706 864
707 send_req (req); 865 req->type = ix;
708} 866 req->sv1 = newSVsv (oldpath);
709 867 req->ptr1 = SvPVbyte_nolen (req->sv1);
710void 868 req->sv2 = newSVsv (newpath);
711aio_symlink(oldpath,newpath,callback=&PL_sv_undef) 869 req->ptr2 = SvPVbyte_nolen (req->sv2);
712 SV * oldpath
713 SV * newpath
714 SV * callback
715 CODE:
716{
717 dREQ;
718 870
719 req->type = REQ_SYMLINK; 871 REQ_SEND;
720 req->fh = newSVsv (oldpath); 872}
721 req->data2ptr = SvPVbyte_nolen (req->fh); 873
722 req->data = newSVsv (newpath); 874void
723 req->dataptr = SvPVbyte_nolen (req->data); 875aio_mknod (SV8 *pathname, int mode, UV dev, SV *callback=&PL_sv_undef)
876 PPCODE:
877{
878 dREQ;
724 879
725 send_req (req); 880 req->type = EIO_MKNOD;
881 req->sv1 = newSVsv (pathname);
882 req->ptr1 = SvPVbyte_nolen (req->sv1);
883 req->int2 = (mode_t)mode;
884 req->offs = dev;
885
886 REQ_SEND;
726} 887}
727 888
728void 889void
890aio_busy (double delay, SV *callback=&PL_sv_undef)
891 PPCODE:
892{
893 dREQ;
894
895 req->type = EIO_BUSY;
896 req->nv1 = delay < 0. ? 0. : delay;
897
898 REQ_SEND;
899}
900
901void
902aio_group (SV *callback=&PL_sv_undef)
903 PROTOTYPE: ;$
904 PPCODE:
905{
906 dREQ;
907
908 req->type = EIO_GROUP;
909
910 eio_submit (req);
911 XPUSHs (req_sv (req, AIO_GRP_KLASS));
912}
913
914void
915aio_nop (SV *callback=&PL_sv_undef)
916 ALIAS:
917 aio_nop = EIO_NOP
918 aio_sync = EIO_SYNC
919 PPCODE:
920{
921 dREQ;
922
923 req->type = ix;
924
925 REQ_SEND;
926}
927
928int
929aioreq_pri (int pri = 0)
930 PROTOTYPE: ;$
931 CODE:
932 RETVAL = next_pri - EIO_PRI_BIAS;
933 if (items > 0)
934 {
935 if (pri < EIO_PRI_MIN) pri = EIO_PRI_MIN;
936 if (pri > EIO_PRI_MAX) pri = EIO_PRI_MAX;
937 next_pri = pri + EIO_PRI_BIAS;
938 }
939 OUTPUT:
940 RETVAL
941
942void
943aioreq_nice (int nice = 0)
944 CODE:
945 nice = next_pri - nice;
946 if (nice < EIO_PRI_MIN) nice = EIO_PRI_MIN;
947 if (nice > EIO_PRI_MAX) nice = EIO_PRI_MAX;
948 next_pri = nice + EIO_PRI_BIAS;
949
950void
729flush() 951flush ()
730 PROTOTYPE: 952 PROTOTYPE:
731 CODE: 953 CODE:
732 while (nreqs) 954 while (eio_nreqs ())
733 { 955 {
734 poll_wait (); 956 poll_wait ();
735 poll_cb (); 957 poll_cb ();
736 } 958 }
737 959
738void 960int
739poll() 961poll()
740 PROTOTYPE: 962 PROTOTYPE:
741 CODE: 963 CODE:
742 if (nreqs)
743 {
744 poll_wait (); 964 poll_wait ();
745 poll_cb (); 965 RETVAL = poll_cb ();
746 } 966 OUTPUT:
967 RETVAL
747 968
748int 969int
749poll_fileno() 970poll_fileno()
750 PROTOTYPE: 971 PROTOTYPE:
751 CODE: 972 CODE:
763 984
764void 985void
765poll_wait() 986poll_wait()
766 PROTOTYPE: 987 PROTOTYPE:
767 CODE: 988 CODE:
768 if (nreqs)
769 poll_wait (); 989 poll_wait ();
770 990
771int 991int
772nreqs() 992nreqs()
773 PROTOTYPE: 993 PROTOTYPE:
774 CODE: 994 CODE:
775 RETVAL = nreqs; 995 RETVAL = eio_nreqs ();
776 OUTPUT: 996 OUTPUT:
777 RETVAL 997 RETVAL
778 998
999int
1000nready()
1001 PROTOTYPE:
1002 CODE:
1003 RETVAL = eio_nready ();
1004 OUTPUT:
1005 RETVAL
1006
1007int
1008npending()
1009 PROTOTYPE:
1010 CODE:
1011 RETVAL = eio_npending ();
1012 OUTPUT:
1013 RETVAL
1014
1015int
1016nthreads()
1017 PROTOTYPE:
1018 CODE:
1019 if (WORDACCESS_UNSAFE) X_LOCK (wrklock);
1020 RETVAL = started;
1021 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock);
1022 OUTPUT:
1023 RETVAL
1024
1025void _on_next_submit (SV *cb)
1026 CODE:
1027 SvREFCNT_dec (on_next_submit);
1028 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1029
1030PROTOTYPES: DISABLE
1031
1032MODULE = IO::AIO PACKAGE = IO::AIO::REQ
1033
1034void
1035cancel (aio_req_ornot req)
1036 CODE:
1037 eio_cancel (req);
1038
1039void
1040cb (aio_req_ornot req, SV *callback=&PL_sv_undef)
1041 CODE:
1042 SvREFCNT_dec (req->callback);
1043 req->callback = newSVsv (callback);
1044
1045MODULE = IO::AIO PACKAGE = IO::AIO::GRP
1046
1047void
1048add (aio_req grp, ...)
1049 PPCODE:
1050{
1051 int i;
1052
1053 if (grp->int1 == 2)
1054 croak ("cannot add requests to IO::AIO::GRP after the group finished");
1055
1056 for (i = 1; i < items; ++i )
1057 {
1058 aio_req req;
1059
1060 if (GIMME_V != G_VOID)
1061 XPUSHs (sv_2mortal (newSVsv (ST (i))));
1062
1063 req = SvAIO_REQ (ST (i));
1064
1065 if (req)
1066 eio_grp_add (grp, req);
1067 }
1068}
1069
1070void
1071cancel_subs (aio_req_ornot req)
1072 CODE:
1073 req_cancel_subs (req);
1074
1075void
1076result (aio_req grp, ...)
1077 CODE:
1078{
1079 int i;
1080 AV *av;
1081
1082 grp->errorno = errno;
1083
1084 av = newAV ();
1085
1086 for (i = 1; i < items; ++i )
1087 av_push (av, newSVsv (ST (i)));
1088
1089 SvREFCNT_dec (grp->sv1);
1090 grp->sv1 = (SV *)av;
1091}
1092
1093void
1094errno (aio_req grp, int errorno = errno)
1095 CODE:
1096 grp->errorno = errorno;
1097
1098void
1099limit (aio_req grp, int limit)
1100 CODE:
1101 eio_grp_limit (grp, limit);
1102
1103void
1104feed (aio_req grp, SV *callback=&PL_sv_undef)
1105 CODE:
1106{
1107 SvREFCNT_dec (grp->sv2);
1108 grp->sv2 = newSVsv (callback);
1109
1110 if (grp->int2 <= 0)
1111 grp->int2 = 2;
1112
1113 eio_grp_limit (grp, grp->int2);
1114}
1115

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines