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.83 by root, Sat Oct 28 00:17:30 2006 UTC vs.
Revision 1.90 by root, Tue Oct 31 00:32:19 2006 UTC

43# else 43# else
44# error sendfile support requested but not available 44# error sendfile support requested but not available
45# endif 45# endif
46#endif 46#endif
47 47
48/* number of seconds after which idle threads exit */
49#define IDLE_TIMEOUT 10
50
48/* used for struct dirent, AIX doesn't provide it */ 51/* used for struct dirent, AIX doesn't provide it */
49#ifndef NAME_MAX 52#ifndef NAME_MAX
50# define NAME_MAX 4096 53# define NAME_MAX 4096
51#endif 54#endif
52 55
65 68
66/* wether word reads are potentially non-atomic. 69/* wether word reads are potentially non-atomic.
67 * this is conservatice, likely most arches this runs 70 * this is conservatice, likely most arches this runs
68 * on have atomic word read/writes. 71 * on have atomic word read/writes.
69 */ 72 */
70#ifndef WORDREAD_UNSAFE 73#ifndef WORDACCESS_UNSAFE
71# if __i386 || __x86_64 74# if __i386 || __x86_64
72# define WORDREAD_UNSAFE 0 75# define WORDACCESS_UNSAFE 0
73# else 76# else
74# define WORDREAD_UNSAFE 1 77# define WORDACCESS_UNSAFE 1
75# endif 78# endif
76#endif 79#endif
77 80
78/* buffer size for various temporary buffers */ 81/* buffer size for various temporary buffers */
79#define AIO_BUFSIZE 65536 82#define AIO_BUFSIZE 65536
83 LOCK (wrklock); \ 86 LOCK (wrklock); \
84 self->dbuf = aio_buf = malloc (AIO_BUFSIZE); \ 87 self->dbuf = aio_buf = malloc (AIO_BUFSIZE); \
85 UNLOCK (wrklock); \ 88 UNLOCK (wrklock); \
86 if (!aio_buf) \ 89 if (!aio_buf) \
87 return -1; 90 return -1;
91
92typedef SV SV8; /* byte-sv, used for argument-checking */
88 93
89enum { 94enum {
90 REQ_QUIT, 95 REQ_QUIT,
91 REQ_OPEN, REQ_CLOSE, 96 REQ_OPEN, REQ_CLOSE,
92 REQ_READ, REQ_WRITE, REQ_READAHEAD, 97 REQ_READ, REQ_WRITE, REQ_READAHEAD,
93 REQ_SENDFILE, 98 REQ_SENDFILE,
94 REQ_STAT, REQ_LSTAT, REQ_FSTAT, 99 REQ_STAT, REQ_LSTAT, REQ_FSTAT,
95 REQ_FSYNC, REQ_FDATASYNC, 100 REQ_FSYNC, REQ_FDATASYNC,
96 REQ_UNLINK, REQ_RMDIR, REQ_RENAME, 101 REQ_UNLINK, REQ_RMDIR, REQ_RENAME,
97 REQ_MKNOD, REQ_READDIR, 102 REQ_MKNOD, REQ_READDIR,
98 REQ_LINK, REQ_SYMLINK, 103 REQ_LINK, REQ_SYMLINK, REQ_READLINK,
99 REQ_GROUP, REQ_NOP, 104 REQ_GROUP, REQ_NOP,
100 REQ_BUSY, 105 REQ_BUSY,
101}; 106};
102 107
103#define AIO_REQ_KLASS "IO::AIO::REQ" 108#define AIO_REQ_KLASS "IO::AIO::REQ"
105 110
106typedef struct aio_cb 111typedef struct aio_cb
107{ 112{
108 struct aio_cb *volatile next; 113 struct aio_cb *volatile next;
109 114
110 SV *data, *callback; 115 SV *callback, *fh;
111 SV *fh, *fh2; 116 SV *sv1, *sv2;
112 void *dataptr, *data2ptr; 117 void *ptr1, *ptr2;
113 Stat_t *statdata;
114 off_t offset; 118 off_t offs;
115 size_t length; 119 size_t size;
116 ssize_t result; 120 ssize_t result;
117 121
118 STRLEN dataoffset; 122 STRLEN stroffset;
119 int type; 123 int type;
120 int fd, fd2; 124 int int1, int2;
121 int errorno; 125 int errorno;
122 mode_t mode; /* open */ 126 mode_t mode; /* open */
123 127
124 unsigned char flags; 128 unsigned char flags;
125 unsigned char pri; 129 unsigned char pri;
127 SV *self; /* the perl counterpart of this request, if any */ 131 SV *self; /* the perl counterpart of this request, if any */
128 struct aio_cb *grp, *grp_prev, *grp_next, *grp_first; 132 struct aio_cb *grp, *grp_prev, *grp_next, *grp_first;
129} aio_cb; 133} aio_cb;
130 134
131enum { 135enum {
132 FLAG_CANCELLED = 0x01, 136 FLAG_CANCELLED = 0x01, /* request was cancelled */
137 FLAG_SV1_RO_OFF = 0x40, /* data was set readonly */
138 FLAG_PTR2_FREE = 0x80, /* need to free(ptr2) */
133}; 139};
134 140
135typedef aio_cb *aio_req; 141typedef aio_cb *aio_req;
136typedef aio_cb *aio_req_ornot; 142typedef aio_cb *aio_req_ornot;
137 143
142 DEFAULT_PRI = 0, 148 DEFAULT_PRI = 0,
143 PRI_BIAS = -PRI_MIN, 149 PRI_BIAS = -PRI_MIN,
144 NUM_PRI = PRI_MAX + PRI_BIAS + 1, 150 NUM_PRI = PRI_MAX + PRI_BIAS + 1,
145}; 151};
146 152
153#define AIO_TICKS ((1000000 + 1023) >> 10)
154
155static unsigned int max_poll_time = 0;
156static unsigned int max_poll_reqs = 0;
157
158/* calculcate time difference in ~1/AIO_TICKS of a second */
159static int tvdiff (struct timeval *tv1, struct timeval *tv2)
160{
161 return (tv2->tv_sec - tv1->tv_sec ) * AIO_TICKS
162 + ((tv2->tv_usec - tv1->tv_usec) >> 10);
163}
164
147static int next_pri = DEFAULT_PRI + PRI_BIAS; 165static int next_pri = DEFAULT_PRI + PRI_BIAS;
148 166
149static unsigned int started, wanted; 167static unsigned int started, idle, wanted;
150 168
151#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) 169#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
152# define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 170# define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
153#else 171#else
154# define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 172# define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
196 214
197 free (wrk); 215 free (wrk);
198} 216}
199 217
200static volatile unsigned int nreqs, nready, npending; 218static volatile unsigned int nreqs, nready, npending;
219static volatile unsigned int max_idle = 4;
201static volatile unsigned int max_outstanding = 0xffffffff; 220static volatile unsigned int max_outstanding = 0xffffffff;
202static int respipe [2]; 221static int respipe [2];
203 222
204static pthread_mutex_t reslock = AIO_MUTEX_INIT; 223static pthread_mutex_t reslock = AIO_MUTEX_INIT;
205static pthread_mutex_t reqlock = AIO_MUTEX_INIT; 224static pthread_mutex_t reqlock = AIO_MUTEX_INIT;
206static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; 225static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER;
207 226
208#if WORDREAD_UNSAFE 227#if WORDACCESS_UNSAFE
209 228
210static unsigned int get_nready () 229static unsigned int get_nready ()
211{ 230{
212 unsigned int retval; 231 unsigned int retval;
213 232
227 UNLOCK (reslock); 246 UNLOCK (reslock);
228 247
229 return retval; 248 return retval;
230} 249}
231 250
251static unsigned int get_nthreads ()
252{
253 unsigned int retval;
254
255 LOCK (wrklock);
256 retval = started;
257 UNLOCK (wrklock);
258
259 return retval;
260}
261
232#else 262#else
233 263
234# define get_nready() nready 264# define get_nready() nready
235# define get_npending() npending 265# define get_npending() npending
266# define get_nthreads() started
236 267
237#endif 268#endif
238 269
239/* 270/*
240 * a somewhat faster data structure might be nice, but 271 * a somewhat faster data structure might be nice, but
288 } 319 }
289 320
290 abort (); 321 abort ();
291} 322}
292 323
293static int poll_cb (int max); 324static int poll_cb ();
294static void req_invoke (aio_req req); 325static void req_invoke (aio_req req);
295static void req_free (aio_req req); 326static void req_free (aio_req req);
296static void req_cancel (aio_req req); 327static void req_cancel (aio_req req);
297 328
298/* must be called at most once */ 329/* must be called at most once */
319 return mg ? (aio_req)mg->mg_ptr : 0; 350 return mg ? (aio_req)mg->mg_ptr : 0;
320} 351}
321 352
322static void aio_grp_feed (aio_req grp) 353static void aio_grp_feed (aio_req grp)
323{ 354{
324 while (grp->length < grp->fd2 && !(grp->flags & FLAG_CANCELLED)) 355 while (grp->size < grp->int2 && !(grp->flags & FLAG_CANCELLED))
325 { 356 {
326 int old_len = grp->length; 357 int old_len = grp->size;
327 358
328 if (grp->fh2 && SvOK (grp->fh2)) 359 if (grp->sv2 && SvOK (grp->sv2))
329 { 360 {
330 dSP; 361 dSP;
331 362
332 ENTER; 363 ENTER;
333 SAVETMPS; 364 SAVETMPS;
334 PUSHMARK (SP); 365 PUSHMARK (SP);
335 XPUSHs (req_sv (grp, AIO_GRP_KLASS)); 366 XPUSHs (req_sv (grp, AIO_GRP_KLASS));
336 PUTBACK; 367 PUTBACK;
337 call_sv (grp->fh2, G_VOID | G_EVAL | G_KEEPERR); 368 call_sv (grp->sv2, G_VOID | G_EVAL | G_KEEPERR);
338 SPAGAIN; 369 SPAGAIN;
339 FREETMPS; 370 FREETMPS;
340 LEAVE; 371 LEAVE;
341 } 372 }
342 373
343 /* stop if no progress has been made */ 374 /* stop if no progress has been made */
344 if (old_len == grp->length) 375 if (old_len == grp->size)
345 { 376 {
346 SvREFCNT_dec (grp->fh2); 377 SvREFCNT_dec (grp->sv2);
347 grp->fh2 = 0; 378 grp->sv2 = 0;
348 break; 379 break;
349 } 380 }
350 } 381 }
351} 382}
352 383
353static void aio_grp_dec (aio_req grp) 384static void aio_grp_dec (aio_req grp)
354{ 385{
355 --grp->length; 386 --grp->size;
356 387
357 /* call feeder, if applicable */ 388 /* call feeder, if applicable */
358 aio_grp_feed (grp); 389 aio_grp_feed (grp);
359 390
360 /* finish, if done */ 391 /* finish, if done */
361 if (!grp->length && grp->fd) 392 if (!grp->size && grp->int1)
362 { 393 {
363 req_invoke (grp); 394 req_invoke (grp);
364 req_free (grp); 395 req_free (grp);
365 } 396 }
366} 397}
367 398
368static void req_invoke (aio_req req) 399static void req_invoke (aio_req req)
369{ 400{
370 dSP; 401 dSP;
402
403 if (req->flags & FLAG_SV1_RO_OFF)
404 SvREADONLY_off (req->sv1);
371 405
372 if (!(req->flags & FLAG_CANCELLED) && SvOK (req->callback)) 406 if (!(req->flags & FLAG_CANCELLED) && SvOK (req->callback))
373 { 407 {
374 ENTER; 408 ENTER;
375 SAVETMPS; 409 SAVETMPS;
383 SV *rv = &PL_sv_undef; 417 SV *rv = &PL_sv_undef;
384 418
385 if (req->result >= 0) 419 if (req->result >= 0)
386 { 420 {
387 int i; 421 int i;
388 char *buf = req->data2ptr; 422 char *buf = req->ptr2;
389 AV *av = newAV (); 423 AV *av = newAV ();
390 424
391 av_extend (av, req->result - 1); 425 av_extend (av, req->result - 1);
392 426
393 for (i = 0; i < req->result; ++i) 427 for (i = 0; i < req->result; ++i)
421 XPUSHs (sv_2mortal (fh)); 455 XPUSHs (sv_2mortal (fh));
422 } 456 }
423 break; 457 break;
424 458
425 case REQ_GROUP: 459 case REQ_GROUP:
426 req->fd = 2; /* mark group as finished */ 460 req->int1 = 2; /* mark group as finished */
427 461
428 if (req->data) 462 if (req->sv1)
429 { 463 {
430 int i; 464 int i;
431 AV *av = (AV *)req->data; 465 AV *av = (AV *)req->sv1;
432 466
433 EXTEND (SP, AvFILL (av) + 1); 467 EXTEND (SP, AvFILL (av) + 1);
434 for (i = 0; i <= AvFILL (av); ++i) 468 for (i = 0; i <= AvFILL (av); ++i)
435 PUSHs (*av_fetch (av, i, 0)); 469 PUSHs (*av_fetch (av, i, 0));
436 } 470 }
438 472
439 case REQ_NOP: 473 case REQ_NOP:
440 case REQ_BUSY: 474 case REQ_BUSY:
441 break; 475 break;
442 476
477 case REQ_READLINK:
478 if (req->result > 0)
479 {
480 SvCUR_set (req->sv1, req->result);
481 *SvEND (req->sv1) = 0;
482 PUSHs (req->sv1);
483 }
484 break;
485
486 case REQ_STAT:
487 case REQ_LSTAT:
488 case REQ_FSTAT:
489 PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT;
490 PL_laststatval = req->result;
491 PL_statcache = *(Stat_t *)(req->ptr2);
492 PUSHs (sv_2mortal (newSViv (req->result)));
493 break;
494
495 case REQ_READ:
496 SvCUR_set (req->sv1, req->stroffset + (req->result > 0 ? req->result : 0));
497 *SvEND (req->sv1) = 0;
498 PUSHs (sv_2mortal (newSViv (req->result)));
499 break;
500
443 default: 501 default:
444 PUSHs (sv_2mortal (newSViv (req->result))); 502 PUSHs (sv_2mortal (newSViv (req->result)));
445 break; 503 break;
446 } 504 }
447 505
482 { 540 {
483 sv_unmagic (req->self, PERL_MAGIC_ext); 541 sv_unmagic (req->self, PERL_MAGIC_ext);
484 SvREFCNT_dec (req->self); 542 SvREFCNT_dec (req->self);
485 } 543 }
486 544
487 SvREFCNT_dec (req->data);
488 SvREFCNT_dec (req->fh); 545 SvREFCNT_dec (req->fh);
546 SvREFCNT_dec (req->sv1);
489 SvREFCNT_dec (req->fh2); 547 SvREFCNT_dec (req->sv2);
490 SvREFCNT_dec (req->callback); 548 SvREFCNT_dec (req->callback);
491 Safefree (req->statdata);
492 549
493 if (req->type == REQ_READDIR) 550 if (req->flags & FLAG_PTR2_FREE)
494 free (req->data2ptr); 551 free (req->ptr2);
495 552
496 Safefree (req); 553 Safefree (req);
497} 554}
498 555
499static void req_cancel_subs (aio_req grp) 556static void req_cancel_subs (aio_req grp)
501 aio_req sub; 558 aio_req sub;
502 559
503 if (grp->type != REQ_GROUP) 560 if (grp->type != REQ_GROUP)
504 return; 561 return;
505 562
506 SvREFCNT_dec (grp->fh2); 563 SvREFCNT_dec (grp->sv2);
507 grp->fh2 = 0; 564 grp->sv2 = 0;
508 565
509 for (sub = grp->grp_first; sub; sub = sub->grp_next) 566 for (sub = grp->grp_first; sub; sub = sub->grp_next)
510 req_cancel (sub); 567 req_cancel (sub);
511} 568}
512 569
556 UNLOCK (wrklock); 613 UNLOCK (wrklock);
557} 614}
558 615
559static void maybe_start_thread () 616static void maybe_start_thread ()
560{ 617{
561#if 0 618 if (get_nthreads () >= wanted)
562 static struct timeval last;
563 struct timeval diff, now;
564#endif
565
566 if (started >= wanted)
567 return; 619 return;
568 620
569 if (nready <= nreqs - get_nready () - get_npending ()) 621 /* todo: maybe use idle here, but might be less exact */
622 if (0 <= (int)get_nthreads () + (int)get_npending () - (int)nreqs)
570 return; 623 return;
571
572#if 0
573 gettimeofday (&now, 0);
574
575 diff.tv_sec = now.tv_sec - last.tv_sec;
576 diff.tv_usec = now.tv_usec - last.tv_usec;
577
578 if (diff.tv_usec < 0)
579 {
580 --diff.tv_sec;
581 diff.tv_usec += 1000000;
582 }
583
584 if (!diff.tv_sec && diff.tv_usec < 10000)
585 return;
586
587 last = now;
588#endif
589 624
590 start_thread (); 625 start_thread ();
591} 626}
592 627
593static void req_send (aio_req req) 628static void req_send (aio_req req)
620 LOCK (wrklock); 655 LOCK (wrklock);
621 --started; 656 --started;
622 UNLOCK (wrklock); 657 UNLOCK (wrklock);
623} 658}
624 659
660static void set_max_idle (int nthreads)
661{
662 if (WORDACCESS_UNSAFE) LOCK (reqlock);
663 max_idle = nthreads <= 0 ? 1 : nthreads;
664 if (WORDACCESS_UNSAFE) UNLOCK (reqlock);
665}
666
625static void min_parallel (int nthreads) 667static void min_parallel (int nthreads)
626{ 668{
627 if (wanted < nthreads) 669 if (wanted < nthreads)
628 wanted = nthreads; 670 wanted = nthreads;
629} 671}
642 fd_set rfd; 684 fd_set rfd;
643 685
644 while (nreqs) 686 while (nreqs)
645 { 687 {
646 int size; 688 int size;
647 if (WORDREAD_UNSAFE) LOCK (reslock); 689 if (WORDACCESS_UNSAFE) LOCK (reslock);
648 size = res_queue.size; 690 size = res_queue.size;
649 if (WORDREAD_UNSAFE) UNLOCK (reslock); 691 if (WORDACCESS_UNSAFE) UNLOCK (reslock);
650 692
651 if (size) 693 if (size)
652 return; 694 return;
653 695
654 maybe_start_thread (); 696 maybe_start_thread ();
658 700
659 select (respipe [0] + 1, &rfd, 0, 0, 0); 701 select (respipe [0] + 1, &rfd, 0, 0, 0);
660 } 702 }
661} 703}
662 704
663static int poll_cb (int max) 705static int poll_cb ()
664{ 706{
665 dSP; 707 dSP;
666 int count = 0; 708 int count = 0;
709 int maxreqs = max_poll_reqs;
667 int do_croak = 0; 710 int do_croak = 0;
711 struct timeval tv_start, tv_now;
668 aio_req req; 712 aio_req req;
713
714 if (max_poll_time)
715 gettimeofday (&tv_start, 0);
669 716
670 for (;;) 717 for (;;)
671 { 718 {
672 while (max <= 0 || count < max) 719 for (;;)
673 { 720 {
674 maybe_start_thread (); 721 maybe_start_thread ();
675 722
676 LOCK (reslock); 723 LOCK (reslock);
677 req = reqq_shift (&res_queue); 724 req = reqq_shift (&res_queue);
694 if (!req) 741 if (!req)
695 break; 742 break;
696 743
697 --nreqs; 744 --nreqs;
698 745
699 if (req->type == REQ_GROUP && req->length) 746 if (req->type == REQ_GROUP && req->size)
700 { 747 {
701 req->fd = 1; /* mark request as delayed */ 748 req->int1 = 1; /* mark request as delayed */
702 continue; 749 continue;
703 } 750 }
704 else 751 else
705 { 752 {
706 if (req->type == REQ_READ)
707 SvCUR_set (req->data, req->dataoffset + (req->result > 0 ? req->result : 0));
708
709 if (req->data2ptr && (req->type == REQ_READ || req->type == REQ_WRITE))
710 SvREADONLY_off (req->data);
711
712 if (req->statdata)
713 {
714 PL_laststype = req->type == REQ_LSTAT ? OP_LSTAT : OP_STAT;
715 PL_laststatval = req->result;
716 PL_statcache = *(req->statdata);
717 }
718
719 req_invoke (req); 753 req_invoke (req);
720 754
721 count++; 755 count++;
722 } 756 }
723 757
724 req_free (req); 758 req_free (req);
759
760 if (maxreqs && !--maxreqs)
761 break;
762
763 if (max_poll_time)
764 {
765 gettimeofday (&tv_now, 0);
766
767 if (tvdiff (&tv_start, &tv_now) >= max_poll_time)
768 break;
769 }
725 } 770 }
726 771
727 if (nreqs <= max_outstanding) 772 if (nreqs <= max_outstanding)
728 break; 773 break;
729 774
730 poll_wait (); 775 poll_wait ();
731 776
732 max = 0; 777 ++maxreqs;
733 } 778 }
734 779
735 return count; 780 return count;
736} 781}
737 782
955 int memofs = 0; 1000 int memofs = 0;
956 int res = 0; 1001 int res = 0;
957 int errorno; 1002 int errorno;
958 1003
959 LOCK (wrklock); 1004 LOCK (wrklock);
960 self->dirp = dirp = opendir (req->dataptr); 1005 self->dirp = dirp = opendir (req->ptr1);
961 self->dbuf = u = malloc (sizeof (*u)); 1006 self->dbuf = u = malloc (sizeof (*u));
1007 req->flags |= FLAG_PTR2_FREE;
962 req->data2ptr = names = malloc (memlen); 1008 req->ptr2 = names = malloc (memlen);
963 UNLOCK (wrklock); 1009 UNLOCK (wrklock);
964 1010
965 if (dirp && u && names) 1011 if (dirp && u && names)
966 for (;;) 1012 for (;;)
967 { 1013 {
981 1027
982 while (memofs + len > memlen) 1028 while (memofs + len > memlen)
983 { 1029 {
984 memlen *= 2; 1030 memlen *= 2;
985 LOCK (wrklock); 1031 LOCK (wrklock);
986 req->data2ptr = names = realloc (names, memlen); 1032 req->ptr2 = names = realloc (names, memlen);
987 UNLOCK (wrklock); 1033 UNLOCK (wrklock);
988 1034
989 if (!names) 1035 if (!names)
990 break; 1036 break;
991 } 1037 }
1004/*****************************************************************************/ 1050/*****************************************************************************/
1005 1051
1006static void *aio_proc (void *thr_arg) 1052static void *aio_proc (void *thr_arg)
1007{ 1053{
1008 aio_req req; 1054 aio_req req;
1055 struct timespec ts;
1009 worker *self = (worker *)thr_arg; 1056 worker *self = (worker *)thr_arg;
1057
1058 /* try to distribute timeouts somewhat evenly */
1059 ts.tv_nsec = (((unsigned long)self + (unsigned long)ts.tv_sec) & 1023UL)
1060 * (1000000000UL / 1024UL);
1010 1061
1011 for (;;) 1062 for (;;)
1012 { 1063 {
1064 ts.tv_sec = time (0) + IDLE_TIMEOUT;
1065
1013 LOCK (reqlock); 1066 LOCK (reqlock);
1014 1067
1015 for (;;) 1068 for (;;)
1016 { 1069 {
1017 self->req = req = reqq_shift (&req_queue); 1070 self->req = req = reqq_shift (&req_queue);
1018 1071
1019 if (req) 1072 if (req)
1020 break; 1073 break;
1021 1074
1075 ++idle;
1076
1077 if (pthread_cond_timedwait (&reqwait, &reqlock, &ts)
1078 == ETIMEDOUT)
1079 {
1080 if (idle > max_idle)
1081 {
1082 --idle;
1083 UNLOCK (reqlock);
1084 LOCK (wrklock);
1085 --started;
1086 UNLOCK (wrklock);
1087 goto quit;
1088 }
1089
1090 /* we are allowed to idle, so do so without any timeout */
1022 pthread_cond_wait (&reqwait, &reqlock); 1091 pthread_cond_wait (&reqwait, &reqlock);
1092 ts.tv_sec = time (0) + IDLE_TIMEOUT;
1093 }
1094
1095 --idle;
1023 } 1096 }
1024 1097
1025 --nready; 1098 --nready;
1026 1099
1027 UNLOCK (reqlock); 1100 UNLOCK (reqlock);
1029 errno = 0; /* strictly unnecessary */ 1102 errno = 0; /* strictly unnecessary */
1030 1103
1031 if (!(req->flags & FLAG_CANCELLED)) 1104 if (!(req->flags & FLAG_CANCELLED))
1032 switch (req->type) 1105 switch (req->type)
1033 { 1106 {
1034 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; 1107 case REQ_READ: req->result = pread (req->int1, req->ptr1, req->size, req->offs); break;
1035 case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; 1108 case REQ_WRITE: req->result = pwrite (req->int1, req->ptr1, req->size, req->offs); break;
1036 1109
1037 case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; 1110 case REQ_READAHEAD: req->result = readahead (req->int1, req->offs, req->size); break;
1038 case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length, self); break; 1111 case REQ_SENDFILE: req->result = sendfile_ (req->int1, req->int2, req->offs, req->size, self); break;
1039 1112
1040 case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; 1113 case REQ_STAT: req->result = stat (req->ptr1, (Stat_t *)req->ptr2); break;
1041 case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; 1114 case REQ_LSTAT: req->result = lstat (req->ptr1, (Stat_t *)req->ptr2); break;
1042 case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; 1115 case REQ_FSTAT: req->result = fstat (req->int1, (Stat_t *)req->ptr2); break;
1043 1116
1044 case REQ_OPEN: req->result = open (req->dataptr, req->fd, req->mode); break; 1117 case REQ_OPEN: req->result = open (req->ptr1, req->int1, req->mode); break;
1045 case REQ_CLOSE: req->result = close (req->fd); break; 1118 case REQ_CLOSE: req->result = close (req->int1); break;
1046 case REQ_UNLINK: req->result = unlink (req->dataptr); break; 1119 case REQ_UNLINK: req->result = unlink (req->ptr1); break;
1047 case REQ_RMDIR: req->result = rmdir (req->dataptr); break; 1120 case REQ_RMDIR: req->result = rmdir (req->ptr1); break;
1048 case REQ_RENAME: req->result = rename (req->data2ptr, req->dataptr); break; 1121 case REQ_RENAME: req->result = rename (req->ptr2, req->ptr1); break;
1049 case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break; 1122 case REQ_LINK: req->result = link (req->ptr2, req->ptr1); break;
1050 case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; 1123 case REQ_SYMLINK: req->result = symlink (req->ptr2, req->ptr1); break;
1051 case REQ_MKNOD: req->result = mknod (req->data2ptr, req->mode, (dev_t)req->offset); break; 1124 case REQ_MKNOD: req->result = mknod (req->ptr2, req->mode, (dev_t)req->offs); break;
1125 case REQ_READLINK: req->result = readlink (req->ptr2, req->ptr1, NAME_MAX); break;
1052 1126
1053 case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; 1127 case REQ_FDATASYNC: req->result = fdatasync (req->int1); break;
1054 case REQ_FSYNC: req->result = fsync (req->fd); break; 1128 case REQ_FSYNC: req->result = fsync (req->int1); break;
1055 case REQ_READDIR: scandir_ (req, self); break; 1129 case REQ_READDIR: scandir_ (req, self); break;
1056 1130
1057 case REQ_BUSY: 1131 case REQ_BUSY:
1058 { 1132 {
1059 struct timeval tv; 1133 struct timeval tv;
1060 1134
1061 tv.tv_sec = req->fd; 1135 tv.tv_sec = req->int1;
1062 tv.tv_usec = req->fd2; 1136 tv.tv_usec = req->int2;
1063 1137
1064 req->result = select (0, 0, 0, 0, &tv); 1138 req->result = select (0, 0, 0, 0, &tv);
1065 } 1139 }
1066 1140
1067 case REQ_GROUP: 1141 case REQ_GROUP:
1068 case REQ_NOP: 1142 case REQ_NOP:
1069 break; 1143 break;
1070 1144
1071 case REQ_QUIT: 1145 case REQ_QUIT:
1072 LOCK (wrklock); 1146 goto quit;
1073 worker_free (self);
1074 --started;
1075 UNLOCK (wrklock);
1076 return 0;
1077 1147
1078 default: 1148 default:
1079 req->result = ENOSYS; 1149 req->result = ENOSYS;
1080 break; 1150 break;
1081 } 1151 }
1093 self->req = 0; 1163 self->req = 0;
1094 worker_clear (self); 1164 worker_clear (self);
1095 1165
1096 UNLOCK (reslock); 1166 UNLOCK (reslock);
1097 } 1167 }
1168
1169quit:
1170 LOCK (wrklock);
1171 worker_free (self);
1172 UNLOCK (wrklock);
1173
1174 return 0;
1098} 1175}
1099 1176
1100/*****************************************************************************/ 1177/*****************************************************************************/
1101 1178
1102static void atfork_prepare (void) 1179static void atfork_prepare (void)
1144 1221
1145 worker_clear (wrk); 1222 worker_clear (wrk);
1146 worker_free (wrk); 1223 worker_free (wrk);
1147 } 1224 }
1148 1225
1149 started = 0; 1226 started = 0;
1227 idle = 0;
1150 nreqs = 0; 1228 nreqs = 0;
1229 nready = 0;
1230 npending = 0;
1151 1231
1152 close (respipe [0]); 1232 close (respipe [0]);
1153 close (respipe [1]); 1233 close (respipe [1]);
1154 create_pipe (); 1234 create_pipe ();
1155 1235
1192 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC)); 1272 newCONSTSUB (stash, "O_TRUNC", newSViv (O_TRUNC));
1193 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO)); 1273 newCONSTSUB (stash, "S_IFIFO", newSViv (S_IFIFO));
1194 1274
1195 create_pipe (); 1275 create_pipe ();
1196 pthread_atfork (atfork_prepare, atfork_parent, atfork_child); 1276 pthread_atfork (atfork_prepare, atfork_parent, atfork_child);
1197
1198 start_thread ();
1199} 1277}
1278
1279void
1280max_poll_reqs (int nreqs)
1281 PROTOTYPE: $
1282 CODE:
1283 max_poll_reqs = nreqs;
1284
1285void
1286max_poll_time (double nseconds)
1287 PROTOTYPE: $
1288 CODE:
1289 max_poll_time = nseconds * AIO_TICKS;
1200 1290
1201void 1291void
1202min_parallel (int nthreads) 1292min_parallel (int nthreads)
1203 PROTOTYPE: $ 1293 PROTOTYPE: $
1204 1294
1205void 1295void
1206max_parallel (int nthreads) 1296max_parallel (int nthreads)
1207 PROTOTYPE: $ 1297 PROTOTYPE: $
1298
1299void
1300max_idle (int nthreads)
1301 PROTOTYPE: $
1302 CODE:
1303 set_max_idle (nthreads);
1208 1304
1209int 1305int
1210max_outstanding (int maxreqs) 1306max_outstanding (int maxreqs)
1211 PROTOTYPE: $ 1307 PROTOTYPE: $
1212 CODE: 1308 CODE:
1215 OUTPUT: 1311 OUTPUT:
1216 RETVAL 1312 RETVAL
1217 1313
1218void 1314void
1219aio_open (pathname,flags,mode,callback=&PL_sv_undef) 1315aio_open (pathname,flags,mode,callback=&PL_sv_undef)
1220 SV * pathname 1316 SV8 * pathname
1221 int flags 1317 int flags
1222 int mode 1318 int mode
1223 SV * callback 1319 SV * callback
1224 PROTOTYPE: $$$;$ 1320 PROTOTYPE: $$$;$
1225 PPCODE: 1321 PPCODE:
1226{ 1322{
1227 dREQ; 1323 dREQ;
1228 1324
1229 req->type = REQ_OPEN; 1325 req->type = REQ_OPEN;
1230 req->data = newSVsv (pathname); 1326 req->sv1 = newSVsv (pathname);
1231 req->dataptr = SvPVbyte_nolen (req->data); 1327 req->ptr1 = SvPVbyte_nolen (req->sv1);
1232 req->fd = flags; 1328 req->int1 = flags;
1233 req->mode = mode; 1329 req->mode = mode;
1234 1330
1235 REQ_SEND; 1331 REQ_SEND;
1236} 1332}
1237 1333
1247 PPCODE: 1343 PPCODE:
1248{ 1344{
1249 dREQ; 1345 dREQ;
1250 1346
1251 req->type = ix; 1347 req->type = ix;
1252 req->fh = newSVsv (fh); 1348 req->fh = newSVsv (fh);
1253 req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); 1349 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh)));
1254 1350
1255 REQ_SEND (req); 1351 REQ_SEND (req);
1256} 1352}
1257 1353
1258void 1354void
1259aio_read (fh,offset,length,data,dataoffset,callback=&PL_sv_undef) 1355aio_read (fh,offset,length,data,dataoffset,callback=&PL_sv_undef)
1260 SV * fh 1356 SV * fh
1261 UV offset 1357 UV offset
1262 UV length 1358 UV length
1263 SV * data 1359 SV8 * data
1264 UV dataoffset 1360 UV dataoffset
1265 SV * callback 1361 SV * callback
1266 ALIAS: 1362 ALIAS:
1267 aio_read = REQ_READ 1363 aio_read = REQ_READ
1268 aio_write = REQ_WRITE 1364 aio_write = REQ_WRITE
1269 PROTOTYPE: $$$$$;$ 1365 PROTOTYPE: $$$$$;$
1270 PPCODE: 1366 PPCODE:
1271{ 1367{
1272 aio_req req;
1273 STRLEN svlen; 1368 STRLEN svlen;
1274 char *svptr = SvPVbyte (data, svlen); 1369 char *svptr = SvPVbyte (data, svlen);
1275 1370
1276 SvUPGRADE (data, SVt_PV); 1371 SvUPGRADE (data, SVt_PV);
1277 SvPOK_on (data); 1372 SvPOK_on (data);
1299 1394
1300 { 1395 {
1301 dREQ; 1396 dREQ;
1302 1397
1303 req->type = ix; 1398 req->type = ix;
1304 req->fh = newSVsv (fh); 1399 req->fh = newSVsv (fh);
1305 req->fd = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh)) 1400 req->int1 = PerlIO_fileno (ix == REQ_READ ? IoIFP (sv_2io (fh))
1306 : IoOFP (sv_2io (fh))); 1401 : IoOFP (sv_2io (fh)));
1307 req->offset = offset; 1402 req->offs = offset;
1308 req->length = length; 1403 req->size = length;
1309 req->data = SvREFCNT_inc (data); 1404 req->sv1 = SvREFCNT_inc (data);
1310 req->dataptr = (char *)svptr + dataoffset; 1405 req->ptr1 = (char *)svptr + dataoffset;
1406 req->stroffset = dataoffset;
1311 1407
1312 if (!SvREADONLY (data)) 1408 if (!SvREADONLY (data))
1313 { 1409 {
1314 SvREADONLY_on (data); 1410 SvREADONLY_on (data);
1315 req->data2ptr = (void *)data; 1411 req->flags |= FLAG_SV1_RO_OFF;
1316 } 1412 }
1317 1413
1318 REQ_SEND; 1414 REQ_SEND;
1319 } 1415 }
1416}
1417
1418void
1419aio_readlink (path,callback=&PL_sv_undef)
1420 SV8 * path
1421 SV * callback
1422 PROTOTYPE: $$;$
1423 PPCODE:
1424{
1425 SV *data;
1426 dREQ;
1427
1428 data = newSV (NAME_MAX);
1429 SvPOK_on (data);
1430
1431 req->type = REQ_READLINK;
1432 req->fh = newSVsv (path);
1433 req->ptr2 = SvPVbyte_nolen (req->fh);
1434 req->sv1 = data;
1435 req->ptr1 = SvPVbyte_nolen (data);
1436
1437 REQ_SEND;
1320} 1438}
1321 1439
1322void 1440void
1323aio_sendfile (out_fh,in_fh,in_offset,length,callback=&PL_sv_undef) 1441aio_sendfile (out_fh,in_fh,in_offset,length,callback=&PL_sv_undef)
1324 SV * out_fh 1442 SV * out_fh
1330 PPCODE: 1448 PPCODE:
1331{ 1449{
1332 dREQ; 1450 dREQ;
1333 1451
1334 req->type = REQ_SENDFILE; 1452 req->type = REQ_SENDFILE;
1335 req->fh = newSVsv (out_fh); 1453 req->fh = newSVsv (out_fh);
1336 req->fd = PerlIO_fileno (IoIFP (sv_2io (out_fh))); 1454 req->int1 = PerlIO_fileno (IoIFP (sv_2io (out_fh)));
1337 req->fh2 = newSVsv (in_fh); 1455 req->sv2 = newSVsv (in_fh);
1338 req->fd2 = PerlIO_fileno (IoIFP (sv_2io (in_fh))); 1456 req->int2 = PerlIO_fileno (IoIFP (sv_2io (in_fh)));
1339 req->offset = in_offset; 1457 req->offs = in_offset;
1340 req->length = length; 1458 req->size = length;
1341 1459
1342 REQ_SEND; 1460 REQ_SEND;
1343} 1461}
1344 1462
1345void 1463void
1352 PPCODE: 1470 PPCODE:
1353{ 1471{
1354 dREQ; 1472 dREQ;
1355 1473
1356 req->type = REQ_READAHEAD; 1474 req->type = REQ_READAHEAD;
1357 req->fh = newSVsv (fh); 1475 req->fh = newSVsv (fh);
1358 req->fd = PerlIO_fileno (IoIFP (sv_2io (fh))); 1476 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh)));
1359 req->offset = offset; 1477 req->offs = offset;
1360 req->length = length; 1478 req->size = length;
1361 1479
1362 REQ_SEND; 1480 REQ_SEND;
1363} 1481}
1364 1482
1365void 1483void
1366aio_stat (fh_or_path,callback=&PL_sv_undef) 1484aio_stat (fh_or_path,callback=&PL_sv_undef)
1367 SV * fh_or_path 1485 SV8 * fh_or_path
1368 SV * callback 1486 SV * callback
1369 ALIAS: 1487 ALIAS:
1370 aio_stat = REQ_STAT 1488 aio_stat = REQ_STAT
1371 aio_lstat = REQ_LSTAT 1489 aio_lstat = REQ_LSTAT
1372 PPCODE: 1490 PPCODE:
1373{ 1491{
1374 dREQ; 1492 dREQ;
1375 1493
1376 New (0, req->statdata, 1, Stat_t); 1494 req->ptr2 = malloc (sizeof (Stat_t));
1377 if (!req->statdata) 1495 if (!req->ptr2)
1378 { 1496 {
1379 req_free (req); 1497 req_free (req);
1380 croak ("out of memory during aio_req->statdata allocation"); 1498 croak ("out of memory during aio_stat statdata allocation");
1381 } 1499 }
1500
1501 req->flags |= FLAG_PTR2_FREE;
1382 1502
1383 if (SvPOK (fh_or_path)) 1503 if (SvPOK (fh_or_path))
1384 { 1504 {
1385 req->type = ix; 1505 req->type = ix;
1386 req->data = newSVsv (fh_or_path); 1506 req->sv1 = newSVsv (fh_or_path);
1387 req->dataptr = SvPVbyte_nolen (req->data); 1507 req->ptr1 = SvPVbyte_nolen (req->sv1);
1388 } 1508 }
1389 else 1509 else
1390 { 1510 {
1391 req->type = REQ_FSTAT; 1511 req->type = REQ_FSTAT;
1392 req->fh = newSVsv (fh_or_path); 1512 req->fh = newSVsv (fh_or_path);
1393 req->fd = PerlIO_fileno (IoIFP (sv_2io (fh_or_path))); 1513 req->int1 = PerlIO_fileno (IoIFP (sv_2io (fh_or_path)));
1394 } 1514 }
1395 1515
1396 REQ_SEND; 1516 REQ_SEND;
1397} 1517}
1398 1518
1399void 1519void
1400aio_unlink (pathname,callback=&PL_sv_undef) 1520aio_unlink (pathname,callback=&PL_sv_undef)
1401 SV * pathname 1521 SV8 * pathname
1402 SV * callback 1522 SV * callback
1403 ALIAS: 1523 ALIAS:
1404 aio_unlink = REQ_UNLINK 1524 aio_unlink = REQ_UNLINK
1405 aio_rmdir = REQ_RMDIR 1525 aio_rmdir = REQ_RMDIR
1406 aio_readdir = REQ_READDIR 1526 aio_readdir = REQ_READDIR
1407 PPCODE: 1527 PPCODE:
1408{ 1528{
1409 dREQ; 1529 dREQ;
1410 1530
1411 req->type = ix; 1531 req->type = ix;
1412 req->data = newSVsv (pathname); 1532 req->sv1 = newSVsv (pathname);
1413 req->dataptr = SvPVbyte_nolen (req->data); 1533 req->ptr1 = SvPVbyte_nolen (req->sv1);
1414 1534
1415 REQ_SEND; 1535 REQ_SEND;
1416} 1536}
1417 1537
1418void 1538void
1419aio_link (oldpath,newpath,callback=&PL_sv_undef) 1539aio_link (oldpath,newpath,callback=&PL_sv_undef)
1420 SV * oldpath 1540 SV8 * oldpath
1421 SV * newpath 1541 SV8 * newpath
1422 SV * callback 1542 SV * callback
1423 ALIAS: 1543 ALIAS:
1424 aio_link = REQ_LINK 1544 aio_link = REQ_LINK
1425 aio_symlink = REQ_SYMLINK 1545 aio_symlink = REQ_SYMLINK
1426 aio_rename = REQ_RENAME 1546 aio_rename = REQ_RENAME
1427 PPCODE: 1547 PPCODE:
1428{ 1548{
1429 dREQ; 1549 dREQ;
1430 1550
1431 req->type = ix; 1551 req->type = ix;
1432 req->fh = newSVsv (oldpath); 1552 req->fh = newSVsv (oldpath);
1433 req->data2ptr = SvPVbyte_nolen (req->fh); 1553 req->ptr2 = SvPVbyte_nolen (req->fh);
1434 req->data = newSVsv (newpath); 1554 req->sv1 = newSVsv (newpath);
1435 req->dataptr = SvPVbyte_nolen (req->data); 1555 req->ptr1 = SvPVbyte_nolen (req->sv1);
1436 1556
1437 REQ_SEND; 1557 REQ_SEND;
1438} 1558}
1439 1559
1440void 1560void
1441aio_mknod (pathname,mode,dev,callback=&PL_sv_undef) 1561aio_mknod (pathname,mode,dev,callback=&PL_sv_undef)
1442 SV * pathname 1562 SV8 * pathname
1443 SV * callback 1563 SV * callback
1444 UV mode 1564 UV mode
1445 UV dev 1565 UV dev
1446 PPCODE: 1566 PPCODE:
1447{ 1567{
1448 dREQ; 1568 dREQ;
1449 1569
1450 req->type = REQ_MKNOD; 1570 req->type = REQ_MKNOD;
1451 req->data = newSVsv (pathname); 1571 req->sv1 = newSVsv (pathname);
1452 req->dataptr = SvPVbyte_nolen (req->data); 1572 req->ptr1 = SvPVbyte_nolen (req->sv1);
1453 req->mode = (mode_t)mode; 1573 req->mode = (mode_t)mode;
1454 req->offset = dev; 1574 req->offs = dev;
1455 1575
1456 REQ_SEND; 1576 REQ_SEND;
1457} 1577}
1458 1578
1459void 1579void
1460aio_busy (delay,callback=&PL_sv_undef) 1580aio_busy (delay,callback=&PL_sv_undef)
1461 double delay 1581 double delay
1462 SV * callback 1582 SV * callback
1463 PPCODE: 1583 PPCODE:
1464{ 1584{
1465 dREQ; 1585 dREQ;
1466 1586
1467 req->type = REQ_BUSY; 1587 req->type = REQ_BUSY;
1468 req->fd = delay < 0. ? 0 : delay; 1588 req->int1 = delay < 0. ? 0 : delay;
1469 req->fd2 = delay < 0. ? 0 : 1000. * (delay - req->fd); 1589 req->int2 = delay < 0. ? 0 : 1000. * (delay - req->int1);
1470 1590
1471 REQ_SEND; 1591 REQ_SEND;
1472} 1592}
1473 1593
1474void 1594void
1478 PPCODE: 1598 PPCODE:
1479{ 1599{
1480 dREQ; 1600 dREQ;
1481 1601
1482 req->type = REQ_GROUP; 1602 req->type = REQ_GROUP;
1603
1483 req_send (req); 1604 req_send (req);
1484
1485 XPUSHs (req_sv (req, AIO_GRP_KLASS)); 1605 XPUSHs (req_sv (req, AIO_GRP_KLASS));
1486} 1606}
1487 1607
1488void 1608void
1489aio_nop (callback=&PL_sv_undef) 1609aio_nop (callback=&PL_sv_undef)
1490 SV * callback 1610 SV * callback
1491 PPCODE: 1611 PPCODE:
1492{ 1612{
1493 dREQ; 1613 dREQ;
1494 1614
1495 req->type = REQ_NOP; 1615 req->type = REQ_NOP;
1549 1669
1550int 1670int
1551poll_cb(...) 1671poll_cb(...)
1552 PROTOTYPE: 1672 PROTOTYPE:
1553 CODE: 1673 CODE:
1554 RETVAL = poll_cb (0); 1674 RETVAL = poll_cb ();
1555 OUTPUT:
1556 RETVAL
1557
1558int
1559poll_some(int max = 0)
1560 PROTOTYPE: $
1561 CODE:
1562 RETVAL = poll_cb (max);
1563 OUTPUT: 1675 OUTPUT:
1564 RETVAL 1676 RETVAL
1565 1677
1566void 1678void
1567poll_wait() 1679poll_wait()
1592 CODE: 1704 CODE:
1593 RETVAL = get_npending (); 1705 RETVAL = get_npending ();
1594 OUTPUT: 1706 OUTPUT:
1595 RETVAL 1707 RETVAL
1596 1708
1709int
1710nthreads()
1711 PROTOTYPE:
1712 CODE:
1713 if (WORDACCESS_UNSAFE) LOCK (wrklock);
1714 RETVAL = started;
1715 if (WORDACCESS_UNSAFE) UNLOCK (wrklock);
1716 OUTPUT:
1717 RETVAL
1718
1597PROTOTYPES: DISABLE 1719PROTOTYPES: DISABLE
1598 1720
1599MODULE = IO::AIO PACKAGE = IO::AIO::REQ 1721MODULE = IO::AIO PACKAGE = IO::AIO::REQ
1600 1722
1601void 1723void
1616 PPCODE: 1738 PPCODE:
1617{ 1739{
1618 int i; 1740 int i;
1619 aio_req req; 1741 aio_req req;
1620 1742
1621 if (grp->fd == 2) 1743 if (grp->int1 == 2)
1622 croak ("cannot add requests to IO::AIO::GRP after the group finished"); 1744 croak ("cannot add requests to IO::AIO::GRP after the group finished");
1623 1745
1624 for (i = 1; i < items; ++i ) 1746 for (i = 1; i < items; ++i )
1625 { 1747 {
1626 if (GIMME_V != G_VOID) 1748 if (GIMME_V != G_VOID)
1628 1750
1629 req = SvAIO_REQ (ST (i)); 1751 req = SvAIO_REQ (ST (i));
1630 1752
1631 if (req) 1753 if (req)
1632 { 1754 {
1633 ++grp->length; 1755 ++grp->size;
1634 req->grp = grp; 1756 req->grp = grp;
1635 1757
1636 req->grp_prev = 0; 1758 req->grp_prev = 0;
1637 req->grp_next = grp->grp_first; 1759 req->grp_next = grp->grp_first;
1638 1760
1661 av = newAV (); 1783 av = newAV ();
1662 1784
1663 for (i = 1; i < items; ++i ) 1785 for (i = 1; i < items; ++i )
1664 av_push (av, newSVsv (ST (i))); 1786 av_push (av, newSVsv (ST (i)));
1665 1787
1666 SvREFCNT_dec (grp->data); 1788 SvREFCNT_dec (grp->sv1);
1667 grp->data = (SV *)av; 1789 grp->sv1 = (SV *)av;
1668} 1790}
1669 1791
1670void 1792void
1671errno (aio_req grp, int errorno = errno) 1793errno (aio_req grp, int errorno = errno)
1672 CODE: 1794 CODE:
1673 grp->errorno = errorno; 1795 grp->errorno = errorno;
1674 1796
1675void 1797void
1676limit (aio_req grp, int limit) 1798limit (aio_req grp, int limit)
1677 CODE: 1799 CODE:
1678 grp->fd2 = limit; 1800 grp->int2 = limit;
1679 aio_grp_feed (grp); 1801 aio_grp_feed (grp);
1680 1802
1681void 1803void
1682feed (aio_req grp, SV *callback=&PL_sv_undef) 1804feed (aio_req grp, SV *callback=&PL_sv_undef)
1683 CODE: 1805 CODE:
1684{ 1806{
1685 SvREFCNT_dec (grp->fh2); 1807 SvREFCNT_dec (grp->sv2);
1686 grp->fh2 = newSVsv (callback); 1808 grp->sv2 = newSVsv (callback);
1687 1809
1688 if (grp->fd2 <= 0) 1810 if (grp->int2 <= 0)
1689 grp->fd2 = 2; 1811 grp->int2 = 2;
1690 1812
1691 aio_grp_feed (grp); 1813 aio_grp_feed (grp);
1692} 1814}
1693 1815

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines