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.448 by root, Thu Jun 4 22:58:28 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;
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.
2599 2616
2600/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */ 2617/* "undo"/cancel a running slf call - used when cancelling a coro, mainly */
2601static void 2618static void
2602slf_destroy (pTHX_ struct coro *coro) 2619slf_destroy (pTHX_ struct coro *coro)
2603{ 2620{
2604 /* this callback is reserved for slf functions needing to do cleanup */ 2621 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 2622
2608 /* 2623 /*
2609 * The on_destroy above most likely is from an SLF call. 2624 * The on_destroy below most likely is from an SLF call.
2610 * 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
2611 * the coro, we will have to force-finish it here, otherwise 2626 * the coro, we will have to force-finish it here, otherwise
2612 * cleanup functions cannot call SLF functions. 2627 * cleanup functions cannot call SLF functions.
2613 */ 2628 */
2614 coro->slf_frame.prepare = 0; 2629 coro->slf_frame.prepare = 0;
2630
2631 /* this callback is reserved for slf functions needing to do cleanup */
2632 if (frame.destroy && frame.prepare && !PL_dirty)
2633 frame.destroy (aTHX_ &frame);
2615} 2634}
2616 2635
2617/* 2636/*
2618 * these not obviously related functions are all rolled into one 2637 * these not obviously related functions are all rolled into one
2619 * function to increase chances that they all will call transfer with the same 2638 * function to increase chances that they all will call transfer with the same
2959{ 2978{
2960 AV *av = (AV *)frame->data; 2979 AV *av = (AV *)frame->data;
2961 SV *count_sv = AvARRAY (av)[0]; 2980 SV *count_sv = AvARRAY (av)[0];
2962 SV *coro_hv = SvRV (coro_current); 2981 SV *coro_hv = SvRV (coro_current);
2963 2982
2983 frame->destroy = 0;
2984
2964 /* 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 */
2965 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
2966 return 0; 2991 return 0;
2992 }
2967 else if (SvIVX (count_sv) > 0) 2993 else if (SvIVX (count_sv) > 0)
2968 { 2994 {
2969 frame->destroy = 0;
2970
2971 if (acquire) 2995 if (acquire)
2972 SvIVX (count_sv) = SvIVX (count_sv) - 1; 2996 SvIVX (count_sv) = SvIVX (count_sv) - 1;
2973 else 2997 else
2974 coro_semaphore_adjust (aTHX_ av, 0); 2998 coro_semaphore_adjust (aTHX_ av, 0);
2975 2999
3435 3459
3436PROTOTYPES: DISABLE 3460PROTOTYPES: DISABLE
3437 3461
3438BOOT: 3462BOOT:
3439{ 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"
3440#ifdef USE_ITHREADS 3466#ifdef USE_ITHREADS
3441# if CORO_PTHREAD 3467# if CORO_PTHREAD
3442 coro_thx = PERL_GET_CONTEXT; 3468 coro_thx = PERL_GET_CONTEXT;
3443# endif 3469# endif
3444#endif 3470#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines