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.447 by root, Tue Oct 14 21:53:32 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>
1137 1138
1138 GvSV (PL_defgv) = newSV (0); 1139 GvSV (PL_defgv) = newSV (0);
1139 GvAV (PL_defgv) = coro->args; coro->args = 0; 1140 GvAV (PL_defgv) = coro->args; coro->args = 0;
1140 GvSV (PL_errgv) = newSV (0); 1141 GvSV (PL_errgv) = newSV (0);
1141 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 1142 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
1142 GvHV (PL_hintgv) = 0; 1143 GvHV (PL_hintgv) = newHV ();
1144#if PERL_VERSION_ATLEAST (5,10,0)
1145 hv_magic (GvHV (PL_hintgv), 0, PERL_MAGIC_hints);
1146#endif
1143 PL_rs = newSVsv (GvSV (irsgv)); 1147 PL_rs = newSVsv (GvSV (irsgv));
1144 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); 1148 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv);
1145 1149
1146 { 1150 {
1147 dSP; 1151 dSP;
1926 1930
1927 ENTER; 1931 ENTER;
1928 SAVETMPS; 1932 SAVETMPS;
1929 1933
1930 PUSHMARK (SP); 1934 PUSHMARK (SP);
1931 XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught", 0))); 1935 XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::idle blocked itself - did you try to block inside an event loop callback? Caught", 0)));
1932 PUTBACK; 1936 PUTBACK;
1933 call_pv ("Carp::confess", G_VOID | G_DISCARD); 1937 call_pv ("Carp::confess", G_VOID | G_DISCARD);
1934 1938
1935 FREETMPS; 1939 FREETMPS;
1936 LEAVE; 1940 LEAVE;
2247 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv); 2251 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv);
2248 } 2252 }
2249 else 2253 else
2250 { 2254 {
2251 struct coro *self = SvSTATE_current; 2255 struct coro *self = SvSTATE_current;
2256
2257 if (!self)
2258 croak ("Coro::cancel called outside of thread content,");
2252 2259
2253 /* otherwise we cancel directly, purely for speed reasons 2260 /* otherwise we cancel directly, purely for speed reasons
2254 * unfortunately, this requires some magic trickery, as 2261 * unfortunately, this requires some magic trickery, as
2255 * somebody else could cancel us, so we have to fight the cancellation. 2262 * somebody else could cancel us, so we have to fight the cancellation.
2256 * this is ugly, and hopefully fully worth the extra speed. 2263 * this is ugly, and hopefully fully worth the extra speed.
2598 2605
2599/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */ 2606/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */
2600static void 2607static void
2601slf_destroy (pTHX_ struct coro *coro) 2608slf_destroy (pTHX_ struct coro *coro)
2602{ 2609{
2603 /* this callback is reserved for slf functions needing to do cleanup */ 2610 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 2611
2607 /* 2612 /*
2608 * The on_destroy above most likely is from an SLF call. 2613 * The on_destroy below most likely is from an SLF call.
2609 * Since by definition the SLF call will not finish when we destroy 2614 * Since by definition the SLF call will not finish when we destroy
2610 * the coro, we will have to force-finish it here, otherwise 2615 * the coro, we will have to force-finish it here, otherwise
2611 * cleanup functions cannot call SLF functions. 2616 * cleanup functions cannot call SLF functions.
2612 */ 2617 */
2613 coro->slf_frame.prepare = 0; 2618 coro->slf_frame.prepare = 0;
2619
2620 /* this callback is reserved for slf functions needing to do cleanup */
2621 if (frame.destroy && frame.prepare && !PL_dirty)
2622 frame.destroy (aTHX_ &frame);
2614} 2623}
2615 2624
2616/* 2625/*
2617 * these not obviously related functions are all rolled into one 2626 * these not obviously related functions are all rolled into one
2618 * function to increase chances that they all will call transfer with the same 2627 * function to increase chances that they all will call transfer with the same
2958{ 2967{
2959 AV *av = (AV *)frame->data; 2968 AV *av = (AV *)frame->data;
2960 SV *count_sv = AvARRAY (av)[0]; 2969 SV *count_sv = AvARRAY (av)[0];
2961 SV *coro_hv = SvRV (coro_current); 2970 SV *coro_hv = SvRV (coro_current);
2962 2971
2972 frame->destroy = 0;
2973
2963 /* if we are about to throw, don't actually acquire the lock, just throw */ 2974 /* if we are about to throw, don't actually acquire the lock, just throw */
2964 if (CORO_THROW) 2975 if (ecb_expect_false (CORO_THROW))
2976 {
2977 /* we still might be responsible for the semaphore, so wake up others */
2978 coro_semaphore_adjust (aTHX_ av, 0);
2979
2965 return 0; 2980 return 0;
2981 }
2966 else if (SvIVX (count_sv) > 0) 2982 else if (SvIVX (count_sv) > 0)
2967 { 2983 {
2968 frame->destroy = 0;
2969
2970 if (acquire) 2984 if (acquire)
2971 SvIVX (count_sv) = SvIVX (count_sv) - 1; 2985 SvIVX (count_sv) = SvIVX (count_sv) - 1;
2972 else 2986 else
2973 coro_semaphore_adjust (aTHX_ av, 0); 2987 coro_semaphore_adjust (aTHX_ av, 0);
2974 2988
3434 3448
3435PROTOTYPES: DISABLE 3449PROTOTYPES: DISABLE
3436 3450
3437BOOT: 3451BOOT:
3438{ 3452{
3453#define VARx(name,expr,type) if (sizeof (type) < sizeof (expr)) croak ("FATAL: Coro thread context slot '" # name "' too small for this version of perl.");
3454#include "state.h"
3439#ifdef USE_ITHREADS 3455#ifdef USE_ITHREADS
3440# if CORO_PTHREAD 3456# if CORO_PTHREAD
3441 coro_thx = PERL_GET_CONTEXT; 3457 coro_thx = PERL_GET_CONTEXT;
3442# endif 3458# endif
3443#endif 3459#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines