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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines