… | |
… | |
238 | enum { |
238 | enum { |
239 | CF_RUNNING = 0x0001, /* coroutine is running */ |
239 | CF_RUNNING = 0x0001, /* coroutine is running */ |
240 | CF_READY = 0x0002, /* coroutine is ready */ |
240 | CF_READY = 0x0002, /* coroutine is ready */ |
241 | CF_NEW = 0x0004, /* has never been switched to */ |
241 | CF_NEW = 0x0004, /* has never been switched to */ |
242 | CF_DESTROYED = 0x0008, /* coroutine data has been freed */ |
242 | CF_DESTROYED = 0x0008, /* coroutine data has been freed */ |
|
|
243 | CF_SUSPENDED = 0x0010, /* coroutine can't be scheduled */ |
243 | }; |
244 | }; |
244 | |
245 | |
245 | /* the structure where most of the perl state is stored, overlaid on the cxstack */ |
246 | /* the structure where most of the perl state is stored, overlaid on the cxstack */ |
246 | typedef struct |
247 | typedef struct |
247 | { |
248 | { |
… | |
… | |
1382 | /* TODO: throwing up here is considered harmful */ |
1383 | /* TODO: throwing up here is considered harmful */ |
1383 | |
1384 | |
1384 | if (expect_true (prev != next)) |
1385 | if (expect_true (prev != next)) |
1385 | { |
1386 | { |
1386 | if (expect_false (!(prev->flags & (CF_RUNNING | CF_NEW)))) |
1387 | if (expect_false (!(prev->flags & (CF_RUNNING | CF_NEW)))) |
1387 | croak ("Coro::State::transfer called with a suspended prev Coro::State, but can only transfer from running or new states,"); |
1388 | croak ("Coro::State::transfer called with a blocked prev Coro::State, but can only transfer from running or new states,"); |
1388 | |
1389 | |
1389 | if (expect_false (next->flags & CF_RUNNING)) |
|
|
1390 | croak ("Coro::State::transfer called with running next Coro::State, but can only transfer to inactive states,"); |
|
|
1391 | |
|
|
1392 | if (expect_false (next->flags & CF_DESTROYED)) |
1390 | if (expect_false (next->flags & (CF_RUNNING | CF_DESTROYED | CF_SUSPENDED))) |
1393 | croak ("Coro::State::transfer called with destroyed next Coro::State, but can only transfer to inactive states,"); |
1391 | croak ("Coro::State::transfer called with running, destroyed or suspended next Coro::State, but can only transfer to inactive states,"); |
1394 | |
1392 | |
1395 | #if !PERL_VERSION_ATLEAST (5,10,0) |
1393 | #if !PERL_VERSION_ATLEAST (5,10,0) |
1396 | if (expect_false (PL_lex_state != LEX_NOTPARSING)) |
1394 | if (expect_false (PL_lex_state != LEX_NOTPARSING)) |
1397 | croak ("Coro::State::transfer called while parsing, but this is not supported in your perl version,"); |
1395 | croak ("Coro::State::transfer called while parsing, but this is not supported in your perl version,"); |
1398 | #endif |
1396 | #endif |
… | |
… | |
1705 | if (expect_true (next_sv)) |
1703 | if (expect_true (next_sv)) |
1706 | { |
1704 | { |
1707 | struct coro *next = SvSTATE_hv (next_sv); |
1705 | struct coro *next = SvSTATE_hv (next_sv); |
1708 | |
1706 | |
1709 | /* cannot transfer to destroyed coros, skip and look for next */ |
1707 | /* cannot transfer to destroyed coros, skip and look for next */ |
1710 | if (expect_false (next->flags & CF_DESTROYED)) |
1708 | if (expect_false (next->flags & (CF_DESTROYED | CF_SUSPENDED))) |
1711 | SvREFCNT_dec (next_sv); /* coro_nready has already been taken care of by destroy */ |
1709 | SvREFCNT_dec (next_sv); /* coro_nready has already been taken care of by destroy */ |
1712 | else |
1710 | else |
1713 | { |
1711 | { |
1714 | next->flags &= ~CF_READY; |
1712 | next->flags &= ~CF_READY; |
1715 | --coro_nready; |
1713 | --coro_nready; |
… | |
… | |
3121 | ALIAS: |
3119 | ALIAS: |
3122 | is_ready = CF_READY |
3120 | is_ready = CF_READY |
3123 | is_running = CF_RUNNING |
3121 | is_running = CF_RUNNING |
3124 | is_new = CF_NEW |
3122 | is_new = CF_NEW |
3125 | is_destroyed = CF_DESTROYED |
3123 | is_destroyed = CF_DESTROYED |
|
|
3124 | is_suspended = CF_SUSPENDED |
3126 | CODE: |
3125 | CODE: |
3127 | RETVAL = boolSV (coro->flags & ix); |
3126 | RETVAL = boolSV (coro->flags & ix); |
3128 | OUTPUT: |
3127 | OUTPUT: |
3129 | RETVAL |
3128 | RETVAL |
3130 | |
3129 | |
… | |
… | |
3195 | SV **dst = ix ? (SV **)&self->slot->defav : (SV **)&self->slot->defsv; |
3194 | SV **dst = ix ? (SV **)&self->slot->defav : (SV **)&self->slot->defsv; |
3196 | |
3195 | |
3197 | SV *tmp = *src; *src = *dst; *dst = tmp; |
3196 | SV *tmp = *src; *src = *dst; *dst = tmp; |
3198 | } |
3197 | } |
3199 | |
3198 | |
|
|
3199 | void |
|
|
3200 | cancel (Coro::State self) |
|
|
3201 | CODE: |
|
|
3202 | coro_state_destroy (aTHX_ self); |
|
|
3203 | coro_call_on_destroy (aTHX_ self); /* actually only for Coro objects */ |
|
|
3204 | |
3200 | |
3205 | |
3201 | MODULE = Coro::State PACKAGE = Coro |
3206 | MODULE = Coro::State PACKAGE = Coro |
3202 | |
3207 | |
3203 | BOOT: |
3208 | BOOT: |
3204 | { |
3209 | { |
… | |
… | |
3278 | cede_notself (...) |
3283 | cede_notself (...) |
3279 | CODE: |
3284 | CODE: |
3280 | CORO_EXECUTE_SLF_XS (slf_init_cede_notself); |
3285 | CORO_EXECUTE_SLF_XS (slf_init_cede_notself); |
3281 | |
3286 | |
3282 | void |
3287 | void |
3283 | _cancel (Coro::State self) |
|
|
3284 | CODE: |
|
|
3285 | coro_state_destroy (aTHX_ self); |
|
|
3286 | coro_call_on_destroy (aTHX_ self); |
|
|
3287 | |
|
|
3288 | void |
|
|
3289 | _set_current (SV *current) |
3288 | _set_current (SV *current) |
3290 | PROTOTYPE: $ |
3289 | PROTOTYPE: $ |
3291 | CODE: |
3290 | CODE: |
3292 | SvREFCNT_dec (SvRV (coro_current)); |
3291 | SvREFCNT_dec (SvRV (coro_current)); |
3293 | SvRV_set (coro_current, SvREFCNT_inc_NN (SvRV (current))); |
3292 | SvRV_set (coro_current, SvREFCNT_inc_NN (SvRV (current))); |