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.441 by root, Tue Mar 4 05:07:44 2014 UTC vs.
Revision 1.449 by root, Sun Jun 21 17:02:49 2015 UTC

42# define PadlistNAMES(pl) (*PadlistARRAY (pl)) 42# define PadlistNAMES(pl) (*PadlistARRAY (pl))
43# define PadARRAY AvARRAY 43# define PadARRAY AvARRAY
44# define PadMAX AvFILLp 44# define PadMAX AvFILLp
45# define newPADLIST(var) ((var) = newAV (), av_extend (var, 1)) 45# define newPADLIST(var) ((var) = newAV (), av_extend (var, 1))
46#endif 46#endif
47#ifndef PadnamelistREFCNT
48# define PadnamelistREFCNT(pnl) SvREFCNT (pnl)
49#endif
50#ifndef PadnamelistREFCNT_dec
51# define PadnamelistREFCNT_dec(pnl) SvREFCNT_dec (pnl)
52#endif
47 53
48/* 5.19.something has replaced SVt_BIND by SVt_INVLIST */ 54/* 5.19.something has replaced SVt_BIND by SVt_INVLIST */
49/* we just alias it to SVt_IV, as that is sufficient for swap_sv for now */ 55/* we just alias it to SVt_IV, as that is sufficient for swap_sv for now */
50#if PERL_VERSION_ATLEAST(5,19,0) 56#if PERL_VERSION_ATLEAST(5,19,0)
51# define SVt_BIND SVt_IV 57# define SVt_BIND SVt_IV
517ecb_inline PADLIST * 523ecb_inline PADLIST *
518coro_derive_padlist (pTHX_ CV *cv) 524coro_derive_padlist (pTHX_ CV *cv)
519{ 525{
520 PADLIST *padlist = CvPADLIST (cv); 526 PADLIST *padlist = CvPADLIST (cv);
521 PADLIST *newpadlist; 527 PADLIST *newpadlist;
528 PADNAMELIST *padnames;
522 PAD *newpad; 529 PAD *newpad;
523 PADOFFSET off = PadlistMAX (padlist) + 1; 530 PADOFFSET off = PadlistMAX (padlist) + 1;
524 531
525#if NEWPADAPI 532#if NEWPADAPI
526 533
553 AvREAL_off (newpadlist); 560 AvREAL_off (newpadlist);
554#endif 561#endif
555 562
556 /* Already extended to 2 elements by newPADLIST. */ 563 /* Already extended to 2 elements by newPADLIST. */
557 PadlistMAX (newpadlist) = 1; 564 PadlistMAX (newpadlist) = 1;
558 PadlistNAMES (newpadlist) = (PADNAMELIST *)SvREFCNT_inc_NN (PadlistNAMES (padlist)); 565
566 padnames = PadlistNAMES (padlist);
567 ++PadnamelistREFCNT (padnames);
568 PadlistNAMES (newpadlist) = padnames;
569
559 PadlistARRAY (newpadlist)[1] = newpad; 570 PadlistARRAY (newpadlist)[1] = newpad;
560 571
561 return newpadlist; 572 return newpadlist;
562} 573}
563 574
584 PadMAX (pad) = -1; 595 PadMAX (pad) = -1;
585 SvREFCNT_dec (pad); 596 SvREFCNT_dec (pad);
586 } 597 }
587 } 598 }
588 599
589 SvREFCNT_dec (PadlistNAMES (padlist)); 600 PadnamelistREFCNT_dec (PadlistNAMES (padlist));
590 601
591#if NEWPADAPI 602#if NEWPADAPI
592 Safefree (PadlistARRAY (padlist)); 603 Safefree (PadlistARRAY (padlist));
593 Safefree (padlist); 604 Safefree (padlist);
594#else 605#else
1138 1149
1139 GvSV (PL_defgv) = newSV (0); 1150 GvSV (PL_defgv) = newSV (0);
1140 GvAV (PL_defgv) = coro->args; coro->args = 0; 1151 GvAV (PL_defgv) = coro->args; coro->args = 0;
1141 GvSV (PL_errgv) = newSV (0); 1152 GvSV (PL_errgv) = newSV (0);
1142 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 1153 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
1143 GvHV (PL_hintgv) = 0; 1154 GvHV (PL_hintgv) = newHV ();
1155#if PERL_VERSION_ATLEAST (5,10,0)
1156 hv_magic (GvHV (PL_hintgv), 0, PERL_MAGIC_hints);
1157#endif
1144 PL_rs = newSVsv (GvSV (irsgv)); 1158 PL_rs = newSVsv (GvSV (irsgv));
1145 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv); 1159 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv);
1146 1160
1147 { 1161 {
1148 dSP; 1162 dSP;
1330 1344
1331 if (PL_curcop != &PL_compiling) 1345 if (PL_curcop != &PL_compiling)
1332 { 1346 {
1333 SV **cb; 1347 SV **cb;
1334 1348
1335 if (oldcxix != cxstack_ix && cctx_current->flags & CC_TRACE_SUB) 1349 if (oldcxix != cxstack_ix && cctx_current->flags & CC_TRACE_SUB && cxstack_ix >= 0)
1336 { 1350 {
1337 PERL_CONTEXT *cx = &cxstack[cxstack_ix]; 1351 PERL_CONTEXT *cx = &cxstack[cxstack_ix];
1338 1352
1339 if (CxTYPE (cx) == CXt_SUB && oldcxix < cxstack_ix) 1353 if (CxTYPE (cx) == CXt_SUB && oldcxix < cxstack_ix)
1340 { 1354 {
1927 1941
1928 ENTER; 1942 ENTER;
1929 SAVETMPS; 1943 SAVETMPS;
1930 1944
1931 PUSHMARK (SP); 1945 PUSHMARK (SP);
1932 XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::IDLE blocked itself - did you try to block inside an event loop callback? Caught", 0))); 1946 XPUSHs (sv_2mortal (newSVpv ("FATAL: $Coro::idle blocked itself - did you try to block inside an event loop callback? Caught", 0)));
1933 PUTBACK; 1947 PUTBACK;
1934 call_pv ("Carp::confess", G_VOID | G_DISCARD); 1948 call_pv ("Carp::confess", G_VOID | G_DISCARD);
1935 1949
1936 FREETMPS; 1950 FREETMPS;
1937 LEAVE; 1951 LEAVE;
2248 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv); 2262 slf_init_terminate_cancel_common (aTHX_ frame, coro_hv);
2249 } 2263 }
2250 else 2264 else
2251 { 2265 {
2252 struct coro *self = SvSTATE_current; 2266 struct coro *self = SvSTATE_current;
2267
2268 if (!self)
2269 croak ("Coro::cancel called outside of thread content,");
2253 2270
2254 /* otherwise we cancel directly, purely for speed reasons 2271 /* otherwise we cancel directly, purely for speed reasons
2255 * unfortunately, this requires some magic trickery, as 2272 * unfortunately, this requires some magic trickery, as
2256 * somebody else could cancel us, so we have to fight the cancellation. 2273 * somebody else could cancel us, so we have to fight the cancellation.
2257 * this is ugly, and hopefully fully worth the extra speed. 2274 * this is ugly, and hopefully fully worth the extra speed.
2608 * Since by definition the SLF call will not finish when we destroy 2625 * Since by definition the SLF call will not finish when we destroy
2609 * the coro, we will have to force-finish it here, otherwise 2626 * the coro, we will have to force-finish it here, otherwise
2610 * cleanup functions cannot call SLF functions. 2627 * cleanup functions cannot call SLF functions.
2611 */ 2628 */
2612 coro->slf_frame.prepare = 0; 2629 coro->slf_frame.prepare = 0;
2613 coro->slf_frame.destroy = 0;
2614 2630
2615 /* this callback is reserved for slf functions needing to do cleanup */ 2631 /* this callback is reserved for slf functions needing to do cleanup */
2616 if (frame.destroy && frame.prepare && !PL_dirty) 2632 if (frame.destroy && frame.prepare && !PL_dirty)
2617 frame.destroy (aTHX_ &frame); 2633 frame.destroy (aTHX_ &frame);
2618} 2634}
2962{ 2978{
2963 AV *av = (AV *)frame->data; 2979 AV *av = (AV *)frame->data;
2964 SV *count_sv = AvARRAY (av)[0]; 2980 SV *count_sv = AvARRAY (av)[0];
2965 SV *coro_hv = SvRV (coro_current); 2981 SV *coro_hv = SvRV (coro_current);
2966 2982
2983 frame->destroy = 0;
2984
2967 /* if we are about to throw, don't actually acquire the lock, just throw */ 2985 /* if we are about to throw, don't actually acquire the lock, just throw */
2968 if (CORO_THROW) 2986 if (ecb_expect_false (CORO_THROW))
2987 {
2988 /* we still might be responsible for the semaphore, so wake up others */
2989 coro_semaphore_adjust (aTHX_ av, 0);
2990
2969 return 0; 2991 return 0;
2992 }
2970 else if (SvIVX (count_sv) > 0) 2993 else if (SvIVX (count_sv) > 0)
2971 { 2994 {
2972 frame->destroy = 0;
2973
2974 if (acquire) 2995 if (acquire)
2975 SvIVX (count_sv) = SvIVX (count_sv) - 1; 2996 SvIVX (count_sv) = SvIVX (count_sv) - 1;
2976 else 2997 else
2977 coro_semaphore_adjust (aTHX_ av, 0); 2998 coro_semaphore_adjust (aTHX_ av, 0);
2978 2999
3438 3459
3439PROTOTYPES: DISABLE 3460PROTOTYPES: DISABLE
3440 3461
3441BOOT: 3462BOOT:
3442{ 3463{
3464#define VARx(name,expr,type) if (sizeof (type) < sizeof (expr)) croak ("FATAL: Coro thread context slot '" # name "' too small for this version of perl.");
3465#include "state.h"
3443#ifdef USE_ITHREADS 3466#ifdef USE_ITHREADS
3444# if CORO_PTHREAD 3467# if CORO_PTHREAD
3445 coro_thx = PERL_GET_CONTEXT; 3468 coro_thx = PERL_GET_CONTEXT;
3446# endif 3469# endif
3447#endif 3470#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines