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.70 by root, Tue Oct 24 15:15:56 2006 UTC vs.
Revision 1.75 by root, Thu Oct 26 06:44:48 2006 UTC

47/* used for struct dirent, AIX doesn't provide it */ 47/* used for struct dirent, AIX doesn't provide it */
48#ifndef NAME_MAX 48#ifndef NAME_MAX
49# define NAME_MAX 4096 49# define NAME_MAX 4096
50#endif 50#endif
51 51
52#ifndef PTHREAD_STACK_MIN
53/* care for broken platforms, e.g. windows */
54# define PTHREAD_STACK_MIN 16384
55#endif
56
52#if __ia64 57#if __ia64
53# define STACKSIZE 65536 58# define STACKSIZE 65536
54#elif __i386 || __x86_64 /* 16k is unreasonably high :( */ 59#elif __i386 || __x86_64 /* 16k is unreasonably high :( */
55# define STACKSIZE PTHREAD_STACK_MIN 60# define STACKSIZE PTHREAD_STACK_MIN
56#else 61#else
59 64
60/* buffer size for various temporary buffers */ 65/* buffer size for various temporary buffers */
61#define AIO_BUFSIZE 65536 66#define AIO_BUFSIZE 65536
62 67
63#define dBUF \ 68#define dBUF \
69 char *aio_buf; \
70 LOCK (wrklock); \
64 char *aio_buf = malloc (AIO_BUFSIZE); \ 71 self->dbuf = aio_buf = malloc (AIO_BUFSIZE); \
72 UNLOCK (wrklock); \
65 if (!aio_buf) \ 73 if (!aio_buf) \
66 return -1; 74 return -1;
67
68#define fBUF free (aio_buf)
69 75
70enum { 76enum {
71 REQ_QUIT, 77 REQ_QUIT,
72 REQ_OPEN, REQ_CLOSE, 78 REQ_OPEN, REQ_CLOSE,
73 REQ_READ, REQ_WRITE, REQ_READAHEAD, 79 REQ_READ, REQ_WRITE, REQ_READAHEAD,
127 133
128static int next_pri = DEFAULT_PRI + PRI_BIAS; 134static int next_pri = DEFAULT_PRI + PRI_BIAS;
129 135
130static int started, wanted; 136static int started, wanted;
131static volatile int nreqs; 137static volatile int nreqs;
132static int max_outstanding = 1<<30;
133static int respipe [2]; 138static int respipe [2];
134 139
135#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) 140#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
136# define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 141# define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
137#else 142#else
138# define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER 143# define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
139#endif 144#endif
145
146#define LOCK(mutex) pthread_mutex_lock (&(mutex))
147#define UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
148
149/* worker threasd management */
150static pthread_mutex_t wrklock = AIO_MUTEX_INIT;
151
152typedef struct worker {
153 /* locked by wrklock */
154 struct worker *prev, *next;
155
156 pthread_t tid;
157
158 /* locked by reslock, reqlock or wrklock */
159 aio_req req; /* currently processed request */
160 void *dbuf;
161 DIR *dirp;
162} worker;
163
164static worker wrk_first = { &wrk_first, &wrk_first, 0 };
165
166static void worker_clear (worker *wrk)
167{
168 if (wrk->dirp)
169 {
170 closedir (wrk->dirp);
171 wrk->dirp = 0;
172 }
173
174 if (wrk->dbuf)
175 {
176 free (wrk->dbuf);
177 wrk->dbuf = 0;
178 }
179}
180
181static void worker_free (worker *wrk)
182{
183 wrk->next->prev = wrk->prev;
184 wrk->prev->next = wrk->next;
185
186 free (wrk);
187}
140 188
141static pthread_mutex_t reslock = AIO_MUTEX_INIT; 189static pthread_mutex_t reslock = AIO_MUTEX_INIT;
142static pthread_mutex_t reqlock = AIO_MUTEX_INIT; 190static pthread_mutex_t reqlock = AIO_MUTEX_INIT;
143static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; 191static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER;
144 192
194 } 242 }
195 243
196 abort (); 244 abort ();
197} 245}
198 246
247static int poll_cb ();
199static void req_invoke (aio_req req); 248static void req_invoke (aio_req req);
200static void req_free (aio_req req); 249static void req_free (aio_req req);
250static void req_cancel (aio_req req);
201 251
202/* must be called at most once */ 252/* must be called at most once */
203static SV *req_sv (aio_req req, const char *klass) 253static SV *req_sv (aio_req req, const char *klass)
204{ 254{
205 if (!req->self) 255 if (!req->self)
274 fd_set rfd; 324 fd_set rfd;
275 325
276 while (nreqs) 326 while (nreqs)
277 { 327 {
278 int size; 328 int size;
279#if !(__i386 || __x86_64) /* safe without sempahore on this archs */ 329#if !(__i386 || __x86_64) /* safe without sempahore on these archs */
280 pthread_mutex_lock (&reslock); 330 LOCK (reslock);
281#endif 331#endif
282 size = res_queue.size; 332 size = res_queue.size;
283#if !(__i386 || __x86_64) /* safe without sempahore on this archs */ 333#if !(__i386 || __x86_64) /* safe without sempahore on these archs */
284 pthread_mutex_unlock (&reslock); 334 UNLOCK (reslock);
285#endif 335#endif
286 336
287 if (size) 337 if (size)
288 return; 338 return;
289 339
313 { 363 {
314 SV *rv = &PL_sv_undef; 364 SV *rv = &PL_sv_undef;
315 365
316 if (req->result >= 0) 366 if (req->result >= 0)
317 { 367 {
368 int i;
318 char *buf = req->data2ptr; 369 char *buf = req->data2ptr;
319 AV *av = newAV (); 370 AV *av = newAV ();
320 371
321 while (req->result) 372 av_extend (av, req->result - 1);
373
374 for (i = 0; i < req->result; ++i)
322 { 375 {
323 SV *sv = newSVpv (buf, 0); 376 SV *sv = newSVpv (buf, 0);
324 377
325 av_push (av, sv); 378 av_store (av, i, sv);
326 buf += SvCUR (sv) + 1; 379 buf += SvCUR (sv) + 1;
327 req->result--;
328 } 380 }
329 381
330 rv = sv_2mortal (newRV_noinc ((SV *)av)); 382 rv = sv_2mortal (newRV_noinc ((SV *)av));
331 } 383 }
332 384
416 SvREFCNT_dec (req->fh); 468 SvREFCNT_dec (req->fh);
417 SvREFCNT_dec (req->fh2); 469 SvREFCNT_dec (req->fh2);
418 SvREFCNT_dec (req->callback); 470 SvREFCNT_dec (req->callback);
419 Safefree (req->statdata); 471 Safefree (req->statdata);
420 472
421 if (req->type == REQ_READDIR && req->result >= 0) 473 if (req->type == REQ_READDIR)
422 free (req->data2ptr); 474 free (req->data2ptr);
423 475
424 Safefree (req); 476 Safefree (req);
425} 477}
426 478
479static void req_cancel_subs (aio_req grp)
480{
481 aio_req sub;
482
483 if (grp->type != REQ_GROUP)
484 return;
485
486 SvREFCNT_dec (grp->fh2);
487 grp->fh2 = 0;
488
489 for (sub = grp->grp_first; sub; sub = sub->grp_next)
490 req_cancel (sub);
491}
492
427static void req_cancel (aio_req req) 493static void req_cancel (aio_req req)
428{ 494{
429 req->flags |= FLAG_CANCELLED; 495 req->flags |= FLAG_CANCELLED;
430 496
431 if (req->type == REQ_GROUP) 497 req_cancel_subs (req);
432 {
433 aio_req sub;
434
435 for (sub = req->grp_first; sub; sub = sub->grp_next)
436 req_cancel (sub);
437 }
438} 498}
439 499
440static int poll_cb () 500static int poll_cb ()
441{ 501{
442 dSP; 502 dSP;
444 int do_croak = 0; 504 int do_croak = 0;
445 aio_req req; 505 aio_req req;
446 506
447 for (;;) 507 for (;;)
448 { 508 {
449 pthread_mutex_lock (&reslock); 509 LOCK (reslock);
450 req = reqq_shift (&res_queue); 510 req = reqq_shift (&res_queue);
451 511
452 if (req) 512 if (req)
453 { 513 {
454 if (!res_queue.size) 514 if (!res_queue.size)
458 while (read (respipe [0], buf, 32) == 32) 518 while (read (respipe [0], buf, 32) == 32)
459 ; 519 ;
460 } 520 }
461 } 521 }
462 522
463 pthread_mutex_unlock (&reslock); 523 UNLOCK (reslock);
464 524
465 if (!req) 525 if (!req)
466 break; 526 break;
467 527
468 --nreqs; 528 --nreqs;
503static void *aio_proc(void *arg); 563static void *aio_proc(void *arg);
504 564
505static void start_thread (void) 565static void start_thread (void)
506{ 566{
507 sigset_t fullsigset, oldsigset; 567 sigset_t fullsigset, oldsigset;
508 pthread_t tid;
509 pthread_attr_t attr; 568 pthread_attr_t attr;
569
570 worker *wrk = calloc (1, sizeof (worker));
571
572 if (!wrk)
573 croak ("unable to allocate worker thread data");
510 574
511 pthread_attr_init (&attr); 575 pthread_attr_init (&attr);
512 pthread_attr_setstacksize (&attr, STACKSIZE); 576 pthread_attr_setstacksize (&attr, STACKSIZE);
513 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); 577 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
514 578
515 sigfillset (&fullsigset); 579 sigfillset (&fullsigset);
580
581 LOCK (wrklock);
516 sigprocmask (SIG_SETMASK, &fullsigset, &oldsigset); 582 sigprocmask (SIG_SETMASK, &fullsigset, &oldsigset);
517 583
518 if (pthread_create (&tid, &attr, aio_proc, 0) == 0) 584 if (pthread_create (&wrk->tid, &attr, aio_proc, (void *)wrk) == 0)
585 {
586 wrk->prev = &wrk_first;
587 wrk->next = wrk_first.next;
588 wrk_first.next->prev = wrk;
589 wrk_first.next = wrk;
519 started++; 590 started++;
591 }
592 else
593 free (wrk);
520 594
521 sigprocmask (SIG_SETMASK, &oldsigset, 0); 595 sigprocmask (SIG_SETMASK, &oldsigset, 0);
596 UNLOCK (wrklock);
522} 597}
523 598
524static void req_send (aio_req req) 599static void req_send (aio_req req)
525{ 600{
526 while (started < wanted && nreqs >= started) 601 while (started < wanted && nreqs >= started)
527 start_thread (); 602 start_thread ();
528 603
529 ++nreqs; 604 ++nreqs;
530 605
531 pthread_mutex_lock (&reqlock); 606 LOCK (reqlock);
532 reqq_push (&req_queue, req); 607 reqq_push (&req_queue, req);
533 pthread_cond_signal (&reqwait); 608 pthread_cond_signal (&reqwait);
534 pthread_mutex_unlock (&reqlock); 609 UNLOCK (reqlock);
535
536 if (nreqs > max_outstanding)
537 for (;;)
538 {
539 poll_cb ();
540
541 if (nreqs <= max_outstanding)
542 break;
543
544 poll_wait ();
545 }
546} 610}
547 611
548static void end_thread (void) 612static void end_thread (void)
549{ 613{
550 aio_req req; 614 aio_req req;
612static ssize_t pread (int fd, void *buf, size_t count, off_t offset) 676static ssize_t pread (int fd, void *buf, size_t count, off_t offset)
613{ 677{
614 ssize_t res; 678 ssize_t res;
615 off_t ooffset; 679 off_t ooffset;
616 680
617 pthread_mutex_lock (&preadwritelock); 681 LOCK (preadwritelock);
618 ooffset = lseek (fd, 0, SEEK_CUR); 682 ooffset = lseek (fd, 0, SEEK_CUR);
619 lseek (fd, offset, SEEK_SET); 683 lseek (fd, offset, SEEK_SET);
620 res = read (fd, buf, count); 684 res = read (fd, buf, count);
621 lseek (fd, ooffset, SEEK_SET); 685 lseek (fd, ooffset, SEEK_SET);
622 pthread_mutex_unlock (&preadwritelock); 686 UNLOCK (preadwritelock);
623 687
624 return res; 688 return res;
625} 689}
626 690
627static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset) 691static ssize_t pwrite (int fd, void *buf, size_t count, off_t offset)
628{ 692{
629 ssize_t res; 693 ssize_t res;
630 off_t ooffset; 694 off_t ooffset;
631 695
632 pthread_mutex_lock (&preadwritelock); 696 LOCK (preadwritelock);
633 ooffset = lseek (fd, 0, SEEK_CUR); 697 ooffset = lseek (fd, 0, SEEK_CUR);
634 lseek (fd, offset, SEEK_SET); 698 lseek (fd, offset, SEEK_SET);
635 res = write (fd, buf, count); 699 res = write (fd, buf, count);
636 lseek (fd, offset, SEEK_SET); 700 lseek (fd, offset, SEEK_SET);
637 pthread_mutex_unlock (&preadwritelock); 701 UNLOCK (preadwritelock);
638 702
639 return res; 703 return res;
640} 704}
641#endif 705#endif
642 706
643#if !HAVE_FDATASYNC 707#if !HAVE_FDATASYNC
644# define fdatasync fsync 708# define fdatasync fsync
645#endif 709#endif
646 710
647#if !HAVE_READAHEAD 711#if !HAVE_READAHEAD
648# define readahead aio_readahead 712# define readahead(fd,offset,count) aio_readahead (fd, offset, count, self)
649 713
650static ssize_t readahead (int fd, off_t offset, size_t count) 714static ssize_t aio_readahead (int fd, off_t offset, size_t count, worker *self)
651{ 715{
652 dBUF; 716 dBUF;
653 717
654 while (count > 0) 718 while (count > 0)
655 { 719 {
658 pread (fd, aio_buf, len, offset); 722 pread (fd, aio_buf, len, offset);
659 offset += len; 723 offset += len;
660 count -= len; 724 count -= len;
661 } 725 }
662 726
663 fBUF;
664
665 errno = 0; 727 errno = 0;
666} 728}
729
667#endif 730#endif
668 731
669#if !HAVE_READDIR_R 732#if !HAVE_READDIR_R
670# define readdir_r aio_readdir_r 733# define readdir_r aio_readdir_r
671 734
674static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res) 737static int readdir_r (DIR *dirp, struct dirent *ent, struct dirent **res)
675{ 738{
676 struct dirent *e; 739 struct dirent *e;
677 int errorno; 740 int errorno;
678 741
679 pthread_mutex_lock (&readdirlock); 742 LOCK (readdirlock);
680 743
681 e = readdir (dirp); 744 e = readdir (dirp);
682 errorno = errno; 745 errorno = errno;
683 746
684 if (e) 747 if (e)
687 strcpy (ent->d_name, e->d_name); 750 strcpy (ent->d_name, e->d_name);
688 } 751 }
689 else 752 else
690 *res = 0; 753 *res = 0;
691 754
692 pthread_mutex_unlock (&readdirlock); 755 UNLOCK (readdirlock);
693 756
694 errno = errorno; 757 errno = errorno;
695 return e ? 0 : -1; 758 return e ? 0 : -1;
696} 759}
697#endif 760#endif
698 761
699/* sendfile always needs emulation */ 762/* sendfile always needs emulation */
700static ssize_t sendfile_ (int ofd, int ifd, off_t offset, size_t count) 763static ssize_t sendfile_ (int ofd, int ifd, off_t offset, size_t count, worker *self)
701{ 764{
702 ssize_t res; 765 ssize_t res;
703 766
704 if (!count) 767 if (!count)
705 return 0; 768 return 0;
782 845
783 offset += cnt; 846 offset += cnt;
784 res += cnt; 847 res += cnt;
785 count -= cnt; 848 count -= cnt;
786 } 849 }
787
788 fBUF;
789 } 850 }
790 851
791 return res; 852 return res;
792} 853}
793 854
794/* read a full directory */ 855/* read a full directory */
795static int scandir_ (const char *path, void **namesp) 856static void scandir_ (aio_req req, worker *self)
796{ 857{
797 DIR *dirp; 858 DIR *dirp;
798 union 859 union
799 { 860 {
800 struct dirent d; 861 struct dirent d;
805 int memlen = 4096; 866 int memlen = 4096;
806 int memofs = 0; 867 int memofs = 0;
807 int res = 0; 868 int res = 0;
808 int errorno; 869 int errorno;
809 870
810 dirp = opendir (path); 871 LOCK (wrklock);
811 if (!dirp) 872 self->dirp = dirp = opendir (req->dataptr);
812 return -1;
813
814 u = malloc (sizeof (*u)); 873 self->dbuf = u = malloc (sizeof (*u));
874 UNLOCK (wrklock);
875
815 names = malloc (memlen); 876 req->data2ptr = names = malloc (memlen);
816 877
817 if (u && names) 878 if (dirp && u && names)
818 for (;;) 879 for (;;)
819 { 880 {
820 errno = 0; 881 errno = 0;
821 readdir_r (dirp, &u->d, &entp); 882 readdir_r (dirp, &u->d, &entp);
822 883
832 res++; 893 res++;
833 894
834 while (memofs + len > memlen) 895 while (memofs + len > memlen)
835 { 896 {
836 memlen *= 2; 897 memlen *= 2;
898 LOCK (wrklock);
837 names = realloc (names, memlen); 899 req->data2ptr = names = realloc (names, memlen);
900 UNLOCK (wrklock);
901
838 if (!names) 902 if (!names)
839 break; 903 break;
840 } 904 }
841 905
842 memcpy (names + memofs, name, len); 906 memcpy (names + memofs, name, len);
843 memofs += len; 907 memofs += len;
844 } 908 }
845 } 909 }
846 910
847 errorno = errno;
848 free (u);
849 closedir (dirp);
850
851 if (errorno) 911 if (errno)
852 {
853 free (names);
854 errno = errorno;
855 res = -1; 912 res = -1;
856 } 913
857 914 req->result = res;
858 *namesp = (void *)names;
859 return res;
860} 915}
861 916
862/*****************************************************************************/ 917/*****************************************************************************/
863 918
864static void *aio_proc (void *thr_arg) 919static void *aio_proc (void *thr_arg)
865{ 920{
866 aio_req req; 921 aio_req req;
867 int type; 922 int type;
923 worker *self = (worker *)thr_arg;
868 924
869 do 925 do
870 { 926 {
871 pthread_mutex_lock (&reqlock); 927 LOCK (reqlock);
872 928
873 for (;;) 929 for (;;)
874 { 930 {
875 req = reqq_shift (&req_queue); 931 self->req = req = reqq_shift (&req_queue);
876 932
877 if (req) 933 if (req)
878 break; 934 break;
879 935
880 pthread_cond_wait (&reqwait, &reqlock); 936 pthread_cond_wait (&reqwait, &reqlock);
881 } 937 }
882 938
883 pthread_mutex_unlock (&reqlock); 939 UNLOCK (reqlock);
884 940
885 errno = 0; /* strictly unnecessary */ 941 errno = 0; /* strictly unnecessary */
886 type = req->type; /* remember type for QUIT check */ 942 type = req->type; /* remember type for QUIT check */
887 943
888 if (!(req->flags & FLAG_CANCELLED)) 944 if (!(req->flags & FLAG_CANCELLED))
890 { 946 {
891 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; 947 case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break;
892 case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; 948 case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break;
893 949
894 case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; 950 case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break;
895 case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length); break; 951 case REQ_SENDFILE: req->result = sendfile_ (req->fd, req->fd2, req->offset, req->length, self); break;
896 952
897 case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break; 953 case REQ_STAT: req->result = stat (req->dataptr, req->statdata); break;
898 case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break; 954 case REQ_LSTAT: req->result = lstat (req->dataptr, req->statdata); break;
899 case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break; 955 case REQ_FSTAT: req->result = fstat (req->fd , req->statdata); break;
900 956
906 case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break; 962 case REQ_LINK: req->result = link (req->data2ptr, req->dataptr); break;
907 case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break; 963 case REQ_SYMLINK: req->result = symlink (req->data2ptr, req->dataptr); break;
908 964
909 case REQ_FDATASYNC: req->result = fdatasync (req->fd); break; 965 case REQ_FDATASYNC: req->result = fdatasync (req->fd); break;
910 case REQ_FSYNC: req->result = fsync (req->fd); break; 966 case REQ_FSYNC: req->result = fsync (req->fd); break;
911 case REQ_READDIR: req->result = scandir_ (req->dataptr, &req->data2ptr); break; 967 case REQ_READDIR: scandir_ (req, self); break;
912 968
913 case REQ_BUSY: 969 case REQ_BUSY:
914 { 970 {
915 struct timeval tv; 971 struct timeval tv;
916 972
930 break; 986 break;
931 } 987 }
932 988
933 req->errorno = errno; 989 req->errorno = errno;
934 990
935 pthread_mutex_lock (&reslock); 991 LOCK (reslock);
936 992
937 if (!reqq_push (&res_queue, req)) 993 if (!reqq_push (&res_queue, req))
938 /* write a dummy byte to the pipe so fh becomes ready */ 994 /* write a dummy byte to the pipe so fh becomes ready */
939 write (respipe [1], &respipe, 1); 995 write (respipe [1], &respipe, 1);
940 996
941 pthread_mutex_unlock (&reslock); 997 self->req = 0;
998 worker_clear (self);
999
1000 UNLOCK (reslock);
942 } 1001 }
943 while (type != REQ_QUIT); 1002 while (type != REQ_QUIT);
944 1003
1004 LOCK (wrklock);
1005 worker_free (self);
1006 UNLOCK (wrklock);
1007
945 return 0; 1008 return 0;
946} 1009}
947 1010
948/*****************************************************************************/ 1011/*****************************************************************************/
949 1012
950static void atfork_prepare (void) 1013static void atfork_prepare (void)
951{ 1014{
952 pthread_mutex_lock (&reqlock); 1015 LOCK (wrklock);
953 pthread_mutex_lock (&reslock); 1016 LOCK (reqlock);
1017 LOCK (reslock);
954#if !HAVE_PREADWRITE 1018#if !HAVE_PREADWRITE
955 pthread_mutex_lock (&preadwritelock); 1019 LOCK (preadwritelock);
956#endif 1020#endif
957#if !HAVE_READDIR_R 1021#if !HAVE_READDIR_R
958 pthread_mutex_lock (&readdirlock); 1022 LOCK (readdirlock);
959#endif 1023#endif
960} 1024}
961 1025
962static void atfork_parent (void) 1026static void atfork_parent (void)
963{ 1027{
964#if !HAVE_READDIR_R 1028#if !HAVE_READDIR_R
965 pthread_mutex_unlock (&readdirlock); 1029 UNLOCK (readdirlock);
966#endif 1030#endif
967#if !HAVE_PREADWRITE 1031#if !HAVE_PREADWRITE
968 pthread_mutex_unlock (&preadwritelock); 1032 UNLOCK (preadwritelock);
969#endif 1033#endif
970 pthread_mutex_unlock (&reslock); 1034 UNLOCK (reslock);
971 pthread_mutex_unlock (&reqlock); 1035 UNLOCK (reqlock);
1036 UNLOCK (wrklock);
972} 1037}
973 1038
974static void atfork_child (void) 1039static void atfork_child (void)
975{ 1040{
976 aio_req prv; 1041 aio_req prv;
977
978 started = 0;
979 1042
980 while (prv = reqq_shift (&req_queue)) 1043 while (prv = reqq_shift (&req_queue))
981 req_free (prv); 1044 req_free (prv);
982 1045
983 while (prv = reqq_shift (&res_queue)) 1046 while (prv = reqq_shift (&res_queue))
984 req_free (prv); 1047 req_free (prv);
985 1048
1049 while (wrk_first.next != &wrk_first)
1050 {
1051 worker *wrk = wrk_first.next;
1052
1053 if (wrk->req)
1054 req_free (wrk->req);
1055
1056 worker_clear (wrk);
1057 worker_free (wrk);
1058 }
1059
1060 started = 0;
1061 nreqs = 0;
1062
986 close (respipe [0]); 1063 close (respipe [0]);
987 close (respipe [1]); 1064 close (respipe [1]);
988 create_pipe (); 1065 create_pipe ();
989 1066
990 atfork_parent (); 1067 atfork_parent ();
1034void 1111void
1035max_parallel (nthreads) 1112max_parallel (nthreads)
1036 int nthreads 1113 int nthreads
1037 PROTOTYPE: $ 1114 PROTOTYPE: $
1038 1115
1039int
1040max_outstanding (nreqs)
1041 int nreqs
1042 PROTOTYPE: $
1043 CODE:
1044 RETVAL = max_outstanding;
1045 max_outstanding = nreqs;
1046
1047void 1116void
1048aio_open (pathname,flags,mode,callback=&PL_sv_undef) 1117aio_open (pathname,flags,mode,callback=&PL_sv_undef)
1049 SV * pathname 1118 SV * pathname
1050 int flags 1119 int flags
1051 int mode 1120 int mode
1422 } 1491 }
1423 } 1492 }
1424} 1493}
1425 1494
1426void 1495void
1496cancel_subs (aio_req_ornot req)
1497 CODE:
1498 req_cancel_subs (req);
1499
1500void
1427result (aio_req grp, ...) 1501result (aio_req grp, ...)
1428 CODE: 1502 CODE:
1429{ 1503{
1430 int i; 1504 int i;
1431 AV *av = newAV (); 1505 AV *av = newAV ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines