… | |
… | |
145 | static size_t coro_stacksize = CORO_STACKSIZE; |
145 | static size_t coro_stacksize = CORO_STACKSIZE; |
146 | static struct CoroAPI coroapi; |
146 | static struct CoroAPI coroapi; |
147 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
147 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
148 | static JMPENV *main_top_env; |
148 | static JMPENV *main_top_env; |
149 | static HV *coro_state_stash, *coro_stash; |
149 | static HV *coro_state_stash, *coro_stash; |
150 | static SV *coro_mortal; /* will be freed after next transfer */ |
150 | static volatile SV *coro_mortal; /* will be freed after next transfer */ |
151 | |
151 | |
152 | static GV *irsgv; /* $/ */ |
152 | static GV *irsgv; /* $/ */ |
153 | static GV *stdoutgv; /* *STDOUT */ |
153 | static GV *stdoutgv; /* *STDOUT */ |
154 | static SV *rv_diehook; |
154 | static SV *rv_diehook; |
155 | static SV *rv_warnhook; |
155 | static SV *rv_warnhook; |
… | |
… | |
664 | return rss; |
664 | return rss; |
665 | } |
665 | } |
666 | |
666 | |
667 | /** coroutine stack handling ************************************************/ |
667 | /** coroutine stack handling ************************************************/ |
668 | |
668 | |
|
|
669 | #if 0 |
669 | static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg); |
670 | static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg); |
670 | |
671 | |
671 | /* |
672 | /* |
672 | * This overrides the default magic get method of %SIG elements. |
673 | * This overrides the default magic get method of %SIG elements. |
673 | * The original one doesn't provide for reading back of PL_diehook/PL_warnhook |
674 | * The original one doesn't provide for reading back of PL_diehook/PL_warnhook |
… | |
… | |
678 | * when a schedule happens then, but we ignore this. |
679 | * when a schedule happens then, but we ignore this. |
679 | */ |
680 | */ |
680 | static int |
681 | static int |
681 | coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) |
682 | coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) |
682 | { |
683 | { |
|
|
684 | return orig_sigelem_get (aTHX_ sv, mg); |
683 | const char *s = MgPV_nolen_const (mg); |
685 | const char *s = MgPV_nolen_const (mg); |
684 | |
686 | |
685 | if (*s == '_') |
687 | if (*s == '_') |
686 | { |
688 | { |
687 | if (strEQ (s, "__DIE__" ) && PL_diehook ) return sv_setsv (sv, PL_diehook ), 0; |
689 | if (strEQ (s, "__DIE__" ) && PL_diehook ) return sv_setsv (sv, PL_diehook ), 0; |
688 | if (strEQ (s, "__WARN__") && PL_warnhook) return sv_setsv (sv, PL_warnhook), 0; |
690 | if (strEQ (s, "__WARN__") && PL_warnhook) return sv_setsv (sv, PL_warnhook), 0; |
689 | } |
691 | } |
690 | |
692 | |
691 | return orig_sigelem_get (aTHX_ sv, mg); |
693 | return orig_sigelem_get (aTHX_ sv, mg); |
692 | } |
694 | } |
|
|
695 | #endif |
693 | |
696 | |
694 | static void |
697 | static void |
695 | coro_setup (pTHX_ struct coro *coro) |
698 | coro_setup (pTHX_ struct coro *coro) |
696 | { |
699 | { |
697 | /* |
700 | /* |
… | |
… | |
1117 | /* always use the TRANSFER macro */ |
1120 | /* always use the TRANSFER macro */ |
1118 | static void NOINLINE |
1121 | static void NOINLINE |
1119 | transfer (pTHX_ struct coro *prev, struct coro *next) |
1122 | transfer (pTHX_ struct coro *prev, struct coro *next) |
1120 | { |
1123 | { |
1121 | dSTACKLEVEL; |
1124 | dSTACKLEVEL; |
|
|
1125 | static volatile int has_throw; |
1122 | |
1126 | |
1123 | /* sometimes transfer is only called to set idle_sp */ |
1127 | /* sometimes transfer is only called to set idle_sp */ |
1124 | if (expect_false (!next)) |
1128 | if (expect_false (!next)) |
1125 | { |
1129 | { |
1126 | ((coro_cctx *)prev)->idle_sp = STACKLEVEL; |
1130 | ((coro_cctx *)prev)->idle_sp = STACKLEVEL; |
… | |
… | |
1178 | ++next->usecount; |
1182 | ++next->usecount; |
1179 | |
1183 | |
1180 | if (expect_true (!next->cctx)) |
1184 | if (expect_true (!next->cctx)) |
1181 | next->cctx = cctx_get (aTHX); |
1185 | next->cctx = cctx_get (aTHX); |
1182 | |
1186 | |
|
|
1187 | has_throw = !!next->throw; |
|
|
1188 | |
1183 | if (expect_false (prev__cctx != next->cctx)) |
1189 | if (expect_false (prev__cctx != next->cctx)) |
1184 | { |
1190 | { |
1185 | prev__cctx->top_env = PL_top_env; |
1191 | prev__cctx->top_env = PL_top_env; |
1186 | PL_top_env = next->cctx->top_env; |
1192 | PL_top_env = next->cctx->top_env; |
1187 | coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); |
1193 | coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); |
1188 | } |
1194 | } |
1189 | |
1195 | |
1190 | free_coro_mortal (aTHX); |
1196 | free_coro_mortal (aTHX); |
1191 | UNLOCK; |
1197 | UNLOCK; |
1192 | |
1198 | |
1193 | if (expect_false (prev->throw || next->throw)) |
1199 | if (expect_false (has_throw)) |
1194 | { |
1200 | { |
1195 | struct coro *coro = SvSTATE (coro_current); |
1201 | struct coro *coro = SvSTATE (coro_current); |
1196 | |
1202 | |
1197 | if (coro->throw) |
1203 | if (coro->throw) |
1198 | { |
1204 | { |
… | |
… | |
1530 | #endif |
1536 | #endif |
1531 | BOOT_PAGESIZE; |
1537 | BOOT_PAGESIZE; |
1532 | |
1538 | |
1533 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
1539 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
1534 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
1540 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
1535 | |
1541 | #if 0 |
1536 | orig_sigelem_get = PL_vtbl_sigelem.svt_get; |
1542 | orig_sigelem_get = PL_vtbl_sigelem.svt_get; |
1537 | PL_vtbl_sigelem.svt_get = coro_sigelem_get; |
1543 | PL_vtbl_sigelem.svt_get = coro_sigelem_get; |
1538 | |
1544 | #endif |
1539 | hv_sig = coro_get_hv (aTHX_ "SIG", TRUE); |
1545 | hv_sig = coro_get_hv (aTHX_ "SIG", TRUE); |
1540 | rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); |
1546 | rv_diehook = SvREFCNT_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); |
1541 | rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); |
1547 | rv_warnhook = SvREFCNT_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); |
1542 | |
1548 | |
1543 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
1549 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
1544 | |
1550 | |
1545 | newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); |
1551 | newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); |
1546 | newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); |
1552 | newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); |