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.415 by root, Tue Aug 30 07:48:53 2011 UTC vs.
Revision 1.416 by root, Mon Dec 12 15:19:56 2011 UTC

181 void *sptr; 181 void *sptr;
182 size_t ssize; 182 size_t ssize;
183 183
184 /* cpu state */ 184 /* cpu state */
185 void *idle_sp; /* sp of top-level transfer/schedule/cede call */ 185 void *idle_sp; /* sp of top-level transfer/schedule/cede call */
186#ifndef NDEBUG
186 JMPENV *idle_te; /* same as idle_sp, but for top_env, TODO: remove once stable */ 187 JMPENV *idle_te; /* same as idle_sp, but for top_env */
188#endif
187 JMPENV *top_env; 189 JMPENV *top_env;
188 coro_context cctx; 190 coro_context cctx;
189 191
190 U32 gen; 192 U32 gen;
191#if CORO_USE_VALGRIND 193#if CORO_USE_VALGRIND
641 AvARRAY (av)[++AvFILLp (av)] = (SV *)CvPADLIST (cv); 643 AvARRAY (av)[++AvFILLp (av)] = (SV *)CvPADLIST (cv);
642} 644}
643 645
644/** load & save, init *******************************************************/ 646/** load & save, init *******************************************************/
645 647
648ecb_inline void
649swap_sv (SV *a, SV *b)
650{
651 const U32 keep = SVs_PADSTALE | SVs_PADTMP | SVs_PADMY; /* keep these flags */
652 SV tmp;
653
654 /* swap sv_any */
655 SvANY (&tmp) = SvANY (a); SvANY (a) = SvANY (b); SvANY (b) = SvANY (&tmp);
656
657 /* swap sv_flags */
658 SvFLAGS (&tmp) = SvFLAGS (a);
659 SvFLAGS (a) = (SvFLAGS (a) & keep) | (SvFLAGS (b ) & ~keep);
660 SvFLAGS (b) = (SvFLAGS (b) & keep) | (SvFLAGS (&tmp) & ~keep);
661
662#if PERL_VERSION_ATLEAST (5,10,0)
663 /* perl 5.10 and later complicates this _quite_ a bit, but it also
664 * is much faster, so no quarrels here. alternatively, we could
665 * sv_upgrade to avoid this.
666 */
667 {
668 /* swap sv_u */
669 tmp.sv_u = a->sv_u; a->sv_u = b->sv_u; b->sv_u = tmp.sv_u;
670
671 /* if SvANY points to the head, we need to adjust the pointers,
672 * as the pointer for a still points to b, and maybe vice versa.
673 */
674 #define svany_in_head(type) \
675 (((1 << SVt_NULL) | (1 << SVt_BIND) | (1 << SVt_IV) | (1 << SVt_RV)) & (1 << (type)))
676
677 if (svany_in_head (SvTYPE (a)))
678 SvANY (a) = (void *)((PTRV)SvANY (a) - (PTRV)b + (PTRV)a);
679
680 if (svany_in_head (SvTYPE (b)))
681 SvANY (b) = (void *)((PTRV)SvANY (b) - (PTRV)a + (PTRV)b);
682 }
683#endif
684}
685
646/* swap sv heads, at least logically */ 686/* swap sv heads, at least logically */
647static void 687static void
648swap_svs (pTHX_ Coro__State c) 688swap_svs (pTHX_ Coro__State c)
649{ 689{
650 int i; 690 int i;
651 691
652 for (i = 0; i <= AvFILLp (c->swap_sv); ) 692 for (i = 0; i <= AvFILLp (c->swap_sv); i += 2)
653 { 693 swap_sv (AvARRAY (c->swap_sv)[i], AvARRAY (c->swap_sv)[i + 1]);
654 SV *a = AvARRAY (c->swap_sv)[i++];
655 SV *b = AvARRAY (c->swap_sv)[i++];
656
657 const U32 keep = SVs_PADSTALE | SVs_PADTMP | SVs_PADMY; /* keep these flags */
658 SV tmp;
659
660 /* swap sv_any */
661 SvANY (&tmp) = SvANY (a); SvANY (a) = SvANY (b); SvANY (b) = SvANY (&tmp);
662
663 /* swap sv_flags */
664 SvFLAGS (&tmp) = SvFLAGS (a);
665 SvFLAGS (a) = (SvFLAGS (a) & keep) | (SvFLAGS (b ) & ~keep);
666 SvFLAGS (b) = (SvFLAGS (b) & keep) | (SvFLAGS (&tmp) & ~keep);
667
668#if PERL_VERSION_ATLEAST (5,10,0)
669 /* perl 5.10 complicates this _quite_ a bit, but it also is
670 * much faster, so no quarrels here. alternatively, we could
671 * sv_upgrade to avoid this.
672 */
673 {
674 /* swap sv_u */
675 tmp.sv_u = a->sv_u; a->sv_u = b->sv_u; b->sv_u = tmp.sv_u;
676
677 /* if SvANY points to the head, we need to adjust the pointers,
678 * as the pointer for a still points to b, and maybe vice versa.
679 */
680 #define svany_in_head(type) \
681 (((1 << SVt_NULL) | (1 << SVt_BIND) | (1 << SVt_IV) | (1 << SVt_RV)) & (1 << (type)))
682
683 if (svany_in_head (SvTYPE (a)))
684 SvANY (a) = (void *)((PTRV)SvANY (a) - (PTRV)b + (PTRV)a);
685
686 if (svany_in_head (SvTYPE (b)))
687 SvANY (b) = (void *)((PTRV)SvANY (b) - (PTRV)a + (PTRV)b);
688 }
689#endif
690 }
691} 694}
692 695
693#define SWAP_SVS(coro) \ 696#define SWAP_SVS(coro) \
694 if (ecb_expect_false ((coro)->swap_sv)) \ 697 if (ecb_expect_false ((coro)->swap_sv)) \
695 swap_svs (aTHX_ (coro)) 698 swap_svs (aTHX_ (coro))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines