… | |
… | |
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 */ |
… | |
… | |
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 |