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.191 by root, Fri Oct 5 20:47:49 2007 UTC vs.
Revision 1.193 by root, Fri Oct 5 23:38:40 2007 UTC

614 GvSV (PL_errgv) = newSV (0); 614 GvSV (PL_errgv) = newSV (0);
615 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 615 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
616 PL_rs = newSVsv (GvSV (irsgv)); 616 PL_rs = newSVsv (GvSV (irsgv));
617 PL_defoutgv = SvREFCNT_inc (stdoutgv); 617 PL_defoutgv = SvREFCNT_inc (stdoutgv);
618 618
619 ENTER; /* necessary e.g. for dounwind */
620
619 { 621 {
620 dSP; 622 dSP;
621 LOGOP myop; 623 LOGOP myop;
622 624
623 Zero (&myop, 1, LOGOP); 625 Zero (&myop, 1, LOGOP);
624 myop.op_next = Nullop; 626 myop.op_next = Nullop;
625 myop.op_flags = OPf_WANT_VOID; 627 myop.op_flags = OPf_WANT_VOID;
626 628
627 PUSHMARK (SP); 629 PUSHMARK (SP);
628 XPUSHs (av_shift (GvAV (PL_defgv))); 630 XPUSHs (sv_2mortal (av_shift (GvAV (PL_defgv))));
629 PUTBACK; 631 PUTBACK;
630 PL_op = (OP *)&myop; 632 PL_op = (OP *)&myop;
631 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); 633 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
632 SPAGAIN; 634 SPAGAIN;
633 } 635 }
634
635 ENTER; /* necessary e.g. for dounwind */
636} 636}
637 637
638static void 638static void
639coro_destroy (pTHX_ struct coro *coro) 639coro_destroy (pTHX_ struct coro *coro)
640{ 640{
708 bot = PL_stack_base + cx->blk_oldsp + 1; 708 bot = PL_stack_base + cx->blk_oldsp + 1;
709 top = cx->blk_gimme == G_ARRAY ? SP + 1 709 top = cx->blk_gimme == G_ARRAY ? SP + 1
710 : cx->blk_gimme == G_SCALAR ? bot + 1 710 : cx->blk_gimme == G_SCALAR ? bot + 1
711 : bot; 711 : bot;
712 712
713 av_extend (av, top - bot);
713 while (bot < top) 714 while (bot < top)
714 av_push (av, SvREFCNT_inc (*bot++)); 715 av_push (av, SvREFCNT_inc (*bot++));
715 716
716 PL_runops = RUNOPS_DEFAULT; 717 PL_runops = RUNOPS_DEFAULT;
717 ENTER; 718 ENTER;
929 Safefree (cctx->sptr); 930 Safefree (cctx->sptr);
930 931
931 Safefree (cctx); 932 Safefree (cctx);
932} 933}
933 934
935/* wether this cctx should be destructed */
936#define CCTX_EXPIRED(cctx) ((cctx)->ssize < coro_stacksize || ((cctx)->flags & CC_NOREUSE))
937
934static coro_cctx * 938static coro_cctx *
935cctx_get (pTHX) 939cctx_get (pTHX)
936{ 940{
937 while (cctx_first) 941 while (cctx_first)
938 { 942 {
939 coro_cctx *cctx = cctx_first; 943 coro_cctx *cctx = cctx_first;
940 cctx_first = cctx->next; 944 cctx_first = cctx->next;
941 --cctx_idle; 945 --cctx_idle;
942 946
943 if (cctx->ssize >= coro_stacksize && !(cctx->flags & CC_NOREUSE)) 947 if (!CCTX_EXPIRED (cctx))
944 return cctx; 948 return cctx;
945 949
946 cctx_destroy (cctx); 950 cctx_destroy (cctx);
947 } 951 }
948 952
1041 /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */ 1045 /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */
1042 assert (("ERROR: current top_env must equal previous top_env", PL_top_env == prev__cctx->idle_te)); 1046 assert (("ERROR: current top_env must equal previous top_env", PL_top_env == prev__cctx->idle_te));
1043 1047
1044 prev->cctx = 0; 1048 prev->cctx = 0;
1045 1049
1050 /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */
1051 if (CCTX_EXPIRED (prev__cctx))
1052 next->cctx = cctx_get (aTHX);
1053
1046 cctx_put (prev__cctx); 1054 cctx_put (prev__cctx);
1047 } 1055 }
1048 1056
1049 ++next->usecount; 1057 ++next->usecount;
1050 1058
1428 1436
1429 coro->hv = hv = newHV (); 1437 coro->hv = hv = newHV ();
1430 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP; 1438 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP;
1431 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 1439 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
1432 1440
1441 av_extend (coro->args, items - 1);
1433 for (i = 1; i < items; i++) 1442 for (i = 1; i < items; i++)
1434 av_push (coro->args, newSVsv (ST (i))); 1443 av_push (coro->args, newSVsv (ST (i)));
1435} 1444}
1436 OUTPUT: 1445 OUTPUT:
1437 RETVAL 1446 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines