ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/State.xs
(Generate patch)

Comparing Coro/Coro/State.xs (file contents):
Revision 1.440 by root, Sat Feb 22 14:12:45 2014 UTC vs.
Revision 1.443 by root, Thu Mar 6 06:40:32 2014 UTC

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...
2599 2602
2600/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */ 2603/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */
2601static void 2604static void
2602slf_destroy (pTHX_ struct coro *coro) 2605slf_destroy (pTHX_ struct coro *coro)
2603{ 2606{
2604 /* this callback is reserved for slf functions needing to do cleanup */ 2607 struct CoroSLF frame = coro->slf_frame;
2605 if (coro->slf_frame.destroy && coro->slf_frame.prepare && !PL_dirty)
2606 coro->slf_frame.destroy (aTHX_ &coro->slf_frame);
2607 2608
2608 /* 2609 /*
2609 * The on_destroy above most likely is from an SLF call. 2610 * The on_destroy below most likely is from an SLF call.
2610 * 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
2611 * the coro, we will have to force-finish it here, otherwise 2612 * the coro, we will have to force-finish it here, otherwise
2612 * cleanup functions cannot call SLF functions. 2613 * cleanup functions cannot call SLF functions.
2613 */ 2614 */
2614 coro->slf_frame.prepare = 0; 2615 coro->slf_frame.prepare = 0;
2616
2617 /* this callback is reserved for slf functions needing to do cleanup */
2618 if (frame.destroy && frame.prepare && !PL_dirty)
2619 frame.destroy (aTHX_ &frame);
2615} 2620}
2616 2621
2617/* 2622/*
2618 * these not obviously related functions are all rolled into one 2623 * these not obviously related functions are all rolled into one
2619 * function to increase chances that they all will call transfer with the same 2624 * function to increase chances that they all will call transfer with the same
2959{ 2964{
2960 AV *av = (AV *)frame->data; 2965 AV *av = (AV *)frame->data;
2961 SV *count_sv = AvARRAY (av)[0]; 2966 SV *count_sv = AvARRAY (av)[0];
2962 SV *coro_hv = SvRV (coro_current); 2967 SV *coro_hv = SvRV (coro_current);
2963 2968
2969 frame->destroy = 0;
2970
2964 /* 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 */
2965 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
2966 return 0; 2977 return 0;
2978 }
2967 else if (SvIVX (count_sv) > 0) 2979 else if (SvIVX (count_sv) > 0)
2968 { 2980 {
2969 frame->destroy = 0;
2970
2971 if (acquire) 2981 if (acquire)
2972 SvIVX (count_sv) = SvIVX (count_sv) - 1; 2982 SvIVX (count_sv) = SvIVX (count_sv) - 1;
2973 else 2983 else
2974 coro_semaphore_adjust (aTHX_ av, 0); 2984 coro_semaphore_adjust (aTHX_ av, 0);
2975 2985

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines