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.46 by pcg, Wed Nov 5 20:02:46 2003 UTC vs.
Revision 1.48 by pcg, Sat Nov 15 03:53:37 2003 UTC

303#define SE } while (0) 303#define SE } while (0)
304 304
305#define LOAD(state) load_state(aTHX_ (state)); 305#define LOAD(state) load_state(aTHX_ (state));
306#define SAVE(state,flags) save_state(aTHX_ (state),(flags)); 306#define SAVE(state,flags) save_state(aTHX_ (state),(flags));
307 307
308#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); SE 308#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); (val) = 0; SE
309 309
310static void 310static void
311load_state(pTHX_ Coro__State c) 311load_state(pTHX_ Coro__State c)
312{ 312{
313 PL_dowarn = c->dowarn; 313 PL_dowarn = c->dowarn;
518 PL_retstack_max = 8; 518 PL_retstack_max = 8;
519} 519}
520 520
521/* 521/*
522 * destroy the stacks, the callchain etc... 522 * destroy the stacks, the callchain etc...
523 * still there is a memleak of 128 bytes...
524 */ 523 */
525STATIC void 524STATIC void
526destroy_stacks(pTHX) 525destroy_stacks(pTHX)
527{ 526{
528 if (!IN_DESTRUCT) 527 if (!IN_DESTRUCT)
609 { 608 {
610#ifdef HAVE_MMAP 609#ifdef HAVE_MMAP
611 if (stack->ssize > 0 && stack->sptr) 610 if (stack->ssize > 0 && stack->sptr)
612 munmap (stack->sptr, stack->ssize); 611 munmap (stack->sptr, stack->ssize);
613 else 612 else
614#else 613#endif
615 Safefree (stack->sptr); 614 Safefree (stack->sptr);
616#endif 615
617 Safefree (stack); 616 Safefree (stack);
618 } 617 }
619 else if (ctx->gencnt == stack->gencnt) 618 else if (ctx->gencnt == stack->gencnt)
620 --stack->usecnt; 619 --stack->usecnt;
621 } 620 }
633 632
634 coro_init_stacks (aTHX); 633 coro_init_stacks (aTHX);
635 /*PL_curcop = 0;*/ 634 /*PL_curcop = 0;*/
636 /*PL_in_eval = PL_in_eval;*/ /* inherit */ 635 /*PL_in_eval = PL_in_eval;*/ /* inherit */
637 SvREFCNT_dec (GvAV (PL_defgv)); 636 SvREFCNT_dec (GvAV (PL_defgv));
638 GvAV (PL_defgv) = ctx->args; 637 GvAV (PL_defgv) = ctx->args; ctx->args = 0;
639 638
640 SPAGAIN; 639 SPAGAIN;
641 640
642 if (ctx->stack) 641 if (ctx->stack)
643 { 642 {
765 next->stack = prev->stack; 764 next->stack = prev->stack;
766 next->gencnt = prev->gencnt; 765 next->gencnt = prev->gencnt;
767 } 766 }
768 else 767 else
769 { 768 {
769 assert (!next->stack);
770 allocate_stack (next, 1); 770 allocate_stack (next, 1);
771 coro_create (&(next->stack->cctx), 771 coro_create (&(next->stack->cctx),
772 setup_coro, (void *)next, 772 setup_coro, (void *)next,
773 next->stack->sptr, labs (next->stack->ssize)); 773 next->stack->sptr, labs (next->stack->ssize));
774 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); 774 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx));
952 Coro__State coro; 952 Coro__State coro;
953 953
954 if (!SvROK (args) || SvTYPE (SvRV (args)) != SVt_PVAV) 954 if (!SvROK (args) || SvTYPE (SvRV (args)) != SVt_PVAV)
955 croak ("Coro::State::_newprocess expects an arrayref"); 955 croak ("Coro::State::_newprocess expects an arrayref");
956 956
957 New (0, coro, 1, struct coro); 957 Newz (0, coro, 1, struct coro);
958 958
959 coro->args = (AV *)SvREFCNT_inc (SvRV (args)); 959 coro->args = (AV *)SvREFCNT_inc (SvRV (args));
960 coro->mainstack = 0; /* actual work is done inside transfer */ 960 coro->mainstack = 0; /* actual work is done inside transfer */
961 coro->stack = 0; 961 coro->stack = 0;
962 962
963 /* same as JMPENV_BOOTSTRAP */ 963 /* same as JMPENV_BOOTSTRAP */
964 /* we might be able to recycle start_env, but safe is safe */ 964 /* we might be able to recycle start_env, but safe is safe */
965 Zero(&coro->start_env, 1, JMPENV); 965 //Zero(&coro->start_env, 1, JMPENV);
966 coro->start_env.je_ret = -1; 966 coro->start_env.je_ret = -1;
967 coro->start_env.je_mustcatch = TRUE; 967 coro->start_env.je_mustcatch = TRUE;
968 968
969 RETVAL = coro; 969 RETVAL = coro;
970 OUTPUT: 970 OUTPUT:
1004 1004
1005 coro->mainstack = 0; 1005 coro->mainstack = 0;
1006 } 1006 }
1007 1007
1008 deallocate_stack (coro); 1008 deallocate_stack (coro);
1009 1009 SvREFCNT_dec (coro->args);
1010 Safefree (coro); 1010 Safefree (coro);
1011 1011
1012void 1012void
1013flush() 1013flush()
1014 CODE: 1014 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines