… | |
… | |
55 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
55 | REQ_STAT, REQ_LSTAT, REQ_FSTAT, |
56 | REQ_FSYNC, REQ_FDATASYNC, |
56 | REQ_FSYNC, REQ_FDATASYNC, |
57 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
57 | REQ_UNLINK, REQ_RMDIR, REQ_RENAME, |
58 | REQ_READDIR, |
58 | REQ_READDIR, |
59 | REQ_LINK, REQ_SYMLINK, |
59 | REQ_LINK, REQ_SYMLINK, |
|
|
60 | REQ_GROUP, REQ_NOP, |
60 | REQ_SLEEP, |
61 | REQ_SLEEP, |
61 | REQ_GROUP, |
|
|
62 | }; |
62 | }; |
63 | |
63 | |
64 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
64 | #define AIO_REQ_KLASS "IO::AIO::REQ" |
65 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
65 | #define AIO_GRP_KLASS "IO::AIO::GRP" |
66 | |
66 | |
67 | typedef struct aio_cb |
67 | typedef struct aio_cb |
68 | { |
68 | { |
69 | struct aio_cb *grp, *grp_prev, *grp_next; |
|
|
70 | |
|
|
71 | struct aio_cb *volatile next; |
69 | struct aio_cb *volatile next; |
72 | |
|
|
73 | SV *self; /* the perl counterpart of this request, if any */ |
|
|
74 | |
70 | |
75 | SV *data, *callback; |
71 | SV *data, *callback; |
76 | SV *fh, *fh2; |
72 | SV *fh, *fh2; |
77 | void *dataptr, *data2ptr; |
73 | void *dataptr, *data2ptr; |
78 | Stat_t *statdata; |
74 | Stat_t *statdata; |
79 | off_t offset; |
75 | off_t offset; |
80 | size_t length; |
76 | size_t length; |
81 | ssize_t result; |
77 | ssize_t result; |
82 | |
78 | |
|
|
79 | STRLEN dataoffset; |
83 | int type; |
80 | int type; |
84 | int fd, fd2; |
81 | int fd, fd2; |
85 | int errorno; |
82 | int errorno; |
86 | STRLEN dataoffset; |
|
|
87 | mode_t mode; /* open */ |
83 | mode_t mode; /* open */ |
|
|
84 | |
88 | unsigned char cancelled; |
85 | unsigned char flags; |
|
|
86 | unsigned char pri; |
|
|
87 | |
|
|
88 | SV *self; /* the perl counterpart of this request, if any */ |
|
|
89 | struct aio_cb *grp, *grp_prev, *grp_next, *grp_first; |
89 | } aio_cb; |
90 | } aio_cb; |
|
|
91 | |
|
|
92 | enum { |
|
|
93 | FLAG_CANCELLED = 0x01, |
|
|
94 | }; |
90 | |
95 | |
91 | typedef aio_cb *aio_req; |
96 | typedef aio_cb *aio_req; |
92 | typedef aio_cb *aio_req_ornot; |
97 | typedef aio_cb *aio_req_ornot; |
|
|
98 | |
|
|
99 | enum { |
|
|
100 | PRI_MIN = -4, |
|
|
101 | PRI_MAX = 4, |
|
|
102 | |
|
|
103 | DEFAULT_PRI = 0, |
|
|
104 | PRI_BIAS = -PRI_MIN, |
|
|
105 | }; |
|
|
106 | |
|
|
107 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
93 | |
108 | |
94 | static int started, wanted; |
109 | static int started, wanted; |
95 | static volatile int nreqs; |
110 | static volatile int nreqs; |
96 | static int max_outstanding = 1<<30; |
111 | static int max_outstanding = 1<<30; |
97 | static int respipe [2]; |
112 | static int respipe [2]; |
… | |
… | |
101 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
116 | static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; |
102 | |
117 | |
103 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
118 | static volatile aio_req reqs, reqe; /* queue start, queue end */ |
104 | static volatile aio_req ress, rese; /* queue start, queue end */ |
119 | static volatile aio_req ress, rese; /* queue start, queue end */ |
105 | |
120 | |
|
|
121 | static void req_invoke (aio_req req); |
106 | static void req_free (aio_req req); |
122 | static void req_free (aio_req req); |
107 | |
123 | |
108 | /* must be called at most once */ |
124 | /* must be called at most once */ |
109 | static SV *req_sv (aio_req req, const char *klass) |
125 | static SV *req_sv (aio_req req, const char *klass) |
110 | { |
126 | { |
|
|
127 | if (!req->self) |
|
|
128 | { |
111 | req->self = (SV *)newHV (); |
129 | req->self = (SV *)newHV (); |
112 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
130 | sv_magic (req->self, 0, PERL_MAGIC_ext, (char *)req, 0); |
|
|
131 | } |
113 | |
132 | |
114 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
133 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
115 | } |
134 | } |
116 | |
135 | |
117 | static aio_req SvAIO_REQ (SV *sv) |
136 | static aio_req SvAIO_REQ (SV *sv) |
118 | { |
137 | { |
|
|
138 | MAGIC *mg; |
|
|
139 | |
119 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
140 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
120 | croak ("object of class " AIO_REQ_KLASS " expected"); |
141 | croak ("object of class " AIO_REQ_KLASS " expected"); |
121 | |
142 | |
122 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
143 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
123 | |
144 | |
124 | return mg ? (aio_req)mg->mg_ptr : 0; |
145 | return mg ? (aio_req)mg->mg_ptr : 0; |
125 | } |
146 | } |
126 | |
147 | |
|
|
148 | static void aio_grp_feed (aio_req grp) |
|
|
149 | { |
|
|
150 | while (grp->length < grp->fd2 && !(grp->flags & FLAG_CANCELLED)) |
|
|
151 | { |
|
|
152 | int old_len = grp->length; |
|
|
153 | |
|
|
154 | if (grp->fh2 && SvOK (grp->fh2)) |
|
|
155 | { |
|
|
156 | dSP; |
|
|
157 | |
|
|
158 | ENTER; |
|
|
159 | SAVETMPS; |
|
|
160 | PUSHMARK (SP); |
|
|
161 | XPUSHs (req_sv (grp, AIO_GRP_KLASS)); |
|
|
162 | PUTBACK; |
|
|
163 | call_sv (grp->fh2, G_VOID | G_EVAL); |
|
|
164 | SPAGAIN; |
|
|
165 | FREETMPS; |
|
|
166 | LEAVE; |
|
|
167 | } |
|
|
168 | |
|
|
169 | /* stop if no progress has been made */ |
|
|
170 | if (old_len == grp->length) |
|
|
171 | { |
|
|
172 | SvREFCNT_dec (grp->fh2); |
|
|
173 | grp->fh2 = 0; |
|
|
174 | break; |
|
|
175 | } |
|
|
176 | } |
|
|
177 | } |
|
|
178 | |
|
|
179 | static void aio_grp_dec (aio_req grp) |
|
|
180 | { |
|
|
181 | --grp->length; |
|
|
182 | |
|
|
183 | /* call feeder, if applicable */ |
|
|
184 | aio_grp_feed (grp); |
|
|
185 | |
|
|
186 | /* finish, if done */ |
|
|
187 | if (!grp->length && grp->fd) |
|
|
188 | { |
|
|
189 | req_invoke (grp); |
|
|
190 | req_free (grp); |
|
|
191 | } |
|
|
192 | } |
|
|
193 | |
127 | static void poll_wait () |
194 | static void poll_wait () |
128 | { |
195 | { |
129 | if (nreqs && !ress) |
196 | while (nreqs) |
130 | { |
197 | { |
|
|
198 | aio_req req; |
|
|
199 | pthread_mutex_lock (&reslock); |
|
|
200 | req = ress; |
|
|
201 | pthread_mutex_unlock (&reslock); |
|
|
202 | |
|
|
203 | if (req) |
|
|
204 | return; |
|
|
205 | |
131 | fd_set rfd; |
206 | fd_set rfd; |
132 | FD_ZERO(&rfd); |
207 | FD_ZERO(&rfd); |
133 | FD_SET(respipe [0], &rfd); |
208 | FD_SET(respipe [0], &rfd); |
134 | |
209 | |
135 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
210 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
… | |
… | |
139 | static void req_invoke (aio_req req) |
214 | static void req_invoke (aio_req req) |
140 | { |
215 | { |
141 | dSP; |
216 | dSP; |
142 | int errorno = errno; |
217 | int errorno = errno; |
143 | |
218 | |
144 | if (req->cancelled || !SvOK (req->callback)) |
219 | if (req->flags & FLAG_CANCELLED || !SvOK (req->callback)) |
145 | return; |
220 | return; |
146 | |
221 | |
147 | errno = req->errorno; |
222 | errno = req->errorno; |
148 | |
223 | |
149 | ENTER; |
224 | ENTER; |
|
|
225 | SAVETMPS; |
150 | PUSHMARK (SP); |
226 | PUSHMARK (SP); |
151 | EXTEND (SP, 1); |
227 | EXTEND (SP, 1); |
152 | |
228 | |
153 | switch (req->type) |
229 | switch (req->type) |
154 | { |
230 | { |
… | |
… | |
193 | XPUSHs (sv_2mortal (fh)); |
269 | XPUSHs (sv_2mortal (fh)); |
194 | } |
270 | } |
195 | break; |
271 | break; |
196 | |
272 | |
197 | case REQ_GROUP: |
273 | case REQ_GROUP: |
|
|
274 | req->fd = 2; /* mark group as finished */ |
|
|
275 | |
198 | if (req->data) |
276 | if (req->data) |
199 | { |
277 | { |
200 | int i; |
278 | int i; |
201 | AV *av = (AV *)req->data; |
279 | AV *av = (AV *)req->data; |
202 | |
280 | |
… | |
… | |
204 | for (i = 0; i <= AvFILL (av); ++i) |
282 | for (i = 0; i <= AvFILL (av); ++i) |
205 | PUSHs (*av_fetch (av, i, 0)); |
283 | PUSHs (*av_fetch (av, i, 0)); |
206 | } |
284 | } |
207 | break; |
285 | break; |
208 | |
286 | |
|
|
287 | case REQ_NOP: |
209 | case REQ_SLEEP: |
288 | case REQ_SLEEP: |
210 | break; |
289 | break; |
211 | |
290 | |
212 | default: |
291 | default: |
213 | PUSHs (sv_2mortal (newSViv (req->result))); |
292 | PUSHs (sv_2mortal (newSViv (req->result))); |
… | |
… | |
217 | |
296 | |
218 | PUTBACK; |
297 | PUTBACK; |
219 | call_sv (req->callback, G_VOID | G_EVAL); |
298 | call_sv (req->callback, G_VOID | G_EVAL); |
220 | SPAGAIN; |
299 | SPAGAIN; |
221 | |
300 | |
|
|
301 | FREETMPS; |
|
|
302 | LEAVE; |
|
|
303 | |
|
|
304 | errno = errorno; |
|
|
305 | |
222 | if (SvTRUE (ERRSV)) |
306 | if (SvTRUE (ERRSV)) |
223 | { |
307 | { |
224 | req_free (req); |
308 | req_free (req); |
225 | croak (0); |
309 | croak (0); |
226 | } |
310 | } |
227 | |
|
|
228 | LEAVE; |
|
|
229 | |
|
|
230 | errno = errorno; |
|
|
231 | } |
311 | } |
232 | |
312 | |
233 | static void req_free (aio_req req) |
313 | static void req_free (aio_req req) |
234 | { |
314 | { |
235 | if (req->grp) |
315 | if (req->grp) |
236 | { |
316 | { |
237 | aio_req grp = req->grp; |
317 | aio_req grp = req->grp; |
238 | |
318 | |
239 | /* unlink request */ |
319 | /* unlink request */ |
240 | req->grp_next->grp_prev = req->grp_prev; |
320 | if (req->grp_next) req->grp_next->grp_prev = req->grp_prev; |
241 | req->grp_prev->grp_next = req->grp_next; |
321 | if (req->grp_prev) req->grp_prev->grp_next = req->grp_next; |
242 | |
322 | |
243 | if (grp->grp_next == grp && grp->fd) |
323 | if (grp->grp_first == req) |
244 | { |
324 | grp->grp_first = req->grp_next; |
245 | req_invoke (grp); |
325 | |
246 | req_free (grp); |
326 | aio_grp_dec (grp); |
247 | } |
|
|
248 | } |
327 | } |
249 | |
328 | |
250 | if (req->self) |
329 | if (req->self) |
251 | { |
330 | { |
252 | sv_unmagic (req->self, PERL_MAGIC_ext); |
331 | sv_unmagic (req->self, PERL_MAGIC_ext); |
253 | SvREFCNT_dec (req->self); |
332 | SvREFCNT_dec (req->self); |
254 | } |
333 | } |
255 | |
334 | |
256 | if (req->data) |
|
|
257 | SvREFCNT_dec (req->data); |
335 | SvREFCNT_dec (req->data); |
258 | |
|
|
259 | if (req->fh) |
|
|
260 | SvREFCNT_dec (req->fh); |
336 | SvREFCNT_dec (req->fh); |
261 | |
|
|
262 | if (req->fh2) |
|
|
263 | SvREFCNT_dec (req->fh2); |
337 | SvREFCNT_dec (req->fh2); |
264 | |
|
|
265 | if (req->statdata) |
|
|
266 | Safefree (req->statdata); |
|
|
267 | |
|
|
268 | if (req->callback) |
|
|
269 | SvREFCNT_dec (req->callback); |
338 | SvREFCNT_dec (req->callback); |
|
|
339 | Safefree (req->statdata); |
270 | |
340 | |
271 | if (req->type == REQ_READDIR && req->result >= 0) |
341 | if (req->type == REQ_READDIR && req->result >= 0) |
272 | free (req->data2ptr); |
342 | free (req->data2ptr); |
273 | |
343 | |
274 | Safefree (req); |
344 | Safefree (req); |
275 | } |
345 | } |
276 | |
346 | |
277 | static void req_cancel (aio_req req) |
347 | static void req_cancel (aio_req req) |
278 | { |
348 | { |
279 | req->cancelled = 1; |
349 | req->flags |= FLAG_CANCELLED; |
280 | |
350 | |
281 | if (req->type == REQ_GROUP) |
351 | if (req->type == REQ_GROUP) |
282 | { |
352 | { |
283 | aio_req sub; |
353 | aio_req sub; |
284 | |
354 | |
285 | for (sub = req->grp_next; sub != req; sub = sub->grp_next) |
355 | for (sub = req->grp_first; sub; sub = sub->grp_next) |
286 | req_cancel (sub); |
356 | req_cancel (sub); |
287 | } |
357 | } |
288 | } |
358 | } |
289 | |
359 | |
290 | static int poll_cb () |
360 | static int poll_cb () |
… | |
… | |
317 | pthread_mutex_unlock (&reslock); |
387 | pthread_mutex_unlock (&reslock); |
318 | |
388 | |
319 | if (!req) |
389 | if (!req) |
320 | break; |
390 | break; |
321 | |
391 | |
322 | nreqs--; |
392 | --nreqs; |
323 | |
393 | |
324 | if (req->type == REQ_QUIT) |
394 | if (req->type == REQ_QUIT) |
325 | started--; |
395 | started--; |
326 | else if (req->type == REQ_GROUP && req->grp_next != req) |
396 | else if (req->type == REQ_GROUP && req->length) |
327 | { |
397 | { |
328 | req->fd = 1; /* mark request as delayed */ |
398 | req->fd = 1; /* mark request as delayed */ |
329 | continue; |
399 | continue; |
330 | } |
400 | } |
331 | else |
401 | else |
… | |
… | |
378 | static void req_send (aio_req req) |
448 | static void req_send (aio_req req) |
379 | { |
449 | { |
380 | while (started < wanted && nreqs >= started) |
450 | while (started < wanted && nreqs >= started) |
381 | start_thread (); |
451 | start_thread (); |
382 | |
452 | |
383 | nreqs++; |
453 | ++nreqs; |
384 | |
454 | |
385 | pthread_mutex_lock (&reqlock); |
455 | pthread_mutex_lock (&reqlock); |
386 | |
456 | |
387 | req->next = 0; |
457 | req->next = 0; |
388 | |
458 | |
… | |
… | |
738 | } |
808 | } |
739 | |
809 | |
740 | pthread_mutex_unlock (&reqlock); |
810 | pthread_mutex_unlock (&reqlock); |
741 | |
811 | |
742 | errno = 0; /* strictly unnecessary */ |
812 | errno = 0; /* strictly unnecessary */ |
|
|
813 | type = req->type; /* remember type for QUIT check */ |
743 | |
814 | |
744 | if (!req->cancelled) |
815 | if (!(req->flags & FLAG_CANCELLED)) |
745 | switch (req->type) |
816 | switch (type) |
746 | { |
817 | { |
747 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
818 | case REQ_READ: req->result = pread (req->fd, req->dataptr, req->length, req->offset); break; |
748 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
819 | case REQ_WRITE: req->result = pwrite (req->fd, req->dataptr, req->length, req->offset); break; |
749 | |
820 | |
750 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
821 | case REQ_READAHEAD: req->result = readahead (req->fd, req->offset, req->length); break; |
… | |
… | |
774 | tv.tv_usec = req->fd2; |
845 | tv.tv_usec = req->fd2; |
775 | |
846 | |
776 | req->result = select (0, 0, 0, 0, &tv); |
847 | req->result = select (0, 0, 0, 0, &tv); |
777 | } |
848 | } |
778 | |
849 | |
|
|
850 | case REQ_GROUP: |
|
|
851 | case REQ_NOP: |
779 | case REQ_QUIT: |
852 | case REQ_QUIT: |
780 | break; |
853 | break; |
781 | |
854 | |
782 | default: |
855 | default: |
783 | req->result = ENOSYS; |
856 | req->result = ENOSYS; |
… | |
… | |
867 | atfork_parent (); |
940 | atfork_parent (); |
868 | } |
941 | } |
869 | |
942 | |
870 | #define dREQ \ |
943 | #define dREQ \ |
871 | aio_req req; \ |
944 | aio_req req; \ |
|
|
945 | int req_pri = next_pri; \ |
|
|
946 | next_pri = DEFAULT_PRI + PRI_BIAS; \ |
872 | \ |
947 | \ |
873 | if (SvOK (callback) && !SvROK (callback)) \ |
948 | if (SvOK (callback) && !SvROK (callback)) \ |
874 | croak ("callback must be undef or of reference type"); \ |
949 | croak ("callback must be undef or of reference type"); \ |
875 | \ |
950 | \ |
876 | Newz (0, req, 1, aio_cb); \ |
951 | Newz (0, req, 1, aio_cb); \ |
877 | if (!req) \ |
952 | if (!req) \ |
878 | croak ("out of memory during aio_req allocation"); \ |
953 | croak ("out of memory during aio_req allocation"); \ |
879 | \ |
954 | \ |
880 | req->callback = newSVsv (callback) |
955 | req->callback = newSVsv (callback); \ |
|
|
956 | req->pri = req_pri |
881 | |
957 | |
882 | #define REQ_SEND \ |
958 | #define REQ_SEND \ |
883 | req_send (req); \ |
959 | req_send (req); \ |
884 | \ |
960 | \ |
885 | if (GIMME_V != G_VOID) \ |
961 | if (GIMME_V != G_VOID) \ |
… | |
… | |
1160 | SV * callback |
1236 | SV * callback |
1161 | PROTOTYPE: ;$ |
1237 | PROTOTYPE: ;$ |
1162 | PPCODE: |
1238 | PPCODE: |
1163 | { |
1239 | { |
1164 | dREQ; |
1240 | dREQ; |
|
|
1241 | |
1165 | req->type = REQ_GROUP; |
1242 | req->type = REQ_GROUP; |
1166 | req->grp_next = req; |
|
|
1167 | req->grp_prev = req; |
|
|
1168 | |
|
|
1169 | req_send (req); |
1243 | req_send (req); |
|
|
1244 | |
1170 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1245 | XPUSHs (req_sv (req, AIO_GRP_KLASS)); |
1171 | } |
1246 | } |
|
|
1247 | |
|
|
1248 | void |
|
|
1249 | aio_nop (callback=&PL_sv_undef) |
|
|
1250 | SV * callback |
|
|
1251 | PPCODE: |
|
|
1252 | { |
|
|
1253 | dREQ; |
|
|
1254 | |
|
|
1255 | req->type = REQ_NOP; |
|
|
1256 | |
|
|
1257 | REQ_SEND; |
|
|
1258 | } |
|
|
1259 | |
|
|
1260 | #if 0 |
|
|
1261 | |
|
|
1262 | void |
|
|
1263 | aio_pri (int pri = DEFAULT_PRI) |
|
|
1264 | CODE: |
|
|
1265 | if (pri < PRI_MIN) pri = PRI_MIN; |
|
|
1266 | if (pri > PRI_MAX) pri = PRI_MAX; |
|
|
1267 | next_pri = pri + PRI_BIAS; |
|
|
1268 | |
|
|
1269 | #endif |
1172 | |
1270 | |
1173 | void |
1271 | void |
1174 | flush () |
1272 | flush () |
1175 | PROTOTYPE: |
1273 | PROTOTYPE: |
1176 | CODE: |
1274 | CODE: |
… | |
… | |
1229 | cancel (aio_req_ornot req) |
1327 | cancel (aio_req_ornot req) |
1230 | PROTOTYPE: |
1328 | PROTOTYPE: |
1231 | CODE: |
1329 | CODE: |
1232 | req_cancel (req); |
1330 | req_cancel (req); |
1233 | |
1331 | |
|
|
1332 | void |
|
|
1333 | cb (aio_req_ornot req, SV *callback=&PL_sv_undef) |
|
|
1334 | CODE: |
|
|
1335 | SvREFCNT_dec (req->callback); |
|
|
1336 | req->callback = newSVsv (callback); |
|
|
1337 | |
1234 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1338 | MODULE = IO::AIO PACKAGE = IO::AIO::GRP |
1235 | |
1339 | |
1236 | void |
1340 | void |
1237 | add (aio_req grp, ...) |
1341 | add (aio_req grp, ...) |
1238 | PPCODE: |
1342 | PPCODE: |
1239 | { |
1343 | { |
1240 | int i; |
1344 | int i; |
|
|
1345 | aio_req req; |
|
|
1346 | |
|
|
1347 | if (grp->fd == 2) |
|
|
1348 | croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
1241 | |
1349 | |
1242 | for (i = 1; i < items; ++i ) |
1350 | for (i = 1; i < items; ++i ) |
1243 | { |
1351 | { |
1244 | if (GIMME_V != G_VOID) |
1352 | if (GIMME_V != G_VOID) |
1245 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
1353 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
1246 | |
1354 | |
1247 | aio_req req = SvAIO_REQ (ST (i)); |
1355 | req = SvAIO_REQ (ST (i)); |
1248 | |
1356 | |
1249 | if (req) |
1357 | if (req) |
1250 | { |
1358 | { |
1251 | req->grp_prev = grp; |
1359 | ++grp->length; |
1252 | req->grp_next = grp->grp_next; |
|
|
1253 | grp->grp_next->grp_prev = req; |
|
|
1254 | grp->grp_next = req; |
|
|
1255 | |
|
|
1256 | req->grp = grp; |
1360 | req->grp = grp; |
|
|
1361 | |
|
|
1362 | req->grp_prev = 0; |
|
|
1363 | req->grp_next = grp->grp_first; |
|
|
1364 | |
|
|
1365 | if (grp->grp_first) |
|
|
1366 | grp->grp_first->grp_prev = req; |
|
|
1367 | |
|
|
1368 | grp->grp_first = req; |
1257 | } |
1369 | } |
1258 | } |
1370 | } |
1259 | } |
1371 | } |
1260 | |
1372 | |
1261 | void |
1373 | void |
1262 | result (aio_req grp, ...) |
1374 | result (aio_req grp, ...) |
|
|
1375 | CODE: |
|
|
1376 | { |
|
|
1377 | int i; |
|
|
1378 | AV *av = newAV (); |
|
|
1379 | |
|
|
1380 | for (i = 1; i < items; ++i ) |
|
|
1381 | av_push (av, newSVsv (ST (i))); |
|
|
1382 | |
|
|
1383 | SvREFCNT_dec (grp->data); |
|
|
1384 | grp->data = (SV *)av; |
|
|
1385 | } |
|
|
1386 | |
|
|
1387 | void |
|
|
1388 | feed_limit (aio_req grp, int limit) |
1263 | CODE: |
1389 | CODE: |
1264 | { |
1390 | grp->fd2 = limit; |
1265 | int i; |
1391 | aio_grp_feed (grp); |
1266 | AV *av = newAV (); |
|
|
1267 | |
1392 | |
1268 | if (grp->data) |
1393 | void |
|
|
1394 | feed (aio_req grp, SV *callback=&PL_sv_undef) |
|
|
1395 | CODE: |
|
|
1396 | { |
1269 | SvREFCNT_dec (grp->data); |
1397 | SvREFCNT_dec (grp->fh2); |
|
|
1398 | grp->fh2 = newSVsv (callback); |
1270 | |
1399 | |
1271 | for (i = 1; i < items; ++i ) |
1400 | if (grp->fd2 <= 0) |
1272 | av_push (av, newSVsv (ST (i))); |
1401 | grp->fd2 = 2; |
1273 | |
1402 | |
1274 | grp->data = (SV *)av; |
1403 | aio_grp_feed (grp); |
1275 | } |
1404 | } |
1276 | |
1405 | |