… | |
… | |
246 | /* state data */ |
246 | /* state data */ |
247 | struct CoroSLF slf_frame; /* saved slf frame */ |
247 | struct CoroSLF slf_frame; /* saved slf frame */ |
248 | AV *mainstack; |
248 | AV *mainstack; |
249 | perl_slots *slot; /* basically the saved sp */ |
249 | perl_slots *slot; /* basically the saved sp */ |
250 | |
250 | |
|
|
251 | CV *startcv; /* the CV to execute */ |
251 | AV *args; /* data associated with this coroutine (initial args) */ |
252 | AV *args; /* data associated with this coroutine (initial args) */ |
252 | int refcnt; /* coroutines are refcounted, yes */ |
253 | int refcnt; /* coroutines are refcounted, yes */ |
253 | int flags; /* CF_ flags */ |
254 | int flags; /* CF_ flags */ |
254 | HV *hv; /* the perl hash associated with this coro, if any */ |
255 | HV *hv; /* the perl hash associated with this coro, if any */ |
255 | void (*on_destroy)(pTHX_ struct coro *coro); |
256 | void (*on_destroy)(pTHX_ struct coro *coro); |
256 | |
257 | |
257 | /* statistics */ |
258 | /* statistics */ |
258 | int usecount; /* number of transfers to this coro */ |
259 | int usecount; /* number of transfers to this coro */ |
259 | |
260 | |
… | |
… | |
321 | #if PERL_VERSION_ATLEAST (5,10,0) |
322 | #if PERL_VERSION_ATLEAST (5,10,0) |
322 | /* silence stupid and wrong 5.10 warning that I am unable to switch off */ |
323 | /* silence stupid and wrong 5.10 warning that I am unable to switch off */ |
323 | get_hv (name, create); |
324 | get_hv (name, create); |
324 | #endif |
325 | #endif |
325 | return get_hv (name, create); |
326 | return get_hv (name, create); |
|
|
327 | } |
|
|
328 | |
|
|
329 | /* may croak */ |
|
|
330 | INLINE CV * |
|
|
331 | coro_sv_2cv (SV *sv) |
|
|
332 | { |
|
|
333 | HV *st; |
|
|
334 | GV *gvp; |
|
|
335 | return sv_2cv (sv, &st, &gvp, 0); |
326 | } |
336 | } |
327 | |
337 | |
328 | static AV * |
338 | static AV * |
329 | coro_clone_padlist (pTHX_ CV *cv) |
339 | coro_clone_padlist (pTHX_ CV *cv) |
330 | { |
340 | { |
… | |
… | |
1018 | SAVETMPS; |
1028 | SAVETMPS; |
1019 | EXTEND (SP, 3); |
1029 | EXTEND (SP, 3); |
1020 | PUSHMARK (SP); |
1030 | PUSHMARK (SP); |
1021 | PUSHs (&PL_sv_yes); |
1031 | PUSHs (&PL_sv_yes); |
1022 | PUSHs (fullname); |
1032 | PUSHs (fullname); |
1023 | PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); |
1033 | PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); |
1024 | PUTBACK; |
1034 | PUTBACK; |
1025 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1035 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1026 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1036 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1027 | SPAGAIN; |
1037 | SPAGAIN; |
1028 | FREETMPS; |
1038 | FREETMPS; |
… | |
… | |
1435 | |
1445 | |
1436 | coro->slot = 0; |
1446 | coro->slot = 0; |
1437 | } |
1447 | } |
1438 | |
1448 | |
1439 | cctx_destroy (coro->cctx); |
1449 | cctx_destroy (coro->cctx); |
|
|
1450 | SvREFCNT_dec (coro->startcv); |
1440 | SvREFCNT_dec (coro->args); |
1451 | SvREFCNT_dec (coro->args); |
1441 | |
1452 | |
1442 | if (coro->next) coro->next->prev = coro->prev; |
1453 | if (coro->next) coro->next->prev = coro->prev; |
1443 | if (coro->prev) coro->prev->next = coro->next; |
1454 | if (coro->prev) coro->prev->next = coro->next; |
1444 | if (coro == coro_first) coro_first = coro->next; |
1455 | if (coro == coro_first) coro_first = coro->next; |
… | |
… | |
2283 | { |
2294 | { |
2284 | if (items >= 2) |
2295 | if (items >= 2) |
2285 | { |
2296 | { |
2286 | /* callback form */ |
2297 | /* callback form */ |
2287 | AV *av = (AV *)SvRV (arg [0]); |
2298 | AV *av = (AV *)SvRV (arg [0]); |
2288 | HV *st; |
|
|
2289 | GV *gvp; |
|
|
2290 | CV *cb_cv = sv_2cv (arg [1], &st, &gvp, 0); |
2299 | CV *cb_cv = coro_sv_2cv (arg [1]); |
2291 | |
2300 | |
2292 | av_push (av, (SV *)SvREFCNT_inc_NN (cb_cv)); |
2301 | av_push (av, (SV *)SvREFCNT_inc_NN (cb_cv)); |
2293 | |
2302 | |
2294 | if (SvIVX (AvARRAY (av)[0]) > 0) |
2303 | if (SvIVX (AvARRAY (av)[0]) > 0) |
2295 | coro_semaphore_adjust (aTHX_ av, 0); |
2304 | coro_semaphore_adjust (aTHX_ av, 0); |
… | |
… | |
2606 | CODE: |
2615 | CODE: |
2607 | { |
2616 | { |
2608 | struct coro *coro; |
2617 | struct coro *coro; |
2609 | MAGIC *mg; |
2618 | MAGIC *mg; |
2610 | HV *hv; |
2619 | HV *hv; |
|
|
2620 | CV *cb; |
2611 | int i; |
2621 | int i; |
|
|
2622 | |
|
|
2623 | if (items > 1) |
|
|
2624 | { |
|
|
2625 | cb = coro_sv_2cv (ST (1)); |
|
|
2626 | |
|
|
2627 | if (CvISXSUB (cb)) |
|
|
2628 | croak ("Coro::State doesn't support XS functions as coroutine start, caught"); |
|
|
2629 | |
|
|
2630 | if (!CvROOT (cb)) |
|
|
2631 | croak ("Coro::State doesn't support autoloaded or undefined functions as coroutine start, caught"); |
|
|
2632 | } |
2612 | |
2633 | |
2613 | Newz (0, coro, 1, struct coro); |
2634 | Newz (0, coro, 1, struct coro); |
2614 | coro->args = newAV (); |
2635 | coro->args = newAV (); |
2615 | coro->flags = CF_NEW; |
2636 | coro->flags = CF_NEW; |
2616 | |
2637 | |
… | |
… | |
2621 | coro->hv = hv = newHV (); |
2642 | coro->hv = hv = newHV (); |
2622 | mg = sv_magicext ((SV *)hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)coro, 0); |
2643 | mg = sv_magicext ((SV *)hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)coro, 0); |
2623 | mg->mg_flags |= MGf_DUP; |
2644 | mg->mg_flags |= MGf_DUP; |
2624 | RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
2645 | RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
2625 | |
2646 | |
|
|
2647 | if (items > 1) |
|
|
2648 | { |
|
|
2649 | coro->startcv = SvREFCNT_inc_NN (cb); |
|
|
2650 | |
2626 | av_extend (coro->args, items - 1); |
2651 | av_extend (coro->args, items - 1); |
|
|
2652 | av_push (coro->args, SvREFCNT_inc (cb)); |
2627 | for (i = 1; i < items; i++) |
2653 | for (i = 2; i < items; i++) |
2628 | av_push (coro->args, newSVsv (ST (i))); |
2654 | av_push (coro->args, newSVsv (ST (i))); |
|
|
2655 | } |
2629 | } |
2656 | } |
2630 | OUTPUT: |
2657 | OUTPUT: |
2631 | RETVAL |
2658 | RETVAL |
2632 | |
2659 | |
2633 | void |
2660 | void |
… | |
… | |
3188 | |
3215 | |
3189 | void |
3216 | void |
3190 | _register (char *target, char *proto, SV *req) |
3217 | _register (char *target, char *proto, SV *req) |
3191 | CODE: |
3218 | CODE: |
3192 | { |
3219 | { |
3193 | HV *st; |
|
|
3194 | GV *gvp; |
|
|
3195 | CV *req_cv = sv_2cv (req, &st, &gvp, 0); |
3220 | CV *req_cv = coro_sv_2cv (req); |
3196 | /* newXSproto doesn't return the CV on 5.8 */ |
3221 | /* newXSproto doesn't return the CV on 5.8 */ |
3197 | CV *slf_cv = newXS (target, coro_aio_req_xs, __FILE__); |
3222 | CV *slf_cv = newXS (target, coro_aio_req_xs, __FILE__); |
3198 | sv_setpv ((SV *)slf_cv, proto); |
3223 | sv_setpv ((SV *)slf_cv, proto); |
3199 | sv_magicext ((SV *)slf_cv, (SV *)req_cv, CORO_MAGIC_type_aio, 0, 0, 0); |
3224 | sv_magicext ((SV *)slf_cv, (SV *)req_cv, CORO_MAGIC_type_aio, 0, 0, 0); |
3200 | } |
3225 | } |