|
|
1 | #if __linux |
|
|
2 | # define _GNU_SOURCE |
|
|
3 | #endif |
|
|
4 | |
1 | #define _REENTRANT 1 |
5 | #define _REENTRANT 1 |
|
|
6 | |
2 | #include <errno.h> |
7 | #include <errno.h> |
3 | |
8 | |
4 | #include "EXTERN.h" |
9 | #include "EXTERN.h" |
5 | #include "perl.h" |
10 | #include "perl.h" |
6 | #include "XSUB.h" |
11 | #include "XSUB.h" |
… | |
… | |
41 | # define NAME_MAX 4096 |
46 | # define NAME_MAX 4096 |
42 | #endif |
47 | #endif |
43 | |
48 | |
44 | #if __ia64 |
49 | #if __ia64 |
45 | # define STACKSIZE 65536 |
50 | # define STACKSIZE 65536 |
|
|
51 | #elif __i386 || __x86_64 /* 16k is unreasonably high :( */ |
|
|
52 | # define STACKSIZE PTHREAD_STACK_MIN |
46 | #else |
53 | #else |
47 | # define STACKSIZE 8192 |
54 | # define STACKSIZE 16384 |
48 | #endif |
55 | #endif |
|
|
56 | |
|
|
57 | /* buffer size for various temporary buffers */ |
|
|
58 | #define AIO_BUFSIZE 65536 |
|
|
59 | |
|
|
60 | #define dBUF \ |
|
|
61 | char *aio_buf = malloc (AIO_BUFSIZE); \ |
|
|
62 | if (!aio_buf) \ |
|
|
63 | return -1; |
|
|
64 | |
|
|
65 | #define fBUF free (aio_buf) |
49 | |
66 | |
50 | enum { |
67 | enum { |
51 | REQ_QUIT, |
68 | REQ_QUIT, |
52 | REQ_OPEN, REQ_CLOSE, |
69 | REQ_OPEN, REQ_CLOSE, |
53 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
70 | REQ_READ, REQ_WRITE, REQ_READAHEAD, |
… | |
… | |
55 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
72 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
56 | REQ_FSYNC, REQ_FDATASYNC, |
73 | REQ_FSYNC, REQ_FDATASYNC, |
57 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
74 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
58 | REQ_READDIR, |
75 | REQ_READDIR, |
59 | REQ_LINK, REQ_SYMLINK, |
76 | REQ_LINK, REQ_SYMLINK, |
|
|
77 | REQ_GROUP, REQ_NOP, |
60 | REQ_SLEEP, |
78 | REQ_SLEEP, |
61 | REQ_GROUP, |
|
|
62 | }; |
79 | }; |
63 | |
80 | |
64 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
81 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
65 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
82 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
66 | |
83 | |
67 | typedef struct aio_cb |
84 | typedef struct aio_cb |
68 | { |
85 | { |
69 | struct aio_cb *volatile next; |
86 | struct aio_cb *volatile next; |
70 | |
|
|
71 | struct aio_cb *grp, *grp_prev, *grp_next, *grp_first; |
|
|
72 | |
|
|
73 | SV *self; /* the perl counterpart of this request, if any */ |
|
|
74 | |
87 | |
75 | SV *data, *callback; |
88 | SV *data, *callback; |
76 | SV *fh, *fh2; |
89 | SV *fh, *fh2; |
77 | void *dataptr, *data2ptr; |
90 | void *dataptr, *data2ptr; |
78 | Stat_t *statdata; |
91 | Stat_t *statdata; |
79 | off_t offset; |
92 | off_t offset; |
80 | size_t length; |
93 | size_t length; |
81 | ssize_t result; |
94 | ssize_t result; |
82 | |
95 | |
|
|
96 | STRLEN dataoffset; |
83 | int type; |
97 | int type; |
84 | int fd, fd2; |
98 | int fd, fd2; |
85 | int errorno; |
99 | int errorno; |
86 | STRLEN dataoffset; |
|
|
87 | mode_t mode; /* open */ |
100 | mode_t mode; /* open */ |
|
|
101 | |
88 | unsigned char cancelled; |
102 | unsigned char flags; |
|
|
103 | unsigned char pri; |
|
|
104 | |
|
|
105 | SV *self; /* the perl counterpart of this request, if any */ |
|
|
106 | struct aio_cb *grp, *grp_prev, *grp_next, *grp_first; |
89 | } aio_cb; |
107 | } aio_cb; |
|
|
108 | |
|
|
109 | enum { |
|
|
110 | FLAG_CANCELLED = 0x01, |
|
|
111 | }; |
90 | |
112 | |
91 | typedef aio_cb *aio_req; |
113 | typedef aio_cb *aio_req; |
92 | typedef aio_cb *aio_req_ornot; |
114 | typedef aio_cb *aio_req_ornot; |
|
|
115 | |
|
|
116 | enum { |
|
|
117 | PRI_MIN = -4, |
|
|
118 | PRI_MAX = 4, |
|
|
119 | |
|
|
120 | DEFAULT_PRI = 0, |
|
|
121 | PRI_BIAS = -PRI_MIN, |
|
|
122 | }; |
|
|
123 | |
|
|
124 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
93 | |
125 | |
94 | static int started, wanted; |
126 | static int started, wanted; |
95 | static volatile int nreqs; |
127 | static volatile int nreqs; |
96 | static int max_outstanding = 1<<30; |
128 | static int max_outstanding = 1<<30; |
97 | static int respipe [2]; |
129 | static int respipe [2]; |
98 | |
130 | |
|
|
131 | #if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP) |
|
|
132 | # define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP |
|
|
133 | #else |
|
|
134 | # define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER |
|
|
135 | #endif |
|
|
136 | |
99 | static pthread_mutex_t reslock = PTHREAD_MUTEX_INITIALIZER; |
137 | static pthread_mutex_t reslock = AIO_MUTEX_INIT; |
100 | static pthread_mutex_t reqlock = PTHREAD_MUTEX_INITIALIZER; |
138 | static pthread_mutex_t reqlock = AIO_MUTEX_INIT; |
101 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
139 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
102 | |
140 | |
103 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
141 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
104 | static volatile aio_req ress, rese; /* queue start, queue end */ |
142 | static volatile aio_req ress, rese; /* queue start, queue end */ |
105 | |
143 | |
… | |
… | |
118 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
156 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
119 | } |
157 | } |
120 | |
158 | |
121 | static aio_req SvAIO_REQ (SV *sv) |
159 | static aio_req SvAIO_REQ (SV *sv) |
122 | { |
160 | { |
|
|
161 | MAGIC *mg; |
|
|
162 | |
123 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
163 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
124 | croak ("object of class " AIO_REQ_KLASS " expected"); |
164 | croak ("object of class " AIO_REQ_KLASS " expected"); |
125 | |
165 | |
126 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
166 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
127 | |
167 | |
128 | return mg ? (aio_req)mg->mg_ptr : 0; |
168 | return mg ? (aio_req)mg->mg_ptr : 0; |
129 | } |
169 | } |
130 | |
170 | |
131 | static void aio_grp_feed (aio_req grp) |
171 | static void aio_grp_feed (aio_req grp) |
132 | { |
172 | { |
133 | while (grp->length < grp->fd2) |
173 | while (grp->length < grp->fd2 && !(grp->flags & FLAG_CANCELLED)) |
134 | { |
174 | { |
135 | int old_len = grp->length; |
175 | int old_len = grp->length; |
136 | |
176 | |
137 | if (grp->fh2 && SvOK (grp->fh2)) |
177 | if (grp->fh2 && SvOK (grp->fh2)) |
138 | { |
178 | { |
… | |
… | |
174 | } |
214 | } |
175 | } |
215 | } |
176 | |
216 | |
177 | static void poll_wait () |
217 | static void poll_wait () |
178 | { |
218 | { |
179 | if (nreqs && !ress) |
|
|
180 | { |
|
|
181 | fd_set rfd; |
219 | fd_set rfd; |
|
|
220 | |
|
|
221 | while (nreqs) |
|
|
222 | { |
|
|
223 | aio_req req; |
|
|
224 | #if !(__i386 || __x86_64) /* safe without sempahore on this archs */ |
|
|
225 | pthread_mutex_lock (&reslock); |
|
|
226 | #endif |
|
|
227 | req = ress; |
|
|
228 | #if !(__i386 || __x86_64) /* safe without sempahore on this archs */ |
|
|
229 | pthread_mutex_unlock (&reslock); |
|
|
230 | #endif |
|
|
231 | |
|
|
232 | if (req) |
|
|
233 | return; |
|
|
234 | |
182 | FD_ZERO(&rfd); |
235 | FD_ZERO(&rfd); |
183 | FD_SET(respipe [0], &rfd); |
236 | FD_SET(respipe [0], &rfd); |
184 | |
237 | |
185 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
238 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
186 | } |
239 | } |
… | |
… | |
189 | static void req_invoke (aio_req req) |
242 | static void req_invoke (aio_req req) |
190 | { |
243 | { |
191 | dSP; |
244 | dSP; |
192 | int errorno = errno; |
245 | int errorno = errno; |
193 | |
246 | |
194 | if (req->cancelled || !SvOK (req->callback)) |
247 | if (req->flags & FLAG_CANCELLED || !SvOK (req->callback)) |
195 | return; |
248 | return; |
196 | |
249 | |
197 | errno = req->errorno; |
250 | errno = req->errorno; |
198 | |
251 | |
199 | ENTER; |
252 | ENTER; |
… | |
… | |
257 | for (i = 0; i <= AvFILL (av); ++i) |
310 | for (i = 0; i <= AvFILL (av); ++i) |
258 | PUSHs (*av_fetch (av, i, 0)); |
311 | PUSHs (*av_fetch (av, i, 0)); |
259 | } |
312 | } |
260 | break; |
313 | break; |
261 | |
314 | |
|
|
315 | case REQ_NOP: |
262 | case REQ_SLEEP: |
316 | case REQ_SLEEP: |
263 | break; |
317 | break; |
264 | |
318 | |
265 | default: |
319 | default: |
266 | PUSHs (sv_2mortal (newSViv (req->result))); |
320 | PUSHs (sv_2mortal (newSViv (req->result))); |
… | |
… | |
318 | Safefree (req); |
372 | Safefree (req); |
319 | } |
373 | } |
320 | |
374 | |
321 | static void req_cancel (aio_req req) |
375 | static void req_cancel (aio_req req) |
322 | { |
376 | { |
323 | req->cancelled = 1; |
377 | req->flags |= FLAG_CANCELLED; |
324 | |
378 | |
325 | if (req->type == REQ_GROUP) |
379 | if (req->type == REQ_GROUP) |
326 | { |
380 | { |
327 | aio_req sub; |
381 | aio_req sub; |
328 | |
382 | |
… | |
… | |
552 | #if !HAVE_READAHEAD |
606 | #if !HAVE_READAHEAD |
553 | # define readahead aio_readahead |
607 | # define readahead aio_readahead |
554 | |
608 | |
555 | static ssize_t readahead (int fd, off_t offset, size_t count) |
609 | static ssize_t readahead (int fd, off_t offset, size_t count) |
556 | { |
610 | { |
557 | char readahead_buf[4096]; |
611 | dBUF; |
558 | |
612 | |
559 | while (count > 0) |
613 | while (count > 0) |
560 | { |
614 | { |
561 | size_t len = count < sizeof (readahead_buf) ? count : sizeof (readahead_buf); |
615 | size_t len = count < AIO_BUFSIZE ? count : AIO_BUFSIZE; |
562 | |
616 | |
563 | pread (fd, readahead_buf, len, offset); |
617 | pread (fd, aio_buf, len, offset); |
564 | offset += len; |
618 | offset += len; |
565 | count -= len; |
619 | count -= len; |
566 | } |
620 | } |
|
|
621 | |
|
|
622 | fBUF; |
567 | |
623 | |
568 | errno = 0; |
624 | errno = 0; |
569 | } |
625 | } |
570 | #endif |
626 | #endif |
571 | |
627 | |
… | |
… | |
657 | #endif |
713 | #endif |
658 | ) |
714 | ) |
659 | ) |
715 | ) |
660 | { |
716 | { |
661 | /* emulate sendfile. this is a major pain in the ass */ |
717 | /* emulate sendfile. this is a major pain in the ass */ |
662 | char buf[4096]; |
718 | dBUF; |
|
|
719 | |
663 | res = 0; |
720 | res = 0; |
664 | |
721 | |
665 | while (count) |
722 | while (count) |
666 | { |
723 | { |
667 | ssize_t cnt; |
724 | ssize_t cnt; |
668 | |
725 | |
669 | cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset); |
726 | cnt = pread (ifd, aio_buf, count > AIO_BUFSIZE ? AIO_BUFSIZE : count, offset); |
670 | |
727 | |
671 | if (cnt <= 0) |
728 | if (cnt <= 0) |
672 | { |
729 | { |
673 | if (cnt && !res) res = -1; |
730 | if (cnt && !res) res = -1; |
674 | break; |
731 | break; |
675 | } |
732 | } |
676 | |
733 | |
677 | cnt = write (ofd, buf, cnt); |
734 | cnt = write (ofd, aio_buf, cnt); |
678 | |
735 | |
679 | if (cnt <= 0) |
736 | if (cnt <= 0) |
680 | { |
737 | { |
681 | if (cnt && !res) res = -1; |
738 | if (cnt && !res) res = -1; |
682 | break; |
739 | break; |
… | |
… | |
684 | |
741 | |
685 | offset += cnt; |
742 | offset += cnt; |
686 | res += cnt; |
743 | res += cnt; |
687 | count -= cnt; |
744 | count -= cnt; |
688 | } |
745 | } |
|
|
746 | |
|
|
747 | fBUF; |
689 | } |
748 | } |
690 | |
749 | |
691 | return res; |
750 | return res; |
692 | } |
751 | } |
693 | |
752 | |
694 | /* read a full directory */ |
753 | /* read a full directory */ |
695 | static int scandir_ (const char *path, void **namesp) |
754 | static int scandir_ (const char *path, void **namesp) |
696 | { |
755 | { |
697 | DIR *dirp = opendir (path); |
756 | DIR *dirp; |
698 | union |
757 | union |
699 | { |
758 | { |
700 | struct dirent d; |
759 | struct dirent d; |
701 | char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; |
760 | char b [offsetof (struct dirent, d_name) + NAME_MAX + 1]; |
702 | } u; |
761 | } *u; |
703 | struct dirent *entp; |
762 | struct dirent *entp; |
704 | char *name, *names; |
763 | char *name, *names; |
705 | int memlen = 4096; |
764 | int memlen = 4096; |
706 | int memofs = 0; |
765 | int memofs = 0; |
707 | int res = 0; |
766 | int res = 0; |
708 | int errorno; |
767 | int errorno; |
709 | |
768 | |
|
|
769 | dirp = opendir (path); |
710 | if (!dirp) |
770 | if (!dirp) |
711 | return -1; |
771 | return -1; |
712 | |
772 | |
|
|
773 | u = malloc (sizeof (*u)); |
713 | names = malloc (memlen); |
774 | names = malloc (memlen); |
714 | |
775 | |
|
|
776 | if (u && names) |
715 | for (;;) |
777 | for (;;) |
716 | { |
778 | { |
|
|
779 | errno = 0; |
717 | errno = 0, readdir_r (dirp, &u.d, &entp); |
780 | readdir_r (dirp, &u->d, &entp); |
718 | |
781 | |
719 | if (!entp) |
782 | if (!entp) |
720 | break; |
783 | break; |
721 | |
784 | |
722 | name = entp->d_name; |
785 | name = entp->d_name; |
723 | |
786 | |
724 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
787 | if (name [0] != '.' || (name [1] && (name [1] != '.' || name [2]))) |
725 | { |
788 | { |
726 | int len = strlen (name) + 1; |
789 | int len = strlen (name) + 1; |
727 | |
790 | |
728 | res++; |
791 | res++; |
729 | |
792 | |
730 | while (memofs + len > memlen) |
793 | while (memofs + len > memlen) |
731 | { |
794 | { |
732 | memlen *= 2; |
795 | memlen *= 2; |
733 | names = realloc (names, memlen); |
796 | names = realloc (names, memlen); |
734 | if (!names) |
797 | if (!names) |
735 | break; |
798 | break; |
736 | } |
799 | } |
737 | |
800 | |
738 | memcpy (names + memofs, name, len); |
801 | memcpy (names + memofs, name, len); |
739 | memofs += len; |
802 | memofs += len; |
740 | } |
803 | } |
741 | } |
804 | } |
742 | |
805 | |
743 | errorno = errno; |
806 | errorno = errno; |
|
|
807 | free (u); |
744 | closedir (dirp); |
808 | closedir (dirp); |
745 | |
809 | |
746 | if (errorno) |
810 | if (errorno) |
747 | { |
811 | { |
748 | free (names); |
812 | free (names); |
… | |
… | |
782 | } |
846 | } |
783 | |
847 | |
784 | pthread_mutex_unlock (&reqlock); |
848 | pthread_mutex_unlock (&reqlock); |
785 | |
849 | |
786 | errno = 0; /* strictly unnecessary */ |
850 | errno = 0; /* strictly unnecessary */ |
787 | |
|
|
788 | if (!req->cancelled) |
|
|
789 | switch (type = req->type) /* remember type for QUIT check */ |
851 | type = req->type; /* remember type for QUIT check */ |
|
|
852 | |
|
|
853 | if (!(req->flags & FLAG_CANCELLED)) |
|
|
854 | switch (type) |
790 | { |
855 | { |
791 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
856 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
792 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
857 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
793 | |
858 | |
794 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
859 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
… | |
… | |
818 | tv.tv_usec = req->fd2; |
883 | tv.tv_usec = req->fd2; |
819 | |
884 | |
820 | req->result = select (0, 0, 0, 0, &tv); |
885 | req->result = select (0, 0, 0, 0, &tv); |
821 | } |
886 | } |
822 | |
887 | |
|
|
888 | case REQ_GROUP: |
|
|
889 | case REQ_NOP: |
823 | case REQ_QUIT: |
890 | case REQ_QUIT: |
824 | break; |
891 | break; |
825 | |
892 | |
826 | default: |
893 | default: |
827 | req->result = ENOSYS; |
894 | req->result = ENOSYS; |
… | |
… | |
911 | atfork_parent (); |
978 | atfork_parent (); |
912 | } |
979 | } |
913 | |
980 | |
914 | #define dREQ \ |
981 | #define dREQ \ |
915 | aio_req req; \ |
982 | aio_req req; \ |
|
|
983 | int req_pri = next_pri; \ |
|
|
984 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
916 | \ |
985 | \ |
917 | if (SvOK (callback) && !SvROK (callback)) \ |
986 | if (SvOK (callback) && !SvROK (callback)) \ |
918 | croak ("callback must be undef or of reference type"); \ |
987 | croak ("callback must be undef or of reference type"); \ |
919 | \ |
988 | \ |
920 | Newz (0, req, 1, aio_cb); \ |
989 | Newz (0, req, 1, aio_cb); \ |
921 | if (!req) \ |
990 | if (!req) \ |
922 | croak ("out of memory during aio_req allocation"); \ |
991 | croak ("out of memory during aio_req allocation"); \ |
923 | \ |
992 | \ |
924 | req->callback = newSVsv (callback) |
993 | req->callback = newSVsv (callback); \ |
|
|
994 | req->pri = req_pri |
925 | |
995 | |
926 | #define REQ_SEND \ |
996 | #define REQ_SEND \ |
927 | req_send (req); \ |
997 | req_send (req); \ |
928 | \ |
998 | \ |
929 | if (GIMME_V != G_VOID) \ |
999 | if (GIMME_V != G_VOID) \ |
… | |
… | |
1204 | SV * callback |
1274 | SV * callback |
1205 | PROTOTYPE: ;$ |
1275 | PROTOTYPE: ;$ |
1206 | PPCODE: |
1276 | PPCODE: |
1207 | { |
1277 | { |
1208 | dREQ; |
1278 | dREQ; |
|
|
1279 | |
1209 | req->type = REQ_GROUP; |
1280 | req->type = REQ_GROUP; |
1210 | req_send (req); |
1281 | req_send (req); |
|
|
1282 | |
1211 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1283 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1212 | } |
1284 | } |
|
|
1285 | |
|
|
1286 | void |
|
|
1287 | aio_nop (callback=&PL_sv_undef) |
|
|
1288 | SV * callback |
|
|
1289 | PPCODE: |
|
|
1290 | { |
|
|
1291 | dREQ; |
|
|
1292 | |
|
|
1293 | req->type = REQ_NOP; |
|
|
1294 | |
|
|
1295 | REQ_SEND; |
|
|
1296 | } |
|
|
1297 | |
|
|
1298 | #if 0 |
|
|
1299 | |
|
|
1300 | void |
|
|
1301 | aio_pri (int pri = DEFAULT_PRI) |
|
|
1302 | CODE: |
|
|
1303 | if (pri < PRI_MIN) pri = PRI_MIN; |
|
|
1304 | if (pri > PRI_MAX) pri = PRI_MAX; |
|
|
1305 | next_pri = pri + PRI_BIAS; |
|
|
1306 | |
|
|
1307 | #endif |
1213 | |
1308 | |
1214 | void |
1309 | void |
1215 | flush () |
1310 | flush () |
1216 | PROTOTYPE: |
1311 | PROTOTYPE: |
1217 | CODE: |
1312 | CODE: |
… | |
… | |
1266 | |
1361 | |
1267 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1362 | MODULE = IO::AIO PACKAGE = IO::AIO::REQ |
1268 | |
1363 | |
1269 | void |
1364 | void |
1270 | cancel (aio_req_ornot req) |
1365 | cancel (aio_req_ornot req) |
1271 | PROTOTYPE: |
|
|
1272 | CODE: |
1366 | CODE: |
1273 | req_cancel (req); |
1367 | req_cancel (req); |
1274 | |
1368 | |
|
|
1369 | void |
|
|
1370 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
|
|
1371 | CODE: |
|
|
1372 | SvREFCNT_dec (req->callback); |
|
|
1373 | req->callback = newSVsv (callback); |
|
|
1374 | |
1275 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1375 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1276 | |
1376 | |
1277 | void |
1377 | void |
1278 | add (aio_req grp, ...) |
1378 | add (aio_req grp, ...) |
1279 | PPCODE: |
1379 | PPCODE: |
1280 | { |
1380 | { |
1281 | int i; |
1381 | int i; |
|
|
1382 | aio_req req; |
1282 | |
1383 | |
1283 | if (grp->fd == 2) |
1384 | if (grp->fd == 2) |
1284 | croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
1385 | croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
1285 | |
1386 | |
1286 | for (i = 1; i < items; ++i ) |
1387 | for (i = 1; i < items; ++i ) |
1287 | { |
1388 | { |
1288 | if (GIMME_V != G_VOID) |
1389 | if (GIMME_V != G_VOID) |
1289 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
1390 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
1290 | |
1391 | |
1291 | aio_req req = SvAIO_REQ (ST (i)); |
1392 | req = SvAIO_REQ (ST (i)); |
1292 | |
1393 | |
1293 | if (req) |
1394 | if (req) |
1294 | { |
1395 | { |
1295 | ++grp->length; |
1396 | ++grp->length; |
1296 | req->grp = grp; |
1397 | req->grp = grp; |
… | |
… | |
1319 | SvREFCNT_dec (grp->data); |
1420 | SvREFCNT_dec (grp->data); |
1320 | grp->data = (SV *)av; |
1421 | grp->data = (SV *)av; |
1321 | } |
1422 | } |
1322 | |
1423 | |
1323 | void |
1424 | void |
1324 | lock (aio_req grp) |
|
|
1325 | CODE: |
|
|
1326 | ++grp->length; |
|
|
1327 | |
|
|
1328 | void |
|
|
1329 | unlock (aio_req grp) |
|
|
1330 | CODE: |
|
|
1331 | aio_grp_dec (grp); |
|
|
1332 | |
|
|
1333 | void |
|
|
1334 | feeder_limit (aio_req grp, int limit) |
1425 | feed_limit (aio_req grp, int limit) |
1335 | CODE: |
1426 | CODE: |
1336 | grp->fd2 = limit; |
1427 | grp->fd2 = limit; |
1337 | aio_grp_feed (grp); |
1428 | aio_grp_feed (grp); |
1338 | |
1429 | |
1339 | void |
1430 | void |
1340 | set_feeder (aio_req grp, SV *callback=&PL_sv_undef) |
1431 | feed (aio_req grp, SV *callback=&PL_sv_undef) |
1341 | CODE: |
1432 | CODE: |
1342 | { |
1433 | { |
1343 | SvREFCNT_dec (grp->fh2); |
1434 | SvREFCNT_dec (grp->fh2); |
1344 | grp->fh2 = newSVsv (callback); |
1435 | grp->fh2 = newSVsv (callback); |
1345 | |
1436 | |