… | |
… | |
118 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
118 | return sv_2mortal (sv_bless (newRV_inc (req->self), gv_stashpv (klass, 1))); |
119 | } |
119 | } |
120 | |
120 | |
121 | static aio_req SvAIO_REQ (SV *sv) |
121 | static aio_req SvAIO_REQ (SV *sv) |
122 | { |
122 | { |
|
|
123 | MAGIC *mg; |
|
|
124 | |
123 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
125 | if (!sv_derived_from (sv, AIO_REQ_KLASS) || !SvROK (sv)) |
124 | croak ("object of class " AIO_REQ_KLASS " expected"); |
126 | croak ("object of class " AIO_REQ_KLASS " expected"); |
125 | |
127 | |
126 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
128 | mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
127 | |
129 | |
128 | return mg ? (aio_req)mg->mg_ptr : 0; |
130 | return mg ? (aio_req)mg->mg_ptr : 0; |
129 | } |
131 | } |
130 | |
132 | |
131 | static void aio_grp_feed (aio_req grp) |
133 | static void aio_grp_feed (aio_req grp) |
… | |
… | |
270 | |
272 | |
271 | PUTBACK; |
273 | PUTBACK; |
272 | call_sv (req->callback, G_VOID | G_EVAL); |
274 | call_sv (req->callback, G_VOID | G_EVAL); |
273 | SPAGAIN; |
275 | SPAGAIN; |
274 | |
276 | |
|
|
277 | FREETMPS; |
|
|
278 | LEAVE; |
|
|
279 | |
|
|
280 | errno = errorno; |
|
|
281 | |
275 | if (SvTRUE (ERRSV)) |
282 | if (SvTRUE (ERRSV)) |
276 | { |
283 | { |
277 | req_free (req); |
284 | req_free (req); |
278 | croak (0); |
285 | croak (0); |
279 | } |
286 | } |
280 | |
|
|
281 | FREETMPS; |
|
|
282 | LEAVE; |
|
|
283 | |
|
|
284 | errno = errorno; |
|
|
285 | } |
287 | } |
286 | |
288 | |
287 | static void req_free (aio_req req) |
289 | static void req_free (aio_req req) |
288 | { |
290 | { |
289 | if (req->grp) |
291 | if (req->grp) |
… | |
… | |
1277 | void |
1279 | void |
1278 | add (aio_req grp, ...) |
1280 | add (aio_req grp, ...) |
1279 | PPCODE: |
1281 | PPCODE: |
1280 | { |
1282 | { |
1281 | int i; |
1283 | int i; |
|
|
1284 | aio_req req; |
1282 | |
1285 | |
1283 | if (grp->fd == 2) |
1286 | if (grp->fd == 2) |
1284 | croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
1287 | croak ("cannot add requests to IO::AIO::GRP after the group finished"); |
1285 | |
1288 | |
1286 | for (i = 1; i < items; ++i ) |
1289 | for (i = 1; i < items; ++i ) |
1287 | { |
1290 | { |
1288 | if (GIMME_V != G_VOID) |
1291 | if (GIMME_V != G_VOID) |
1289 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
1292 | XPUSHs (sv_2mortal (newSVsv (ST (i)))); |
1290 | |
1293 | |
1291 | aio_req req = SvAIO_REQ (ST (i)); |
1294 | req = SvAIO_REQ (ST (i)); |
1292 | |
1295 | |
1293 | if (req) |
1296 | if (req) |
1294 | { |
1297 | { |
1295 | ++grp->length; |
1298 | ++grp->length; |
1296 | req->grp = grp; |
1299 | req->grp = grp; |
… | |
… | |
1305 | } |
1308 | } |
1306 | } |
1309 | } |
1307 | } |
1310 | } |
1308 | |
1311 | |
1309 | void |
1312 | void |
|
|
1313 | result (aio_req grp, ...) |
|
|
1314 | CODE: |
|
|
1315 | { |
|
|
1316 | int i; |
|
|
1317 | AV *av = newAV (); |
|
|
1318 | |
|
|
1319 | for (i = 1; i < items; ++i ) |
|
|
1320 | av_push (av, newSVsv (ST (i))); |
|
|
1321 | |
|
|
1322 | SvREFCNT_dec (grp->data); |
|
|
1323 | grp->data = (SV *)av; |
|
|
1324 | } |
|
|
1325 | |
|
|
1326 | void |
1310 | lock (aio_req grp) |
1327 | lock (aio_req grp) |
1311 | CODE: |
1328 | CODE: |
1312 | ++grp->length; |
1329 | ++grp->length; |
1313 | |
1330 | |
1314 | void |
1331 | void |