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.31 by root, Sun Aug 26 16:36:08 2001 UTC vs.
Revision 1.47 by pcg, Sat Nov 15 03:53:10 2003 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include "patchlevel.h"
6
7#if PATCHLEVEL < 6
8# ifndef PL_ppaddr
9# define PL_ppaddr ppaddr
10# endif
11# ifndef call_sv
12# define call_sv perl_call_sv
13# endif
14# ifndef get_sv
15# define get_sv perl_get_sv
16# endif
17# ifndef get_cv
18# define get_cv perl_get_cv
19# endif
20# ifndef IS_PADGV
21# define IS_PADGV(v) 0
22# endif
23# ifndef IS_PADCONST
24# define IS_PADCONST(v) 0
25# endif
26#endif
27
5#include "libcoro/coro.c" 28#include "libcoro/coro.c"
6 29
7#include <signal.h> 30#include <signal.h>
8 31
9#ifdef HAVE_MMAP 32#ifdef HAVE_MMAP
10# include <unistd.h> 33# include <unistd.h>
11# include <sys/mman.h> 34# include <sys/mman.h>
12# ifndef MAP_ANON
13# ifdef MAP_ANONYMOUS 35# ifndef MAP_ANONYMOUS
14# define MAP_ANON MAP_ANONYMOUS 36# ifdef MAP_ANON
37# define MAP_ANONYMOUS MAP_ANON
15# else 38# else
16# undef HAVE_MMAP 39# undef HAVE_MMAP
17# endif 40# endif
18# endif 41# endif
19#endif 42#endif
25 48
26/* The next macro should declare a variable stacklevel that contains and approximation 49/* 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 50 * to the current C stack pointer. Its property is that it changes with each call
28 * and should be unique. */ 51 * and should be unique. */
29#define dSTACKLEVEL void *stacklevel = &stacklevel 52#define dSTACKLEVEL void *stacklevel = &stacklevel
53
54#define IN_DESTRUCT (PL_main_cv == Nullcv)
30 55
31#define labs(l) ((l) >= 0 ? (l) : -(l)) 56#define labs(l) ((l) >= 0 ? (l) : -(l))
32 57
33#include "CoroAPI.h" 58#include "CoroAPI.h"
34 59
45 void *sptr; 70 void *sptr;
46 long ssize; /* positive == mmap, otherwise malloc */ 71 long ssize; /* positive == mmap, otherwise malloc */
47} coro_stack; 72} coro_stack;
48 73
49struct coro { 74struct coro {
75 /* the top-level JMPENV for each coroutine, needed to catch dies. */
76 JMPENV start_env;
77
50 /* the optional C context */ 78 /* the optional C context */
51 coro_stack *stack; 79 coro_stack *stack;
52 void *cursp; 80 void *cursp;
53 int gencnt; 81 int gencnt;
54 82
66 AV *curstack; 94 AV *curstack;
67 AV *mainstack; 95 AV *mainstack;
68 SV **stack_sp; 96 SV **stack_sp;
69 OP *op; 97 OP *op;
70 SV **curpad; 98 SV **curpad;
99 AV *comppad;
71 SV **stack_base; 100 SV **stack_base;
72 SV **stack_max; 101 SV **stack_max;
73 SV **tmps_stack; 102 SV **tmps_stack;
74 I32 tmps_floor; 103 I32 tmps_floor;
75 I32 tmps_ix; 104 I32 tmps_ix;
99static AV *main_mainstack; /* used to differentiate between $main and others */ 128static AV *main_mainstack; /* used to differentiate between $main and others */
100static HV *coro_state_stash; 129static HV *coro_state_stash;
101static SV *ucoro_state_sv; 130static SV *ucoro_state_sv;
102static U32 ucoro_state_hash; 131static U32 ucoro_state_hash;
103static HV *padlist_cache; 132static HV *padlist_cache;
133static SV *coro_mortal; /* will be freed after next transfer */
104 134
105/* mostly copied from op.c:cv_clone2 */ 135/* mostly copied from op.c:cv_clone2 */
106STATIC AV * 136STATIC AV *
107clone_padlist (AV *protopadlist) 137clone_padlist (AV *protopadlist)
108{ 138{
273#define SE } while (0) 303#define SE } while (0)
274 304
275#define LOAD(state) load_state(aTHX_ (state)); 305#define LOAD(state) load_state(aTHX_ (state));
276#define SAVE(state,flags) save_state(aTHX_ (state),(flags)); 306#define SAVE(state,flags) save_state(aTHX_ (state),(flags));
277 307
278#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
279 309
280static void 310static void
281load_state(pTHX_ Coro__State c) 311load_state(pTHX_ Coro__State c)
282{ 312{
283 PL_dowarn = c->dowarn; 313 PL_dowarn = c->dowarn;
287 PL_curstack = c->curstack; 317 PL_curstack = c->curstack;
288 PL_mainstack = c->mainstack; 318 PL_mainstack = c->mainstack;
289 PL_stack_sp = c->stack_sp; 319 PL_stack_sp = c->stack_sp;
290 PL_op = c->op; 320 PL_op = c->op;
291 PL_curpad = c->curpad; 321 PL_curpad = c->curpad;
322 PL_comppad = c->comppad;
292 PL_stack_base = c->stack_base; 323 PL_stack_base = c->stack_base;
293 PL_stack_max = c->stack_max; 324 PL_stack_max = c->stack_max;
294 PL_tmps_stack = c->tmps_stack; 325 PL_tmps_stack = c->tmps_stack;
295 PL_tmps_floor = c->tmps_floor; 326 PL_tmps_floor = c->tmps_floor;
296 PL_tmps_ix = c->tmps_ix; 327 PL_tmps_ix = c->tmps_ix;
384 PUSHs ((SV *)cv); 415 PUSHs ((SV *)cv);
385 416
386 get_padlist (cv); /* this is a monster */ 417 get_padlist (cv); /* this is a monster */
387 } 418 }
388 } 419 }
420#ifdef CXt_FORMAT
389 else if (CxTYPE(cx) == CXt_FORMAT) 421 else if (CxTYPE(cx) == CXt_FORMAT)
390 { 422 {
391 /* I never used formats, so how should I know how these are implemented? */ 423 /* I never used formats, so how should I know how these are implemented? */
392 /* my bold guess is as a simple, plain sub... */ 424 /* my bold guess is as a simple, plain sub... */
393 croak ("CXt_FORMAT not yet handled. Don't switch coroutines from within formats"); 425 croak ("CXt_FORMAT not yet handled. Don't switch coroutines from within formats");
394 } 426 }
427#endif
395 } 428 }
396 429
397 if (top_si->si_type == PERLSI_MAIN) 430 if (top_si->si_type == PERLSI_MAIN)
398 break; 431 break;
399 432
416 c->curstack = PL_curstack; 449 c->curstack = PL_curstack;
417 c->mainstack = PL_mainstack; 450 c->mainstack = PL_mainstack;
418 c->stack_sp = PL_stack_sp; 451 c->stack_sp = PL_stack_sp;
419 c->op = PL_op; 452 c->op = PL_op;
420 c->curpad = PL_curpad; 453 c->curpad = PL_curpad;
454 c->comppad = PL_comppad;
421 c->stack_base = PL_stack_base; 455 c->stack_base = PL_stack_base;
422 c->stack_max = PL_stack_max; 456 c->stack_max = PL_stack_max;
423 c->tmps_stack = PL_tmps_stack; 457 c->tmps_stack = PL_tmps_stack;
424 c->tmps_floor = PL_tmps_floor; 458 c->tmps_floor = PL_tmps_floor;
425 c->tmps_ix = PL_tmps_ix; 459 c->tmps_ix = PL_tmps_ix;
465 499
466 New(54,PL_markstack,16,I32); 500 New(54,PL_markstack,16,I32);
467 PL_markstack_ptr = PL_markstack; 501 PL_markstack_ptr = PL_markstack;
468 PL_markstack_max = PL_markstack + 16; 502 PL_markstack_max = PL_markstack + 16;
469 503
504#ifdef SET_MARK_OFFSET
470 SET_MARK_OFFSET; 505 SET_MARK_OFFSET;
506#endif
471 507
472 New(54,PL_scopestack,16,I32); 508 New(54,PL_scopestack,16,I32);
473 PL_scopestack_ix = 0; 509 PL_scopestack_ix = 0;
474 PL_scopestack_max = 16; 510 PL_scopestack_max = 16;
475 511
487 * still there is a memleak of 128 bytes... 523 * still there is a memleak of 128 bytes...
488 */ 524 */
489STATIC void 525STATIC void
490destroy_stacks(pTHX) 526destroy_stacks(pTHX)
491{ 527{
492 int destruct = PL_main_cv != Nullcv; 528 if (!IN_DESTRUCT)
493
494 if (destruct)
495 { 529 {
496 /* is this ugly, I ask? */ 530 /* is this ugly, I ask? */
497 while (PL_scopestack_ix) 531 while (PL_scopestack_ix)
498 LEAVE; 532 LEAVE;
499 533
513 dSP; 547 dSP;
514 SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); 548 SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack);
515 PUTBACK; /* possibly superfluous */ 549 PUTBACK; /* possibly superfluous */
516 } 550 }
517 551
518 if (destruct) 552 if (!IN_DESTRUCT)
519 { 553 {
520 dounwind(-1); 554 dounwind(-1);
521 SvREFCNT_dec(PL_curstackinfo->si_stack); 555 SvREFCNT_dec(PL_curstackinfo->si_stack);
522 } 556 }
523 557
543 stack->refcnt = 1; 577 stack->refcnt = 1;
544 stack->usecnt = 1; 578 stack->usecnt = 1;
545 stack->gencnt = ctx->gencnt = 0; 579 stack->gencnt = ctx->gencnt = 0;
546 if (alloc) 580 if (alloc)
547 { 581 {
548#ifdef HAVE_MMAP 582#if HAVE_MMAP
549 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */ 583 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */
550 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0); 584 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
551 if (stack->sptr == (void *)-1) 585 if (stack->sptr == (void *)-1)
552#endif 586#endif
553 { 587 {
554 /*FIXME*//*D*//* reasonable stack size! */ 588 /*FIXME*//*D*//* reasonable stack size! */
555 stack->ssize = -4096 * sizeof (long); 589 stack->ssize = -4096 * sizeof (long);
575 { 609 {
576#ifdef HAVE_MMAP 610#ifdef HAVE_MMAP
577 if (stack->ssize > 0 && stack->sptr) 611 if (stack->ssize > 0 && stack->sptr)
578 munmap (stack->sptr, stack->ssize); 612 munmap (stack->sptr, stack->ssize);
579 else 613 else
580#else 614#endif
581 Safefree (stack->sptr); 615 Safefree (stack->sptr);
582#endif 616
583 Safefree (stack); 617 Safefree (stack);
584 } 618 }
585 else if (ctx->gencnt == stack->gencnt) 619 else if (ctx->gencnt == stack->gencnt)
586 --stack->usecnt; 620 --stack->usecnt;
587 } 621 }
599 633
600 coro_init_stacks (aTHX); 634 coro_init_stacks (aTHX);
601 /*PL_curcop = 0;*/ 635 /*PL_curcop = 0;*/
602 /*PL_in_eval = PL_in_eval;*/ /* inherit */ 636 /*PL_in_eval = PL_in_eval;*/ /* inherit */
603 SvREFCNT_dec (GvAV (PL_defgv)); 637 SvREFCNT_dec (GvAV (PL_defgv));
604 GvAV (PL_defgv) = ctx->args; 638 GvAV (PL_defgv) = ctx->args; ctx->args = 0;
605 639
606 SPAGAIN; 640 SPAGAIN;
607 641
608 if (ctx->stack) 642 if (ctx->stack)
609 { 643 {
636 * that doesn't matter, though, since it is only 670 * that doesn't matter, though, since it is only
637 * pp_nextstate and we never return... 671 * pp_nextstate and we never return...
638 * ah yes, and I don't care anyways ;) 672 * ah yes, and I don't care anyways ;)
639 */ 673 */
640 PUTBACK; 674 PUTBACK;
641 PL_op = pp_entersub(); 675 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
642 SPAGAIN; 676 SPAGAIN;
643 677
644 ENTER; /* necessary e.g. for dounwind */ 678 ENTER; /* necessary e.g. for dounwind */
645 } 679 }
646} 680}
650{ 684{
651 /* 685 /*
652 * this is a _very_ stripped down perl interpreter ;) 686 * this is a _very_ stripped down perl interpreter ;)
653 */ 687 */
654 Coro__State ctx = (Coro__State)arg; 688 Coro__State ctx = (Coro__State)arg;
689 JMPENV coro_start_env;
655 690
656 /*FIXME*//* must set up top_env here */ 691 PL_top_env = &ctx->start_env;
692
657 ctx->cursp = 0; 693 ctx->cursp = 0;
658 PL_op = PL_op->op_next; 694 PL_op = PL_op->op_next;
659 CALLRUNOPS(aTHX); 695 CALLRUNOPS(aTHX);
660 696
661 abort (); 697 abort ();
718 if (!prev->stack) 754 if (!prev->stack)
719 allocate_stack (prev, 0); 755 allocate_stack (prev, 0);
720 756
721 if (prev->stack->sptr && flags & TRANSFER_LAZY_STACK) 757 if (prev->stack->sptr && flags & TRANSFER_LAZY_STACK)
722 { 758 {
759 PL_top_env = &next->start_env;
760
723 setup_coro (next); 761 setup_coro (next);
724 762
725 prev->stack->refcnt++; 763 prev->stack->refcnt++;
726 prev->stack->usecnt++; 764 prev->stack->usecnt++;
727 next->stack = prev->stack; 765 next->stack = prev->stack;
728 next->gencnt = prev->gencnt; 766 next->gencnt = prev->gencnt;
729 } 767 }
730 else 768 else
731 { 769 {
770 assert (!next->stack);
732 allocate_stack (next, 1); 771 allocate_stack (next, 1);
733 coro_create (&(next->stack->cctx), 772 coro_create (&(next->stack->cctx),
734 setup_coro, (void *)next, 773 setup_coro, (void *)next,
735 next->stack->sptr, labs (next->stack->ssize)); 774 next->stack->sptr, labs (next->stack->ssize));
736 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); 775 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx));
738 } 777 }
739 } 778 }
740 else 779 else
741 setup_coro (next); 780 setup_coro (next);
742 } 781 }
782
783 /*
784 * xnext is now either prev or next, depending on wether
785 * we switched the c stack or not. that's why I use a global
786 * variable, that should become thread-specific at one point.
787 */
788 xnext->cursp = stacklevel;
743 } 789 }
744 790
745 /* 791 if (coro_mortal)
746 * xnext is now either prev or next, depending on wether
747 * we switched the c stack or not. that's why i use a global
748 * variable, that should become thread-specific at one point.
749 */
750 xnext->cursp = stacklevel;
751}
752
753static struct coro *
754sv_to_coro (SV *arg, const char *funcname, const char *varname)
755{
756 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVHV)
757 { 792 {
758 HE *he = hv_fetch_ent((HV *)SvRV(arg), ucoro_state_sv, 0, ucoro_state_hash); 793 SvREFCNT_dec (coro_mortal);
759 794 coro_mortal = 0;
760 if (!he)
761 croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", funcname, varname);
762
763 arg = HeVAL(he);
764 } 795 }
765 796}
797
798#define SV_CORO(sv,func) \
799 do { \
800 if (SvROK (sv)) \
801 sv = SvRV (sv); \
802 \
803 if (SvTYPE(sv) == SVt_PVHV) \
804 { \
805 HE *he = hv_fetch_ent((HV *)sv, ucoro_state_sv, 0, ucoro_state_hash); \
806 \
807 if (!he) \
808 croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", func, # sv); \
809 \
810 (sv) = SvRV (HeVAL(he)); \
811 } \
812 \
766 /* must also be changed inside Coro::Cont::yield */ 813 /* must also be changed inside Coro::Cont::yield */ \
767 if (SvROK(arg) && SvSTASH(SvRV(arg)) == coro_state_stash) 814 if (!SvOBJECT(sv) || SvSTASH(sv) != coro_state_stash) \
768 return (struct coro *) SvIV((SV*)SvRV(arg));
769
770 croak ("%s() -- %s is not (and contains not) a Coro::State object", funcname, varname); 815 croak ("%s() -- %s is not (and contains not) a Coro::State object", func, # sv); \
771 /*NORETURN*/ 816 \
772} 817 } while(0)
818
819#define SvSTATE(sv) (struct coro *)SvIV (sv)
773 820
774static void 821static void
775api_transfer(pTHX_ SV *prev, SV *next, int flags) 822api_transfer(pTHX_ SV *prev, SV *next, int flags)
776{ 823{
777 transfer(aTHX_ 824 SV_CORO (prev, "Coro::transfer");
778 sv_to_coro (prev, "Coro::transfer", "prev"), 825 SV_CORO (next, "Coro::transfer");
779 sv_to_coro (next, "Coro::transfer", "next"), 826
780 flags); 827 transfer(aTHX_ SvSTATE(prev), SvSTATE(next), flags);
781} 828}
782 829
783/** Coro ********************************************************************/ 830/** Coro ********************************************************************/
784 831
785#define PRIO_MAX 3 832#define PRIO_MAX 3
795static int coro_nready; 842static int coro_nready;
796 843
797static void 844static void
798coro_enq (SV *sv) 845coro_enq (SV *sv)
799{ 846{
800 if (SvROK (sv))
801 {
802 SV *hv = SvRV (sv);
803 if (SvTYPE (hv) == SVt_PVHV) 847 if (SvTYPE (sv) == SVt_PVHV)
804 { 848 {
805 SV **xprio = hv_fetch ((HV *)hv, "prio", 4, 0); 849 SV **xprio = hv_fetch ((HV *)sv, "prio", 4, 0);
806 int prio = xprio ? SvIV (*xprio) : PRIO_NORMAL; 850 int prio = xprio ? SvIV (*xprio) : PRIO_NORMAL;
807 851
808 prio = prio > PRIO_MAX ? PRIO_MAX 852 prio = prio > PRIO_MAX ? PRIO_MAX
809 : prio < PRIO_MIN ? PRIO_MIN 853 : prio < PRIO_MIN ? PRIO_MIN
810 : prio; 854 : prio;
811 855
812 av_push (coro_ready [prio - PRIO_MIN], sv); 856 av_push (coro_ready [prio - PRIO_MIN], sv);
813 coro_nready++; 857 coro_nready++;
814 858
815 return; 859 return;
816 }
817 } 860 }
818 861
819 croak ("Coro::ready tried to enqueue something that is not a coroutine"); 862 croak ("Coro::ready tried to enqueue something that is not a coroutine");
820} 863}
821 864
839} 882}
840 883
841static void 884static void
842api_ready (SV *coro) 885api_ready (SV *coro)
843{ 886{
887 if (SvROK (coro))
888 coro = SvRV (coro);
889
844 coro_enq (SvREFCNT_inc (coro)); 890 coro_enq (SvREFCNT_inc (coro));
845} 891}
846 892
847static void 893static void
848api_schedule (int cede) 894api_schedule (void)
849{ 895{
850 SV *prev, *next; 896 SV *prev, *next;
851 897
852 prev = GvSV (coro_current); 898 prev = SvRV (GvSV (coro_current));
853
854 if (cede)
855 coro_enq (SvREFCNT_inc (prev));
856
857 next = coro_deq (PRIO_MIN); 899 next = coro_deq (PRIO_MIN);
858 900
859 if (!next) 901 if (!next)
860 next = SvREFCNT_inc (GvSV (coro_idle)); 902 next = SvREFCNT_inc (SvRV (GvSV (coro_idle)));
861 903
862 GvSV (coro_current) = SvREFCNT_inc (next); 904 /* free this only after the transfer */
863 transfer (aTHX_ 905 coro_mortal = prev;
864 sv_to_coro (prev, "Coro::schedule", "current coroutine"), 906 SV_CORO (prev, "Coro::schedule");
865 sv_to_coro (next, "Coro::schedule", "next coroutine"), 907
908 SvRV (GvSV (coro_current)) = next;
909
910 SV_CORO (next, "Coro::schedule");
911
912 transfer (aTHX_ SvSTATE (prev), SvSTATE (next),
866 TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK); 913 TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK);
867 SvREFCNT_dec (next); 914}
868 SvREFCNT_dec (prev); 915
916static void
917api_cede (void)
918{
919 coro_enq (SvREFCNT_inc (SvRV (GvSV (coro_current))));
920
921 api_schedule ();
869} 922}
870 923
871MODULE = Coro::State PACKAGE = Coro::State 924MODULE = Coro::State PACKAGE = Coro::State
872 925
873PROTOTYPES: ENABLE 926PROTOTYPES: ENABLE
900 Coro__State coro; 953 Coro__State coro;
901 954
902 if (!SvROK (args) || SvTYPE (SvRV (args)) != SVt_PVAV) 955 if (!SvROK (args) || SvTYPE (SvRV (args)) != SVt_PVAV)
903 croak ("Coro::State::_newprocess expects an arrayref"); 956 croak ("Coro::State::_newprocess expects an arrayref");
904 957
905 New (0, coro, 1, struct coro); 958 Newz (0, coro, 1, struct coro);
906 959
907 coro->args = (AV *)SvREFCNT_inc (SvRV (args)); 960 coro->args = (AV *)SvREFCNT_inc (SvRV (args));
908 coro->mainstack = 0; /* actual work is done inside transfer */ 961 coro->mainstack = 0; /* actual work is done inside transfer */
909 coro->stack = 0; 962 coro->stack = 0;
910 963
964 /* same as JMPENV_BOOTSTRAP */
965 /* we might be able to recycle start_env, but safe is safe */
966 //Zero(&coro->start_env, 1, JMPENV);
967 coro->start_env.je_ret = -1;
968 coro->start_env.je_mustcatch = TRUE;
969
911 RETVAL = coro; 970 RETVAL = coro;
912 OUTPUT: 971 OUTPUT:
913 RETVAL 972 RETVAL
914 973
915void 974void
916transfer(prev, next, flags) 975transfer(prev, next, flags)
917 Coro::State_or_hashref prev 976 SV *prev
918 Coro::State_or_hashref next 977 SV *next
919 int flags 978 int flags
920 PROTOTYPE: @ 979 PROTOTYPE: @
921 CODE: 980 CODE:
922 PUTBACK; 981 PUTBACK;
982 SV_CORO (next, "Coro::transfer");
983 SV_CORO (prev, "Coro::transfer");
923 transfer (aTHX_ prev, next, flags); 984 transfer (aTHX_ SvSTATE (prev), SvSTATE (next), flags);
924 SPAGAIN; 985 SPAGAIN;
925 986
926void 987void
927DESTROY(coro) 988DESTROY(coro)
928 Coro::State coro 989 Coro::State coro
944 1005
945 coro->mainstack = 0; 1006 coro->mainstack = 0;
946 } 1007 }
947 1008
948 deallocate_stack (coro); 1009 deallocate_stack (coro);
949 1010 SvREFCNT_dec (coro->args);
950 Safefree (coro); 1011 Safefree (coro);
951 1012
952void 1013void
953flush() 1014flush()
954 CODE: 1015 CODE:
981 SV *sv; 1042 SV *sv;
982 AV *defav = GvAV (PL_defgv); 1043 AV *defav = GvAV (PL_defgv);
983 struct coro *prev, *next; 1044 struct coro *prev, *next;
984 1045
985 if (!returnstk) 1046 if (!returnstk)
986 returnstk = SvRV (get_sv ("Coro::Cont::return", FALSE)); 1047 returnstk = SvRV ((SV *)get_sv ("Coro::Cont::return", FALSE));
987 1048
988 /* set up @_ -- ugly */ 1049 /* set up @_ -- ugly */
989 av_clear (defav); 1050 av_clear (defav);
990 av_fill (defav, items - 1); 1051 av_fill (defav, items - 1);
991 while (items--) 1052 while (items--)
1023 1084
1024 { 1085 {
1025 SV *sv = perl_get_sv("Coro::API", 1); 1086 SV *sv = perl_get_sv("Coro::API", 1);
1026 1087
1027 coroapi.schedule = api_schedule; 1088 coroapi.schedule = api_schedule;
1089 coroapi.cede = api_cede;
1028 coroapi.ready = api_ready; 1090 coroapi.ready = api_ready;
1029 coroapi.nready = &coro_nready; 1091 coroapi.nready = &coro_nready;
1030 coroapi.current = coro_current; 1092 coroapi.current = coro_current;
1031 1093
1032 GCoroAPI = &coroapi; 1094 GCoroAPI = &coroapi;
1036} 1098}
1037 1099
1038void 1100void
1039ready(self) 1101ready(self)
1040 SV * self 1102 SV * self
1103 PROTOTYPE: $
1041 CODE: 1104 CODE:
1042 api_ready (self); 1105 api_ready (self);
1043 1106
1044int 1107int
1045nready(...) 1108nready(...)
1050 RETVAL 1113 RETVAL
1051 1114
1052void 1115void
1053schedule(...) 1116schedule(...)
1054 PROTOTYPE: 1117 PROTOTYPE:
1055 ALIAS:
1056 cede = 1
1057 CODE: 1118 CODE:
1058 api_schedule (ix); 1119 api_schedule ();
1059 1120
1121void
1122cede(...)
1123 PROTOTYPE:
1124 CODE:
1125 api_cede ();
1126

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines