… | |
… | |
209 | enum |
209 | enum |
210 | { |
210 | { |
211 | CF_RUNNING = 0x0001, /* coroutine is running */ |
211 | CF_RUNNING = 0x0001, /* coroutine is running */ |
212 | CF_READY = 0x0002, /* coroutine is ready */ |
212 | CF_READY = 0x0002, /* coroutine is ready */ |
213 | CF_NEW = 0x0004, /* has never been switched to */ |
213 | CF_NEW = 0x0004, /* has never been switched to */ |
214 | CF_DESTROYED = 0x0008, /* coroutine data has been freed */ |
214 | CF_ZOMBIE = 0x0008, /* coroutine data has been freed */ |
215 | CF_SUSPENDED = 0x0010, /* coroutine can't be scheduled */ |
215 | CF_SUSPENDED = 0x0010, /* coroutine can't be scheduled */ |
216 | CF_NOCANCEL = 0x0020, /* cannot cancel, set slf_frame.data to 1 (hackish) */ |
216 | CF_NOCANCEL = 0x0020, /* cannot cancel, set slf_frame.data to 1 (hackish) */ |
217 | }; |
217 | }; |
218 | |
218 | |
219 | /* the structure where most of the perl state is stored, overlaid on the cxstack */ |
219 | /* the structure where most of the perl state is stored, overlaid on the cxstack */ |
… | |
… | |
967 | #endif |
967 | #endif |
968 | |
968 | |
969 | /* |
969 | /* |
970 | * This overrides the default magic get method of %SIG elements. |
970 | * This overrides the default magic get method of %SIG elements. |
971 | * The original one doesn't provide for reading back of PL_diehook/PL_warnhook |
971 | * The original one doesn't provide for reading back of PL_diehook/PL_warnhook |
972 | * and instead of trying to save and restore the hash elements, we just provide |
972 | * and instead of trying to save and restore the hash elements (extremely slow), |
973 | * readback here. |
973 | * we just provide our own readback here. |
974 | */ |
974 | */ |
975 | static int |
975 | static int |
976 | coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) |
976 | coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) |
977 | { |
977 | { |
978 | const char *s = MgPV_nolen_const (mg); |
978 | const char *s = MgPV_nolen_const (mg); |
… | |
… | |
1086 | PL_parser = 0; |
1086 | PL_parser = 0; |
1087 | #endif |
1087 | #endif |
1088 | PL_hints = 0; |
1088 | PL_hints = 0; |
1089 | |
1089 | |
1090 | /* recreate the die/warn hooks */ |
1090 | /* recreate the die/warn hooks */ |
1091 | PL_diehook = 0; SvSetMagicSV (*hv_fetch (hv_sig, "__DIE__" , sizeof ("__DIE__" ) - 1, 1), rv_diehook ); |
1091 | PL_diehook = SvREFCNT_inc (rv_diehook); |
1092 | PL_warnhook = 0; SvSetMagicSV (*hv_fetch (hv_sig, "__WARN__", sizeof ("__WARN__") - 1, 1), rv_warnhook); |
1092 | PL_warnhook = SvREFCNT_inc (rv_warnhook); |
1093 | |
1093 | |
1094 | GvSV (PL_defgv) = newSV (0); |
1094 | GvSV (PL_defgv) = newSV (0); |
1095 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
1095 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
1096 | GvSV (PL_errgv) = newSV (0); |
1096 | GvSV (PL_errgv) = newSV (0); |
1097 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
1097 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
… | |
… | |
1594 | if (expect_true (prev != next)) |
1594 | if (expect_true (prev != next)) |
1595 | { |
1595 | { |
1596 | if (expect_false (!(prev->flags & (CF_RUNNING | CF_NEW)))) |
1596 | if (expect_false (!(prev->flags & (CF_RUNNING | CF_NEW)))) |
1597 | croak ("Coro::State::transfer called with a blocked prev Coro::State, but can only transfer from running or new states,"); |
1597 | croak ("Coro::State::transfer called with a blocked prev Coro::State, but can only transfer from running or new states,"); |
1598 | |
1598 | |
1599 | if (expect_false (next->flags & (CF_RUNNING | CF_DESTROYED | CF_SUSPENDED))) |
1599 | if (expect_false (next->flags & (CF_RUNNING | CF_ZOMBIE | CF_SUSPENDED))) |
1600 | croak ("Coro::State::transfer called with running, destroyed or suspended next Coro::State, but can only transfer to inactive states,"); |
1600 | croak ("Coro::State::transfer called with running, destroyed or suspended next Coro::State, but can only transfer to inactive states,"); |
1601 | |
1601 | |
1602 | #if !PERL_VERSION_ATLEAST (5,10,0) |
1602 | #if !PERL_VERSION_ATLEAST (5,10,0) |
1603 | if (expect_false (PL_lex_state != LEX_NOTPARSING)) |
1603 | if (expect_false (PL_lex_state != LEX_NOTPARSING)) |
1604 | croak ("Coro::State::transfer called while parsing, but this is not supported in your perl version,"); |
1604 | croak ("Coro::State::transfer called while parsing, but this is not supported in your perl version,"); |
… | |
… | |
1695 | coro_call_on_destroy (pTHX_ struct coro *coro); |
1695 | coro_call_on_destroy (pTHX_ struct coro *coro); |
1696 | |
1696 | |
1697 | static void |
1697 | static void |
1698 | coro_state_destroy (pTHX_ struct coro *coro) |
1698 | coro_state_destroy (pTHX_ struct coro *coro) |
1699 | { |
1699 | { |
1700 | if (coro->flags & CF_DESTROYED) |
1700 | if (coro->flags & CF_ZOMBIE) |
1701 | return; |
1701 | return; |
1702 | |
1702 | |
1703 | slf_destroy (aTHX_ coro); |
1703 | slf_destroy (aTHX_ coro); |
1704 | |
1704 | |
1705 | coro->flags |= CF_DESTROYED; |
1705 | coro->flags |= CF_ZOMBIE; |
1706 | |
1706 | |
1707 | if (coro->flags & CF_READY) |
1707 | if (coro->flags & CF_READY) |
1708 | { |
1708 | { |
1709 | /* reduce nready, as destroying a ready coro effectively unreadies it */ |
1709 | /* reduce nready, as destroying a ready coro effectively unreadies it */ |
1710 | /* alternative: look through all ready queues and remove the coro */ |
1710 | /* alternative: look through all ready queues and remove the coro */ |
… | |
… | |
1889 | struct coro *next = coro_deq (aTHX); |
1889 | struct coro *next = coro_deq (aTHX); |
1890 | |
1890 | |
1891 | if (expect_true (next)) |
1891 | if (expect_true (next)) |
1892 | { |
1892 | { |
1893 | /* cannot transfer to destroyed coros, skip and look for next */ |
1893 | /* cannot transfer to destroyed coros, skip and look for next */ |
1894 | if (expect_false (next->flags & (CF_DESTROYED | CF_SUSPENDED))) |
1894 | if (expect_false (next->flags & (CF_ZOMBIE | CF_SUSPENDED))) |
1895 | SvREFCNT_dec (next->hv); /* coro_nready has already been taken care of by destroy */ |
1895 | SvREFCNT_dec (next->hv); /* coro_nready has already been taken care of by destroy */ |
1896 | else |
1896 | else |
1897 | { |
1897 | { |
1898 | next->flags &= ~CF_READY; |
1898 | next->flags &= ~CF_READY; |
1899 | --coro_nready; |
1899 | --coro_nready; |
… | |
… | |
2135 | coro_push_av (aTHX_ coro->status, G_ARRAY); |
2135 | coro_push_av (aTHX_ coro->status, G_ARRAY); |
2136 | SPAGAIN; |
2136 | SPAGAIN; |
2137 | } |
2137 | } |
2138 | |
2138 | |
2139 | PUTBACK; |
2139 | PUTBACK; |
2140 | call_sv (sv_2mortal (cb), G_VOID | G_DISCARD); |
2140 | call_sv (cb, G_VOID | G_DISCARD); |
2141 | } |
2141 | } |
2142 | } |
2142 | } |
2143 | } |
2143 | } |
2144 | |
2144 | |
2145 | static void |
2145 | static void |
… | |
… | |
3547 | PROTOTYPE: $ |
3547 | PROTOTYPE: $ |
3548 | ALIAS: |
3548 | ALIAS: |
3549 | is_ready = CF_READY |
3549 | is_ready = CF_READY |
3550 | is_running = CF_RUNNING |
3550 | is_running = CF_RUNNING |
3551 | is_new = CF_NEW |
3551 | is_new = CF_NEW |
3552 | is_destroyed = CF_DESTROYED |
3552 | is_destroyed = CF_ZOMBIE |
|
|
3553 | is_zombie = CF_ZOMBIE |
3553 | is_suspended = CF_SUSPENDED |
3554 | is_suspended = CF_SUSPENDED |
3554 | CODE: |
3555 | CODE: |
3555 | RETVAL = boolSV (coro->flags & ix); |
3556 | RETVAL = boolSV (coro->flags & ix); |
3556 | OUTPUT: |
3557 | OUTPUT: |
3557 | RETVAL |
3558 | RETVAL |