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.439 by root, Tue Nov 19 05:16:01 2013 UTC vs.
Revision 1.444 by root, Thu May 1 08:09:18 2014 UTC

14#include "perliol.h" 14#include "perliol.h"
15 15
16#include "schmorp.h" 16#include "schmorp.h"
17 17
18#define ECB_NO_THREADS 1 18#define ECB_NO_THREADS 1
19#define ECB_NO_LIBM 1
19#include "ecb.h" 20#include "ecb.h"
20 21
21#include <stddef.h> 22#include <stddef.h>
22#include <stdio.h> 23#include <stdio.h>
23#include <errno.h> 24#include <errno.h>
2248 } 2249 }
2249 else 2250 else
2250 { 2251 {
2251 struct coro *self = SvSTATE_current; 2252 struct coro *self = SvSTATE_current;
2252 2253
2254 if (!self)
2255 croak ("Coro::cancel called outside of thread content,");
2256
2253 /* otherwise we cancel directly, purely for speed reasons 2257 /* otherwise we cancel directly, purely for speed reasons
2254 * unfortunately, this requires some magic trickery, as 2258 * unfortunately, this requires some magic trickery, as
2255 * 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.
2256 * this is ugly, and hopefully fully worth the extra speed. 2260 * this is ugly, and hopefully fully worth the extra speed.
2257 * besides, I can't get the slow-but-safe version working... 2261 * besides, I can't get the slow-but-safe version working...
2598 2602
2599/* "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 */
2600static void 2604static void
2601slf_destroy (pTHX_ struct coro *coro) 2605slf_destroy (pTHX_ struct coro *coro)
2602{ 2606{
2603 /* this callback is reserved for slf functions needing to do cleanup */ 2607 struct CoroSLF frame = coro->slf_frame;
2604 if (coro->slf_frame.destroy && coro->slf_frame.prepare && !PL_dirty)
2605 coro->slf_frame.destroy (aTHX_ &coro->slf_frame);
2606 2608
2607 /* 2609 /*
2608 * The on_destroy above most likely is from an SLF call. 2610 * The on_destroy below most likely is from an SLF call.
2609 * 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
2610 * the coro, we will have to force-finish it here, otherwise 2612 * the coro, we will have to force-finish it here, otherwise
2611 * cleanup functions cannot call SLF functions. 2613 * cleanup functions cannot call SLF functions.
2612 */ 2614 */
2613 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);
2614} 2620}
2615 2621
2616/* 2622/*
2617 * these not obviously related functions are all rolled into one 2623 * these not obviously related functions are all rolled into one
2618 * 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
2958{ 2964{
2959 AV *av = (AV *)frame->data; 2965 AV *av = (AV *)frame->data;
2960 SV *count_sv = AvARRAY (av)[0]; 2966 SV *count_sv = AvARRAY (av)[0];
2961 SV *coro_hv = SvRV (coro_current); 2967 SV *coro_hv = SvRV (coro_current);
2962 2968
2969 frame->destroy = 0;
2970
2963 /* 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 */
2964 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
2965 return 0; 2977 return 0;
2978 }
2966 else if (SvIVX (count_sv) > 0) 2979 else if (SvIVX (count_sv) > 0)
2967 { 2980 {
2968 frame->destroy = 0;
2969
2970 if (acquire) 2981 if (acquire)
2971 SvIVX (count_sv) = SvIVX (count_sv) - 1; 2982 SvIVX (count_sv) = SvIVX (count_sv) - 1;
2972 else 2983 else
2973 coro_semaphore_adjust (aTHX_ av, 0); 2984 coro_semaphore_adjust (aTHX_ av, 0);
2974 2985
3434 3445
3435PROTOTYPES: DISABLE 3446PROTOTYPES: DISABLE
3436 3447
3437BOOT: 3448BOOT:
3438{ 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"
3439#ifdef USE_ITHREADS 3452#ifdef USE_ITHREADS
3440# if CORO_PTHREAD 3453# if CORO_PTHREAD
3441 coro_thx = PERL_GET_CONTEXT; 3454 coro_thx = PERL_GET_CONTEXT;
3442# endif 3455# endif
3443#endif 3456#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines