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

75/* 5.8.7 */ 75/* 5.8.7 */
76#ifndef SvRV_set 76#ifndef SvRV_set
77# define SvRV_set(s,v) SvRV(s) = (v) 77# define SvRV_set(s,v) SvRV(s) = (v)
78#endif 78#endif
79 79
80/* 5.8.8 */
81#ifndef GV_NOTQUAL
82# define GV_NOTQUAL 0
83#endif
84#ifndef newSV
85# define newSV(l) NEWSV(0,l)
86#endif
87
80#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 88#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
81# undef CORO_STACKGUARD 89# undef CORO_STACKGUARD
82#endif 90#endif
83 91
84#ifndef CORO_STACKGUARD 92#ifndef CORO_STACKGUARD
132static AV *main_mainstack; /* used to differentiate between $main and others */ 140static AV *main_mainstack; /* used to differentiate between $main and others */
133static JMPENV *main_top_env; 141static JMPENV *main_top_env;
134static HV *coro_state_stash, *coro_stash; 142static HV *coro_state_stash, *coro_stash;
135static SV *coro_mortal; /* will be freed after next transfer */ 143static SV *coro_mortal; /* will be freed after next transfer */
136 144
137static GV *irsgv; /* $/ */ 145static GV *irsgv; /* $/ */
138static GV *stdoutgv; /* STDOUT */ 146static GV *stdoutgv; /* *STDOUT */
139 147
140/* async_pool helper stuff */ 148/* async_pool helper stuff */
141static SV *sv_pool_rss; 149static SV *sv_pool_rss;
142static SV *sv_pool_size; 150static SV *sv_pool_size;
143static AV *av_async_pool; 151static AV *av_async_pool;
599 PL_curpm = 0; 607 PL_curpm = 0;
600 PL_localizing = 0; 608 PL_localizing = 0;
601 PL_dirty = 0; 609 PL_dirty = 0;
602 PL_restartop = 0; 610 PL_restartop = 0;
603 611
604 GvSV (PL_defgv) = NEWSV (0, 0); 612 GvSV (PL_defgv) = newSV (0);
605 GvAV (PL_defgv) = coro->args; coro->args = 0; 613 GvAV (PL_defgv) = coro->args; coro->args = 0;
606 GvSV (PL_errgv) = NEWSV (0, 0); 614 GvSV (PL_errgv) = newSV (0);
607 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);
608 PL_rs = newSVsv (GvSV (irsgv)); 616 PL_rs = newSVsv (GvSV (irsgv));
609 PL_defoutgv = SvREFCNT_inc (stdoutgv); 617 PL_defoutgv = SvREFCNT_inc (stdoutgv);
610 618
619 ENTER; /* necessary e.g. for dounwind */
620
611 { 621 {
612 dSP; 622 dSP;
613 LOGOP myop; 623 LOGOP myop;
614 624
615 Zero (&myop, 1, LOGOP); 625 Zero (&myop, 1, LOGOP);
616 myop.op_next = Nullop; 626 myop.op_next = Nullop;
617 myop.op_flags = OPf_WANT_VOID; 627 myop.op_flags = OPf_WANT_VOID;
618 628
619 PUSHMARK (SP); 629 PUSHMARK (SP);
620 XPUSHs (av_shift (GvAV (PL_defgv))); 630 XPUSHs (sv_2mortal (av_shift (GvAV (PL_defgv))));
621 PUTBACK; 631 PUTBACK;
622 PL_op = (OP *)&myop; 632 PL_op = (OP *)&myop;
623 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); 633 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
624 SPAGAIN; 634 SPAGAIN;
625 } 635 }
626
627 ENTER; /* necessary e.g. for dounwind */
628} 636}
629 637
630static void 638static void
631coro_destroy (pTHX_ struct coro *coro) 639coro_destroy (pTHX_ struct coro *coro)
632{ 640{
700 bot = PL_stack_base + cx->blk_oldsp + 1; 708 bot = PL_stack_base + cx->blk_oldsp + 1;
701 top = cx->blk_gimme == G_ARRAY ? SP + 1 709 top = cx->blk_gimme == G_ARRAY ? SP + 1
702 : cx->blk_gimme == G_SCALAR ? bot + 1 710 : cx->blk_gimme == G_SCALAR ? bot + 1
703 : bot; 711 : bot;
704 712
713 av_extend (av, top - bot);
705 while (bot < top) 714 while (bot < top)
706 av_push (av, SvREFCNT_inc (*bot++)); 715 av_push (av, SvREFCNT_inc (*bot++));
707 716
708 PL_runops = RUNOPS_DEFAULT; 717 PL_runops = RUNOPS_DEFAULT;
709 ENTER; 718 ENTER;
921 Safefree (cctx->sptr); 930 Safefree (cctx->sptr);
922 931
923 Safefree (cctx); 932 Safefree (cctx);
924} 933}
925 934
935/* wether this cctx should be destructed */
936#define CCTX_EXPIRED(cctx) ((cctx)->ssize < coro_stacksize || ((cctx)->flags & CC_NOREUSE))
937
926static coro_cctx * 938static coro_cctx *
927cctx_get (pTHX) 939cctx_get (pTHX)
928{ 940{
929 while (cctx_first) 941 while (cctx_first)
930 { 942 {
931 coro_cctx *cctx = cctx_first; 943 coro_cctx *cctx = cctx_first;
932 cctx_first = cctx->next; 944 cctx_first = cctx->next;
933 --cctx_idle; 945 --cctx_idle;
934 946
935 if (cctx->ssize >= coro_stacksize && !(cctx->flags & CC_NOREUSE)) 947 if (!CCTX_EXPIRED (cctx))
936 return cctx; 948 return cctx;
937 949
938 cctx_destroy (cctx); 950 cctx_destroy (cctx);
939 } 951 }
940 952
1033 /* 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 */
1034 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));
1035 1047
1036 prev->cctx = 0; 1048 prev->cctx = 0;
1037 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
1038 cctx_put (prev__cctx); 1054 cctx_put (prev__cctx);
1039 } 1055 }
1040 1056
1041 ++next->usecount; 1057 ++next->usecount;
1042 1058
1420 1436
1421 coro->hv = hv = newHV (); 1437 coro->hv = hv = newHV ();
1422 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;
1423 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 1439 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
1424 1440
1441 av_extend (coro->args, items - 1);
1425 for (i = 1; i < items; i++) 1442 for (i = 1; i < items; i++)
1426 av_push (coro->args, newSVsv (ST (i))); 1443 av_push (coro->args, newSVsv (ST (i)));
1427} 1444}
1428 OUTPUT: 1445 OUTPUT:
1429 RETVAL 1446 RETVAL

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines