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.69 by root, Tue Oct 24 11:57:30 2006 UTC vs.
Revision 1.75 by root, Thu Oct 26 06:44:48 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines