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.27 by root, Mon Aug 20 16:58:19 2001 UTC vs.
Revision 1.45 by root, Tue May 27 01:15:31 2003 UTC

7#include <signal.h> 7#include <signal.h>
8 8
9#ifdef HAVE_MMAP 9#ifdef HAVE_MMAP
10# include <unistd.h> 10# include <unistd.h>
11# include <sys/mman.h> 11# include <sys/mman.h>
12# ifndef MAP_ANON
13# ifdef MAP_ANONYMOUS 12# ifndef MAP_ANONYMOUS
14# define MAP_ANON MAP_ANONYMOUS 13# ifdef MAP_ANON
14# define MAP_ANONYMOUS MAP_ANON
15# else 15# else
16# undef HAVE_MMAP 16# undef HAVE_MMAP
17# endif 17# endif
18# endif 18# endif
19#endif 19#endif
20 20
21#define MAY_FLUSH /* increases codesize */ 21#define MAY_FLUSH /* increases codesize and is rarely used */
22 22
23#define SUB_INIT "Coro::State::initialize" 23#define SUB_INIT "Coro::State::initialize"
24#define UCORO_STATE "_coro_state" 24#define UCORO_STATE "_coro_state"
25 25
26/* The next macro should delcare a variable stacklevel that contains and approximation 26/* The next macro should declare a variable stacklevel that contains and approximation
27 * to the current C stack pointer. Its property is that it changes with each call 27 * to the current C stack pointer. Its property is that it changes with each call
28 * and should be unique. */ 28 * and should be unique. */
29#define dSTACKLEVEL void *stacklevel = &stacklevel 29#define dSTACKLEVEL void *stacklevel = &stacklevel
30
31#define IN_DESTRUCT (PL_main_cv == Nullcv)
30 32
31#define labs(l) ((l) >= 0 ? (l) : -(l)) 33#define labs(l) ((l) >= 0 ? (l) : -(l))
32 34
33#include "CoroAPI.h" 35#include "CoroAPI.h"
34 36
45 void *sptr; 47 void *sptr;
46 long ssize; /* positive == mmap, otherwise malloc */ 48 long ssize; /* positive == mmap, otherwise malloc */
47} coro_stack; 49} coro_stack;
48 50
49struct coro { 51struct coro {
52 /* the top-level JMPENV for each coroutine, needed to catch dies. */
53 JMPENV start_env;
54
50 /* the optional C context */ 55 /* the optional C context */
51 coro_stack *stack; 56 coro_stack *stack;
52 void *cursp; 57 void *cursp;
53 int gencnt; 58 int gencnt;
54 59
66 AV *curstack; 71 AV *curstack;
67 AV *mainstack; 72 AV *mainstack;
68 SV **stack_sp; 73 SV **stack_sp;
69 OP *op; 74 OP *op;
70 SV **curpad; 75 SV **curpad;
76 AV *comppad;
71 SV **stack_base; 77 SV **stack_base;
72 SV **stack_max; 78 SV **stack_max;
73 SV **tmps_stack; 79 SV **tmps_stack;
74 I32 tmps_floor; 80 I32 tmps_floor;
75 I32 tmps_ix; 81 I32 tmps_ix;
99static AV *main_mainstack; /* used to differentiate between $main and others */ 105static AV *main_mainstack; /* used to differentiate between $main and others */
100static HV *coro_state_stash; 106static HV *coro_state_stash;
101static SV *ucoro_state_sv; 107static SV *ucoro_state_sv;
102static U32 ucoro_state_hash; 108static U32 ucoro_state_hash;
103static HV *padlist_cache; 109static HV *padlist_cache;
110static SV *coro_mortal; /* will be freed after next transfer */
104 111
105/* mostly copied from op.c:cv_clone2 */ 112/* mostly copied from op.c:cv_clone2 */
106STATIC AV * 113STATIC AV *
107clone_padlist (AV *protopadlist) 114clone_padlist (AV *protopadlist)
108{ 115{
270#endif 277#endif
271 278
272#define SB do { 279#define SB do {
273#define SE } while (0) 280#define SE } while (0)
274 281
275#define LOAD(state) SB load_state(aTHX_ (state)); SPAGAIN; SE 282#define LOAD(state) load_state(aTHX_ (state));
276#define SAVE(state,flags) SB PUTBACK; save_state(aTHX_ (state),(flags)); SE 283#define SAVE(state,flags) save_state(aTHX_ (state),(flags));
277 284
278#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); SE 285#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); SE
279 286
280static void 287static void
281load_state(pTHX_ Coro__State c) 288load_state(pTHX_ Coro__State c)
287 PL_curstack = c->curstack; 294 PL_curstack = c->curstack;
288 PL_mainstack = c->mainstack; 295 PL_mainstack = c->mainstack;
289 PL_stack_sp = c->stack_sp; 296 PL_stack_sp = c->stack_sp;
290 PL_op = c->op; 297 PL_op = c->op;
291 PL_curpad = c->curpad; 298 PL_curpad = c->curpad;
299 PL_comppad = c->comppad;
292 PL_stack_base = c->stack_base; 300 PL_stack_base = c->stack_base;
293 PL_stack_max = c->stack_max; 301 PL_stack_max = c->stack_max;
294 PL_tmps_stack = c->tmps_stack; 302 PL_tmps_stack = c->tmps_stack;
295 PL_tmps_floor = c->tmps_floor; 303 PL_tmps_floor = c->tmps_floor;
296 PL_tmps_ix = c->tmps_ix; 304 PL_tmps_ix = c->tmps_ix;
355 363
356 PUSHs (Nullsv); 364 PUSHs (Nullsv);
357 /* this loop was inspired by pp_caller */ 365 /* this loop was inspired by pp_caller */
358 for (;;) 366 for (;;)
359 { 367 {
360 do 368 while (cxix >= 0)
361 { 369 {
362 PERL_CONTEXT *cx = &ccstk[cxix--]; 370 PERL_CONTEXT *cx = &ccstk[cxix--];
363 371
364 if (CxTYPE(cx) == CXt_SUB) 372 if (CxTYPE(cx) == CXt_SUB)
365 { 373 {
391 /* I never used formats, so how should I know how these are implemented? */ 399 /* I never used formats, so how should I know how these are implemented? */
392 /* my bold guess is as a simple, plain sub... */ 400 /* my bold guess is as a simple, plain sub... */
393 croak ("CXt_FORMAT not yet handled. Don't switch coroutines from within formats"); 401 croak ("CXt_FORMAT not yet handled. Don't switch coroutines from within formats");
394 } 402 }
395 } 403 }
396 while (cxix >= 0);
397 404
398 if (top_si->si_type == PERLSI_MAIN) 405 if (top_si->si_type == PERLSI_MAIN)
399 break; 406 break;
400 407
401 top_si = top_si->si_prev; 408 top_si = top_si->si_prev;
407 } 414 }
408 415
409 c->defav = flags & TRANSFER_SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0; 416 c->defav = flags & TRANSFER_SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0;
410 c->defsv = flags & TRANSFER_SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0; 417 c->defsv = flags & TRANSFER_SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0;
411 c->errsv = flags & TRANSFER_SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0; 418 c->errsv = flags & TRANSFER_SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0;
412
413 /* I have not the slightest idea of why av_reify is necessary */
414 /* but if it's missing the defav contents magically get replaced sometimes */
415 if (c->defav)
416 av_reify (c->defav);
417 419
418 c->dowarn = PL_dowarn; 420 c->dowarn = PL_dowarn;
419 c->in_eval = PL_in_eval; 421 c->in_eval = PL_in_eval;
420 422
421 c->curstackinfo = PL_curstackinfo; 423 c->curstackinfo = PL_curstackinfo;
422 c->curstack = PL_curstack; 424 c->curstack = PL_curstack;
423 c->mainstack = PL_mainstack; 425 c->mainstack = PL_mainstack;
424 c->stack_sp = PL_stack_sp; 426 c->stack_sp = PL_stack_sp;
425 c->op = PL_op; 427 c->op = PL_op;
426 c->curpad = PL_curpad; 428 c->curpad = PL_curpad;
429 c->comppad = PL_comppad;
427 c->stack_base = PL_stack_base; 430 c->stack_base = PL_stack_base;
428 c->stack_max = PL_stack_max; 431 c->stack_max = PL_stack_max;
429 c->tmps_stack = PL_tmps_stack; 432 c->tmps_stack = PL_tmps_stack;
430 c->tmps_floor = PL_tmps_floor; 433 c->tmps_floor = PL_tmps_floor;
431 c->tmps_ix = PL_tmps_ix; 434 c->tmps_ix = PL_tmps_ix;
493 * still there is a memleak of 128 bytes... 496 * still there is a memleak of 128 bytes...
494 */ 497 */
495STATIC void 498STATIC void
496destroy_stacks(pTHX) 499destroy_stacks(pTHX)
497{ 500{
501 if (!IN_DESTRUCT)
502 {
498 /* is this ugly, I ask? */ 503 /* is this ugly, I ask? */
499 while (PL_scopestack_ix) 504 while (PL_scopestack_ix)
500 LEAVE; 505 LEAVE;
501 506
502 /* sure it is, but more important: is it correct?? :/ */ 507 /* sure it is, but more important: is it correct?? :/ */
503 while (PL_tmps_ix > PL_tmps_floor) /* should only ever be one iteration */ 508 while (PL_tmps_ix > PL_tmps_floor) /* should only ever be one iteration */
504 FREETMPS; 509 FREETMPS;
510 }
505 511
506 while (PL_curstackinfo->si_next) 512 while (PL_curstackinfo->si_next)
507 PL_curstackinfo = PL_curstackinfo->si_next; 513 PL_curstackinfo = PL_curstackinfo->si_next;
508 514
509 while (PL_curstackinfo) 515 while (PL_curstackinfo)
514 dSP; 520 dSP;
515 SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); 521 SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack);
516 PUTBACK; /* possibly superfluous */ 522 PUTBACK; /* possibly superfluous */
517 } 523 }
518 524
519 if (PL_main_cv != Nullcv) /* don't during destruction. hack? */ 525 if (!IN_DESTRUCT)
526 {
520 dounwind(-1); 527 dounwind(-1);
521
522 SvREFCNT_dec(PL_curstackinfo->si_stack); 528 SvREFCNT_dec(PL_curstackinfo->si_stack);
529 }
530
523 Safefree(PL_curstackinfo->si_cxstack); 531 Safefree(PL_curstackinfo->si_cxstack);
524 Safefree(PL_curstackinfo); 532 Safefree(PL_curstackinfo);
525 PL_curstackinfo = p; 533 PL_curstackinfo = p;
526 } 534 }
527 535
542 stack->refcnt = 1; 550 stack->refcnt = 1;
543 stack->usecnt = 1; 551 stack->usecnt = 1;
544 stack->gencnt = ctx->gencnt = 0; 552 stack->gencnt = ctx->gencnt = 0;
545 if (alloc) 553 if (alloc)
546 { 554 {
547#ifdef HAVE_MMAP 555#if HAVE_MMAP
548 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */ 556 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */
549 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0); 557 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
550 if (stack->sptr == (void *)-1) 558 if (stack->sptr == (void *)-1)
551#endif 559#endif
552 { 560 {
553 /*FIXME*//*D*//* reasonable stack size! */ 561 /*FIXME*//*D*//* reasonable stack size! */
554 stack->ssize = -4096 * sizeof (long); 562 stack->ssize = -4096 * sizeof (long);
635 * that doesn't matter, though, since it is only 643 * that doesn't matter, though, since it is only
636 * pp_nextstate and we never return... 644 * pp_nextstate and we never return...
637 * ah yes, and I don't care anyways ;) 645 * ah yes, and I don't care anyways ;)
638 */ 646 */
639 PUTBACK; 647 PUTBACK;
640 PL_op = pp_entersub(); 648 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
641 SPAGAIN; 649 SPAGAIN;
642 650
643 ENTER; /* necessary e.g. for dounwind */ 651 ENTER; /* necessary e.g. for dounwind */
644 } 652 }
645} 653}
649{ 657{
650 /* 658 /*
651 * this is a _very_ stripped down perl interpreter ;) 659 * this is a _very_ stripped down perl interpreter ;)
652 */ 660 */
653 Coro__State ctx = (Coro__State)arg; 661 Coro__State ctx = (Coro__State)arg;
662 JMPENV coro_start_env;
654 663
655 /*FIXME*//* must set up top_env here */ 664 PL_top_env = &ctx->start_env;
665
656 ctx->cursp = 0; 666 ctx->cursp = 0;
657 PL_op = PL_op->op_next; 667 PL_op = PL_op->op_next;
658 CALLRUNOPS(aTHX); 668 CALLRUNOPS(aTHX);
659 669
660 abort (); 670 abort ();
661} 671}
662 672
663STATIC void 673STATIC void
664transfer(pTHX_ struct coro *prev, struct coro *next, int flags) 674transfer(pTHX_ struct coro *prev, struct coro *next, int flags)
665{ 675{
666 dSP;
667 dSTACKLEVEL; 676 dSTACKLEVEL;
677 static struct coro *xnext;
668 678
669 if (prev != next) 679 if (prev != next)
670 { 680 {
681 xnext = next;
682
671 if (next->mainstack) 683 if (next->mainstack)
672 { 684 {
673 SAVE (prev, flags); 685 SAVE (prev, flags);
674 LOAD (next); 686 LOAD (next);
675 687
698 continue_coro, (void *)next, 710 continue_coro, (void *)next,
699 next->stack->sptr, labs (next->stack->ssize)); 711 next->stack->sptr, labs (next->stack->ssize));
700 } 712 }
701 713
702 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); 714 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx));
715 /* don't add any code here */
703 } 716 }
704 717
705 } 718 }
706 else if (next->tmps_ix == -2) 719 else if (next->tmps_ix == -2)
707 croak ("tried to transfer to running coroutine"); 720 croak ("tried to transfer to running coroutine");
714 if (!prev->stack) 727 if (!prev->stack)
715 allocate_stack (prev, 0); 728 allocate_stack (prev, 0);
716 729
717 if (prev->stack->sptr && flags & TRANSFER_LAZY_STACK) 730 if (prev->stack->sptr && flags & TRANSFER_LAZY_STACK)
718 { 731 {
732 PL_top_env = &next->start_env;
733
719 setup_coro (next); 734 setup_coro (next);
720 735
721 prev->stack->refcnt++; 736 prev->stack->refcnt++;
722 prev->stack->usecnt++; 737 prev->stack->usecnt++;
723 next->stack = prev->stack; 738 next->stack = prev->stack;
728 allocate_stack (next, 1); 743 allocate_stack (next, 1);
729 coro_create (&(next->stack->cctx), 744 coro_create (&(next->stack->cctx),
730 setup_coro, (void *)next, 745 setup_coro, (void *)next,
731 next->stack->sptr, labs (next->stack->ssize)); 746 next->stack->sptr, labs (next->stack->ssize));
732 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); 747 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx));
748 /* don't add any code here */
733 } 749 }
734 } 750 }
735 else 751 else
736 setup_coro (next); 752 setup_coro (next);
737 } 753 }
738 }
739 754
755 /*
756 * xnext is now either prev or next, depending on wether
757 * we switched the c stack or not. that's why I use a global
758 * variable, that should become thread-specific at one point.
759 */
740 next->cursp = stacklevel; 760 xnext->cursp = stacklevel;
741}
742
743static struct coro *
744sv_to_coro (SV *arg, const char *funcname, const char *varname)
745{
746 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVHV)
747 { 761 }
762
763 if (coro_mortal)
764 {
765 SvREFCNT_dec (coro_mortal);
766 coro_mortal = 0;
767 }
768}
769
770#define SV_CORO(sv,func) \
771 do { \
772 if (SvROK (sv)) \
773 sv = SvRV (sv); \
774 \
775 if (SvTYPE(sv) == SVt_PVHV) \
776 { \
748 HE *he = hv_fetch_ent((HV *)SvRV(arg), ucoro_state_sv, 0, ucoro_state_hash); 777 HE *he = hv_fetch_ent((HV *)sv, ucoro_state_sv, 0, ucoro_state_hash); \
749 778 \
750 if (!he) 779 if (!he) \
751 croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", funcname, varname); 780 croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", func, # sv); \
752 781 \
753 arg = HeVAL(he); 782 (sv) = SvRV (HeVAL(he)); \
754 } 783 } \
755 784 \
756 /* must also be changed inside Coro::Cont::yield */ 785 /* must also be changed inside Coro::Cont::yield */ \
757 if (SvROK(arg) && SvSTASH(SvRV(arg)) == coro_state_stash) 786 if (!SvOBJECT(sv) || SvSTASH(sv) != coro_state_stash) \
758 return (struct coro *) SvIV((SV*)SvRV(arg));
759
760 croak ("%s() -- %s is not (and contains not) a Coro::State object", funcname, varname); 787 croak ("%s() -- %s is not (and contains not) a Coro::State object", func, # sv); \
761 /*NORETURN*/ 788 \
762} 789 } while(0)
790
791#define SvSTATE(sv) (struct coro *)SvIV (sv)
763 792
764static void 793static void
765api_transfer(pTHX_ SV *prev, SV *next, int flags) 794api_transfer(pTHX_ SV *prev, SV *next, int flags)
766{ 795{
767 transfer(aTHX_ 796 SV_CORO (prev, "Coro::transfer");
768 sv_to_coro (prev, "Coro::transfer", "prev"), 797 SV_CORO (next, "Coro::transfer");
769 sv_to_coro (next, "Coro::transfer", "next"), 798
770 flags); 799 transfer(aTHX_ SvSTATE(prev), SvSTATE(next), flags);
771} 800}
772 801
773/** Coro ********************************************************************/ 802/** Coro ********************************************************************/
774 803
775#define PRIO_MAX 3 804#define PRIO_MAX 3
785static int coro_nready; 814static int coro_nready;
786 815
787static void 816static void
788coro_enq (SV *sv) 817coro_enq (SV *sv)
789{ 818{
790 if (SvROK (sv))
791 {
792 SV *hv = SvRV (sv);
793 if (SvTYPE (hv) == SVt_PVHV) 819 if (SvTYPE (sv) == SVt_PVHV)
794 { 820 {
795 SV **xprio = hv_fetch ((HV *)hv, "prio", 4, 0); 821 SV **xprio = hv_fetch ((HV *)sv, "prio", 4, 0);
796 int prio = xprio ? SvIV (*xprio) : PRIO_NORMAL; 822 int prio = xprio ? SvIV (*xprio) : PRIO_NORMAL;
797 823
798 prio = prio > PRIO_MAX ? PRIO_MAX 824 prio = prio > PRIO_MAX ? PRIO_MAX
799 : prio < PRIO_MIN ? PRIO_MIN 825 : prio < PRIO_MIN ? PRIO_MIN
800 : prio; 826 : prio;
801 827
802 av_push (coro_ready [prio - PRIO_MIN], sv); 828 av_push (coro_ready [prio - PRIO_MIN], sv);
803 coro_nready++; 829 coro_nready++;
804 830
805 return; 831 return;
806 }
807 } 832 }
808 833
809 croak ("Coro::ready tried to enqueue something that is not a coroutine"); 834 croak ("Coro::ready tried to enqueue something that is not a coroutine");
810} 835}
811 836
829} 854}
830 855
831static void 856static void
832api_ready (SV *coro) 857api_ready (SV *coro)
833{ 858{
859 if (SvROK (coro))
860 coro = SvRV (coro);
861
834 coro_enq (SvREFCNT_inc (coro)); 862 coro_enq (SvREFCNT_inc (coro));
835} 863}
836 864
837static void 865static void
838api_schedule (int cede) 866api_schedule (void)
839{ 867{
840 SV *prev, *next; 868 SV *prev, *next;
841 869
842 prev = GvSV (coro_current); 870 prev = SvRV (GvSV (coro_current));
843
844 if (cede)
845 coro_enq (SvREFCNT_inc (prev));
846
847 next = coro_deq (PRIO_MIN); 871 next = coro_deq (PRIO_MIN);
848 872
849 if (!next) 873 if (!next)
850 next = SvREFCNT_inc (GvSV (coro_idle)); 874 next = SvREFCNT_inc (SvRV (GvSV (coro_idle)));
851 875
852 GvSV (coro_current) = SvREFCNT_inc (next); 876 /* free this only after the transfer */
853 transfer (aTHX_ 877 coro_mortal = prev;
854 sv_to_coro (prev, "Coro::schedule", "current coroutine"), 878 SV_CORO (prev, "Coro::schedule");
855 sv_to_coro (next, "Coro::schedule", "next coroutine"), 879
880 SvRV (GvSV (coro_current)) = next;
881
882 SV_CORO (next, "Coro::schedule");
883
884 transfer (aTHX_ SvSTATE (prev), SvSTATE (next),
856 TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK); 885 TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK);
857 SvREFCNT_dec (next); 886}
858 SvREFCNT_dec (prev); 887
888static void
889api_cede (void)
890{
891 coro_enq (SvREFCNT_inc (SvRV (GvSV (coro_current))));
892
893 api_schedule ();
859} 894}
860 895
861MODULE = Coro::State PACKAGE = Coro::State 896MODULE = Coro::State PACKAGE = Coro::State
862 897
863PROTOTYPES: ENABLE 898PROTOTYPES: ENABLE
896 931
897 coro->args = (AV *)SvREFCNT_inc (SvRV (args)); 932 coro->args = (AV *)SvREFCNT_inc (SvRV (args));
898 coro->mainstack = 0; /* actual work is done inside transfer */ 933 coro->mainstack = 0; /* actual work is done inside transfer */
899 coro->stack = 0; 934 coro->stack = 0;
900 935
936 /* same as JMPENV_BOOTSTRAP */
937 /* we might be able to recycle start_env, but safe is safe */
938 Zero(&coro->start_env, 1, JMPENV);
939 coro->start_env.je_ret = -1;
940 coro->start_env.je_mustcatch = TRUE;
941
901 RETVAL = coro; 942 RETVAL = coro;
902 OUTPUT: 943 OUTPUT:
903 RETVAL 944 RETVAL
904 945
905void 946void
906transfer(prev, next, flags) 947transfer(prev, next, flags)
907 Coro::State_or_hashref prev 948 SV *prev
908 Coro::State_or_hashref next 949 SV *next
909 int flags 950 int flags
910 PROTOTYPE: @ 951 PROTOTYPE: @
911 CODE: 952 CODE:
912 PUTBACK; 953 PUTBACK;
954 SV_CORO (next, "Coro::transfer");
955 SV_CORO (prev, "Coro::transfer");
913 transfer (aTHX_ prev, next, flags); 956 transfer (aTHX_ SvSTATE (prev), SvSTATE (next), flags);
914 SPAGAIN; 957 SPAGAIN;
915 958
916void 959void
917DESTROY(coro) 960DESTROY(coro)
918 Coro::State coro 961 Coro::State coro
920 963
921 if (coro->mainstack && coro->mainstack != main_mainstack) 964 if (coro->mainstack && coro->mainstack != main_mainstack)
922 { 965 {
923 struct coro temp; 966 struct coro temp;
924 967
968 PUTBACK;
925 SAVE(aTHX_ (&temp), TRANSFER_SAVE_ALL); 969 SAVE(aTHX_ (&temp), TRANSFER_SAVE_ALL);
926 LOAD(aTHX_ coro); 970 LOAD(aTHX_ coro);
971 SPAGAIN;
927 972
928 destroy_stacks (aTHX); 973 destroy_stacks (aTHX);
929 974
930 LOAD((&temp)); /* this will get rid of defsv etc.. */ 975 LOAD((&temp)); /* this will get rid of defsv etc.. */
976 SPAGAIN;
931 977
932 coro->mainstack = 0; 978 coro->mainstack = 0;
933 } 979 }
934 980
935 deallocate_stack (coro); 981 deallocate_stack (coro);
1010 1056
1011 { 1057 {
1012 SV *sv = perl_get_sv("Coro::API", 1); 1058 SV *sv = perl_get_sv("Coro::API", 1);
1013 1059
1014 coroapi.schedule = api_schedule; 1060 coroapi.schedule = api_schedule;
1061 coroapi.cede = api_cede;
1015 coroapi.ready = api_ready; 1062 coroapi.ready = api_ready;
1016 coroapi.nready = &coro_nready; 1063 coroapi.nready = &coro_nready;
1017 coroapi.current = coro_current; 1064 coroapi.current = coro_current;
1018 1065
1019 GCoroAPI = &coroapi; 1066 GCoroAPI = &coroapi;
1023} 1070}
1024 1071
1025void 1072void
1026ready(self) 1073ready(self)
1027 SV * self 1074 SV * self
1075 PROTOTYPE: $
1028 CODE: 1076 CODE:
1029 api_ready (self); 1077 api_ready (self);
1030 1078
1031int 1079int
1032nready(...) 1080nready(...)
1037 RETVAL 1085 RETVAL
1038 1086
1039void 1087void
1040schedule(...) 1088schedule(...)
1041 PROTOTYPE: 1089 PROTOTYPE:
1042 ALIAS:
1043 cede = 1
1044 CODE: 1090 CODE:
1045 api_schedule (ix); 1091 api_schedule ();
1046 1092
1093void
1094cede(...)
1095 PROTOTYPE:
1096 CODE:
1097 api_cede ();
1098

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines