… | |
… | |
221 | |
221 | |
222 | /* process data */ |
222 | /* process data */ |
223 | AV *mainstack; |
223 | AV *mainstack; |
224 | perl_slots *slot; /* basically the saved sp */ |
224 | perl_slots *slot; /* basically the saved sp */ |
225 | |
225 | |
226 | /* data associated with this coroutine (initial args) */ |
226 | AV *args; /* data associated with this coroutine (initial args) */ |
227 | AV *args; |
227 | int refcnt; /* coroutines are refcounted, yes */ |
228 | int refcnt; |
|
|
229 | int flags; /* CF_ flags */ |
228 | int flags; /* CF_ flags */ |
|
|
229 | HV *hv; /* the perl hash associated with this coro, if any */ |
230 | |
230 | |
231 | /* statistics */ |
231 | /* statistics */ |
232 | int usecount; /* number of transfers to this coro */ |
232 | int usecount; /* number of transfers to this coro */ |
233 | |
233 | |
234 | /* coro process data */ |
234 | /* coro process data */ |
235 | int prio; |
235 | int prio; |
236 | SV *throw; |
236 | SV *throw; /* exception to be thrown */ |
237 | |
237 | |
238 | /* async_pool */ |
238 | /* async_pool */ |
239 | SV *saved_deffh; |
239 | SV *saved_deffh; |
240 | |
240 | |
241 | /* linked list */ |
241 | /* linked list */ |
242 | struct coro *next, *prev; |
242 | struct coro *next, *prev; |
243 | HV *hv; /* the perl hash associated with this coro, if any */ |
|
|
244 | }; |
243 | }; |
245 | |
244 | |
246 | typedef struct coro *Coro__State; |
245 | typedef struct coro *Coro__State; |
247 | typedef struct coro *Coro__State_or_hashref; |
246 | typedef struct coro *Coro__State_or_hashref; |
248 | |
247 | |
… | |
… | |
453 | |
452 | |
454 | #define VAR(name,type) PL_ ## name = slot->name; |
453 | #define VAR(name,type) PL_ ## name = slot->name; |
455 | # include "state.h" |
454 | # include "state.h" |
456 | #undef VAR |
455 | #undef VAR |
457 | |
456 | |
|
|
457 | /*hv_store (hv_sig, strpair ("__DIE__" ), SvREFCNT_inc (sv_diehook ), 0);*/ |
|
|
458 | /*hv_store (hv_sig, strpair ("__WARN__"), SvREFCNT_inc (sv_warnhook), 0);*/ |
|
|
459 | |
458 | { |
460 | { |
459 | dSP; |
461 | dSP; |
460 | |
462 | |
461 | CV *cv; |
463 | CV *cv; |
462 | |
464 | |
… | |
… | |
521 | |
523 | |
522 | PUTBACK; |
524 | PUTBACK; |
523 | } |
525 | } |
524 | |
526 | |
525 | /* allocate some space on the context stack for our purposes */ |
527 | /* allocate some space on the context stack for our purposes */ |
|
|
528 | /* we manually unroll here, as usually 2 slots is enough */ |
|
|
529 | if (SLOT_COUNT >= 1) CXINC; |
|
|
530 | if (SLOT_COUNT >= 2) CXINC; |
|
|
531 | if (SLOT_COUNT >= 3) CXINC; |
526 | { |
532 | { |
527 | /* we manually unroll here, as usually 2 slots is enough */ |
|
|
528 | int i; |
533 | int i; |
529 | if (SLOT_COUNT >= 1) CXINC; |
|
|
530 | if (SLOT_COUNT >= 2) CXINC; |
|
|
531 | if (SLOT_COUNT >= 3) CXINC; |
|
|
532 | for (i = 3; i < SLOT_COUNT; ++i) |
534 | for (i = 3; i < SLOT_COUNT; ++i) |
533 | CXINC; |
535 | CXINC; |
534 | |
|
|
535 | cxstack_ix -= SLOT_COUNT; /* undo allocation */ |
|
|
536 | } |
536 | } |
|
|
537 | cxstack_ix -= SLOT_COUNT; /* undo allocation */ |
537 | |
538 | |
538 | c->mainstack = PL_mainstack; |
539 | c->mainstack = PL_mainstack; |
539 | |
540 | |
540 | { |
541 | { |
541 | perl_slots *slot = c->slot = (perl_slots *)(cxstack + cxstack_ix + 1); |
542 | perl_slots *slot = c->slot = (perl_slots *)(cxstack + cxstack_ix + 1); |
… | |
… | |
555 | * allocate various perl stacks. This is an exact copy |
556 | * allocate various perl stacks. This is an exact copy |
556 | * of perl.c:init_stacks, except that it uses less memory |
557 | * of perl.c:init_stacks, except that it uses less memory |
557 | * on the (sometimes correct) assumption that coroutines do |
558 | * on the (sometimes correct) assumption that coroutines do |
558 | * not usually need a lot of stackspace. |
559 | * not usually need a lot of stackspace. |
559 | */ |
560 | */ |
560 | #if CORO_PREFER_PERL_FUNCTIONS |
561 | #if 1 |
561 | # define coro_init_stacks init_stacks |
562 | # define coro_init_stacks init_stacks |
562 | #else |
563 | #else |
563 | static void |
564 | static void |
564 | coro_init_stacks (pTHX) |
565 | coro_init_stacks (pTHX) |
565 | { |
566 | { |
… | |
… | |
685 | PL_curpm = 0; |
686 | PL_curpm = 0; |
686 | PL_curpad = 0; |
687 | PL_curpad = 0; |
687 | PL_localizing = 0; |
688 | PL_localizing = 0; |
688 | PL_dirty = 0; |
689 | PL_dirty = 0; |
689 | PL_restartop = 0; |
690 | PL_restartop = 0; |
690 | SvREFCNT_inc (PL_diehook ); hv_store (hv_sig, strpair ("__DIE__" ), SvREFCNT_inc (sv_diehook ), 0); |
691 | PL_diehook = 0; hv_store (hv_sig, strpair ("__DIE__" ), SvREFCNT_inc (sv_diehook ), 0); |
691 | SvREFCNT_inc (PL_warnhook); hv_store (hv_sig, strpair ("__WARN__"), SvREFCNT_inc (sv_warnhook), 0); |
692 | PL_warnhook = 0; hv_store (hv_sig, strpair ("__WARN__"), SvREFCNT_inc (sv_warnhook), 0); |
692 | |
693 | |
693 | GvSV (PL_defgv) = newSV (0); |
694 | GvSV (PL_defgv) = newSV (0); |
694 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
695 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
695 | GvSV (PL_errgv) = newSV (0); |
696 | GvSV (PL_errgv) = newSV (0); |
696 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
697 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |