… | |
… | |
2249 | } |
2249 | } |
2250 | else |
2250 | else |
2251 | { |
2251 | { |
2252 | struct coro *self = SvSTATE_current; |
2252 | struct coro *self = SvSTATE_current; |
2253 | |
2253 | |
|
|
2254 | if (!self) |
|
|
2255 | croak ("Coro::cancel called outside of thread content,"); |
|
|
2256 | |
2254 | /* otherwise we cancel directly, purely for speed reasons |
2257 | /* otherwise we cancel directly, purely for speed reasons |
2255 | * unfortunately, this requires some magic trickery, as |
2258 | * unfortunately, this requires some magic trickery, as |
2256 | * somebody else could cancel us, so we have to fight the cancellation. |
2259 | * somebody else could cancel us, so we have to fight the cancellation. |
2257 | * this is ugly, and hopefully fully worth the extra speed. |
2260 | * this is ugly, and hopefully fully worth the extra speed. |
2258 | * besides, I can't get the slow-but-safe version working... |
2261 | * besides, I can't get the slow-but-safe version working... |
… | |
… | |
2608 | * Since by definition the SLF call will not finish when we destroy |
2611 | * Since by definition the SLF call will not finish when we destroy |
2609 | * the coro, we will have to force-finish it here, otherwise |
2612 | * the coro, we will have to force-finish it here, otherwise |
2610 | * cleanup functions cannot call SLF functions. |
2613 | * cleanup functions cannot call SLF functions. |
2611 | */ |
2614 | */ |
2612 | coro->slf_frame.prepare = 0; |
2615 | coro->slf_frame.prepare = 0; |
2613 | coro->slf_frame.destroy = 0; |
|
|
2614 | |
2616 | |
2615 | /* this callback is reserved for slf functions needing to do cleanup */ |
2617 | /* this callback is reserved for slf functions needing to do cleanup */ |
2616 | if (frame.destroy && frame.prepare && !PL_dirty) |
2618 | if (frame.destroy && frame.prepare && !PL_dirty) |
2617 | frame.destroy (aTHX_ &frame); |
2619 | frame.destroy (aTHX_ &frame); |
2618 | } |
2620 | } |
… | |
… | |
2962 | { |
2964 | { |
2963 | AV *av = (AV *)frame->data; |
2965 | AV *av = (AV *)frame->data; |
2964 | SV *count_sv = AvARRAY (av)[0]; |
2966 | SV *count_sv = AvARRAY (av)[0]; |
2965 | SV *coro_hv = SvRV (coro_current); |
2967 | SV *coro_hv = SvRV (coro_current); |
2966 | |
2968 | |
|
|
2969 | frame->destroy = 0; |
|
|
2970 | |
2967 | /* if we are about to throw, don't actually acquire the lock, just throw */ |
2971 | /* if we are about to throw, don't actually acquire the lock, just throw */ |
2968 | if (CORO_THROW) |
2972 | if (ecb_expect_false (CORO_THROW)) |
|
|
2973 | { |
|
|
2974 | /* we still might be responsible for the semaphore, so wake up others */ |
|
|
2975 | coro_semaphore_adjust (aTHX_ av, 0); |
|
|
2976 | |
2969 | return 0; |
2977 | return 0; |
|
|
2978 | } |
2970 | else if (SvIVX (count_sv) > 0) |
2979 | else if (SvIVX (count_sv) > 0) |
2971 | { |
2980 | { |
2972 | frame->destroy = 0; |
|
|
2973 | |
|
|
2974 | if (acquire) |
2981 | if (acquire) |
2975 | SvIVX (count_sv) = SvIVX (count_sv) - 1; |
2982 | SvIVX (count_sv) = SvIVX (count_sv) - 1; |
2976 | else |
2983 | else |
2977 | coro_semaphore_adjust (aTHX_ av, 0); |
2984 | coro_semaphore_adjust (aTHX_ av, 0); |
2978 | |
2985 | |
… | |
… | |
3438 | |
3445 | |
3439 | PROTOTYPES: DISABLE |
3446 | PROTOTYPES: DISABLE |
3440 | |
3447 | |
3441 | BOOT: |
3448 | BOOT: |
3442 | { |
3449 | { |
|
|
3450 | #define VARx(name,expr,type) if (sizeof (type) < sizeof (expr)) croak ("FATAL: Coro thread context slot '" # name "' too small for this version of perl."); |
|
|
3451 | #include "state.h" |
3443 | #ifdef USE_ITHREADS |
3452 | #ifdef USE_ITHREADS |
3444 | # if CORO_PTHREAD |
3453 | # if CORO_PTHREAD |
3445 | coro_thx = PERL_GET_CONTEXT; |
3454 | coro_thx = PERL_GET_CONTEXT; |
3446 | # endif |
3455 | # endif |
3447 | #endif |
3456 | #endif |