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.16 by root, Wed Jul 25 04:26:55 2001 UTC vs.
Revision 1.29 by root, Sat Aug 25 21:40:34 2001 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 "libcoro/coro.c" 5#include "libcoro/coro.c"
6
7#include <signal.h>
6 8
7#ifdef HAVE_MMAP 9#ifdef HAVE_MMAP
8# include <unistd.h> 10# include <unistd.h>
9# include <sys/mman.h> 11# include <sys/mman.h>
10# ifndef MAP_ANON 12# ifndef MAP_ANON
14# undef HAVE_MMAP 16# undef HAVE_MMAP
15# endif 17# endif
16# endif 18# endif
17#endif 19#endif
18 20
19#define MAY_FLUSH /* increases codesize */ 21#define MAY_FLUSH /* increases codesize and is rarely used */
20
21/* perl-related */
22#define TRANSFER_SAVE_DEFAV 0x00000001
23#define TRANSFER_SAVE_DEFSV 0x00000002
24#define TRANSFER_SAVE_ERRSV 0x00000004
25/* c-related */
26#define TRANSFER_SAVE_CCTXT 0x00000008
27#ifdef CORO_LAZY_STACK
28# define TRANSFER_LAZY_STACK 0x00000010
29#else
30# define TRANSFER_LAZY_STACK 0x00000000
31#endif
32
33#define TRANSFER_SAVE_ALL (TRANSFER_SAVE_DEFAV|TRANSFER_SAVE_DEFSV \
34 |TRANSFER_SAVE_ERRSV|TRANSFER_SAVE_CCTXT)
35 22
36#define SUB_INIT "Coro::State::initialize" 23#define SUB_INIT "Coro::State::initialize"
37#define UCORO_STATE "_coro_state" 24#define UCORO_STATE "_coro_state"
38 25
39/* 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
40 * to the current C stack pointer. It's property is that it changes with each call 27 * to the current C stack pointer. Its property is that it changes with each call
41 * and should be unique. */ 28 * and should be unique. */
42#define dSTACKLEVEL void *stacklevel = &stacklevel 29#define dSTACKLEVEL void *stacklevel = &stacklevel
43 30
44#define labs(l) ((l) >= 0 ? (l) : -(l)) 31#define labs(l) ((l) >= 0 ? (l) : -(l))
32
33#include "CoroAPI.h"
34
35static struct CoroAPI coroapi;
45 36
46/* this is actually not only the c stack but also c registers etc... */ 37/* this is actually not only the c stack but also c registers etc... */
47typedef struct { 38typedef struct {
48 int refcnt; /* pointer reference counter */ 39 int refcnt; /* pointer reference counter */
49 int usecnt; /* shared by how many coroutines */ 40 int usecnt; /* shared by how many coroutines */
52 coro_context cctx; 43 coro_context cctx;
53 44
54 void *sptr; 45 void *sptr;
55 long ssize; /* positive == mmap, otherwise malloc */ 46 long ssize; /* positive == mmap, otherwise malloc */
56} coro_stack; 47} coro_stack;
57
58static coro_stack main_stack = { 1, 0, 0 };
59 48
60struct coro { 49struct coro {
61 /* the optional C context */ 50 /* the optional C context */
62 coro_stack *stack; 51 coro_stack *stack;
63 void *cursp; 52 void *cursp;
68 SV *defsv; 57 SV *defsv;
69 SV *errsv; 58 SV *errsv;
70 59
71 /* saved global state not related to stacks */ 60 /* saved global state not related to stacks */
72 U8 dowarn; 61 U8 dowarn;
62 I32 in_eval;
73 63
74 /* the stacks and related info (callchain etc..) */ 64 /* the stacks and related info (callchain etc..) */
75 PERL_SI *curstackinfo; 65 PERL_SI *curstackinfo;
76 AV *curstack; 66 AV *curstack;
77 AV *mainstack; 67 AV *mainstack;
95 I32 savestack_max; 85 I32 savestack_max;
96 OP **retstack; 86 OP **retstack;
97 I32 retstack_ix; 87 I32 retstack_ix;
98 I32 retstack_max; 88 I32 retstack_max;
99 COP *curcop; 89 COP *curcop;
100 JMPENV start_env;
101 JMPENV *top_env; 90 JMPENV *top_env;
102 91
103 /* data associated with this coroutine (initial args) */ 92 /* data associated with this coroutine (initial args) */
104 AV *args; 93 AV *args;
105}; 94};
206 195
207 return newpadlist; 196 return newpadlist;
208} 197}
209 198
210#ifdef MAY_FLUSH 199#ifdef MAY_FLUSH
211STATIC AV * 200STATIC void
212free_padlist (AV *padlist) 201free_padlist (AV *padlist)
213{ 202{
214 /* may be during global destruction */ 203 /* may be during global destruction */
215 if (SvREFCNT(padlist)) 204 if (SvREFCNT(padlist))
216 { 205 {
281#endif 270#endif
282 271
283#define SB do { 272#define SB do {
284#define SE } while (0) 273#define SE } while (0)
285 274
286#define LOAD(state) SB load_state(aTHX_ (state)); SPAGAIN; SE 275#define LOAD(state) load_state(aTHX_ (state));
287#define SAVE(state,flags) SB PUTBACK; save_state(aTHX_ (state),(flags)); SE 276#define SAVE(state,flags) save_state(aTHX_ (state),(flags));
288 277
289#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); SE 278#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); SE
290 279
291static void 280static void
292load_state(pTHX_ Coro__State c) 281load_state(pTHX_ Coro__State c)
293{ 282{
294 PL_dowarn = c->dowarn; 283 PL_dowarn = c->dowarn;
284 PL_in_eval = c->in_eval;
295 285
296 PL_curstackinfo = c->curstackinfo; 286 PL_curstackinfo = c->curstackinfo;
297 PL_curstack = c->curstack; 287 PL_curstack = c->curstack;
298 PL_mainstack = c->mainstack; 288 PL_mainstack = c->mainstack;
299 PL_stack_sp = c->stack_sp; 289 PL_stack_sp = c->stack_sp;
316 PL_savestack_max = c->savestack_max; 306 PL_savestack_max = c->savestack_max;
317 PL_retstack = c->retstack; 307 PL_retstack = c->retstack;
318 PL_retstack_ix = c->retstack_ix; 308 PL_retstack_ix = c->retstack_ix;
319 PL_retstack_max = c->retstack_max; 309 PL_retstack_max = c->retstack_max;
320 PL_curcop = c->curcop; 310 PL_curcop = c->curcop;
321 PL_start_env = c->start_env;
322 PL_top_env = c->top_env; 311 PL_top_env = c->top_env;
323 312
324 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); 313 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav);
325 if (c->defsv) REPLACE_SV (DEFSV , c->defsv); 314 if (c->defsv) REPLACE_SV (DEFSV , c->defsv);
326 if (c->errsv) REPLACE_SV (ERRSV , c->errsv); 315 if (c->errsv) REPLACE_SV (ERRSV , c->errsv);
419 408
420 c->defav = flags & TRANSFER_SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0; 409 c->defav = flags & TRANSFER_SAVE_DEFAV ? (AV *)SvREFCNT_inc (GvAV (PL_defgv)) : 0;
421 c->defsv = flags & TRANSFER_SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0; 410 c->defsv = flags & TRANSFER_SAVE_DEFSV ? SvREFCNT_inc (DEFSV) : 0;
422 c->errsv = flags & TRANSFER_SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0; 411 c->errsv = flags & TRANSFER_SAVE_ERRSV ? SvREFCNT_inc (ERRSV) : 0;
423 412
424 /* I have not the slightest idea of why av_reify is necessary */
425 /* but if it's missing the defav contents magically get replaced sometimes */
426 if (c->defav)
427 av_reify (c->defav);
428
429 c->dowarn = PL_dowarn; 413 c->dowarn = PL_dowarn;
414 c->in_eval = PL_in_eval;
430 415
431 c->curstackinfo = PL_curstackinfo; 416 c->curstackinfo = PL_curstackinfo;
432 c->curstack = PL_curstack; 417 c->curstack = PL_curstack;
433 c->mainstack = PL_mainstack; 418 c->mainstack = PL_mainstack;
434 c->stack_sp = PL_stack_sp; 419 c->stack_sp = PL_stack_sp;
451 c->savestack_max = PL_savestack_max; 436 c->savestack_max = PL_savestack_max;
452 c->retstack = PL_retstack; 437 c->retstack = PL_retstack;
453 c->retstack_ix = PL_retstack_ix; 438 c->retstack_ix = PL_retstack_ix;
454 c->retstack_max = PL_retstack_max; 439 c->retstack_max = PL_retstack_max;
455 c->curcop = PL_curcop; 440 c->curcop = PL_curcop;
456 c->start_env = PL_start_env;
457 c->top_env = PL_top_env; 441 c->top_env = PL_top_env;
458} 442}
459 443
460/* 444/*
461 * allocate various perl stacks. This is an exact copy 445 * allocate various perl stacks. This is an exact copy
525 dSP; 509 dSP;
526 SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack); 510 SWITCHSTACK (PL_curstack, PL_curstackinfo->si_stack);
527 PUTBACK; /* possibly superfluous */ 511 PUTBACK; /* possibly superfluous */
528 } 512 }
529 513
514 if (PL_main_cv != Nullcv) /* don't during destruction. hack? */
530 dounwind(-1); 515 dounwind(-1);
531 516
532 SvREFCNT_dec(PL_curstackinfo->si_stack); 517 SvREFCNT_dec(PL_curstackinfo->si_stack);
533 Safefree(PL_curstackinfo->si_cxstack); 518 Safefree(PL_curstackinfo->si_cxstack);
534 Safefree(PL_curstackinfo); 519 Safefree(PL_curstackinfo);
535 PL_curstackinfo = p; 520 PL_curstackinfo = p;
553 stack->usecnt = 1; 538 stack->usecnt = 1;
554 stack->gencnt = ctx->gencnt = 0; 539 stack->gencnt = ctx->gencnt = 0;
555 if (alloc) 540 if (alloc)
556 { 541 {
557#ifdef HAVE_MMAP 542#ifdef HAVE_MMAP
558 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write */ 543 stack->ssize = 128 * 1024 * sizeof (long); /* mmap should do allocate-on-write for us */
559 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0); 544 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
560 if (stack->sptr == (void *)-1) 545 if (stack->sptr == (void *)-1)
561#endif 546#endif
562 { 547 {
563 /*FIXME*//*D*//* reasonable stack size! */ 548 /*FIXME*//*D*//* reasonable stack size! */
605 dSP; 590 dSP;
606 Coro__State ctx = (Coro__State)arg; 591 Coro__State ctx = (Coro__State)arg;
607 SV *sub_init = (SV*)get_cv(SUB_INIT, FALSE); 592 SV *sub_init = (SV*)get_cv(SUB_INIT, FALSE);
608 593
609 coro_init_stacks (aTHX); 594 coro_init_stacks (aTHX);
610 JMPENV_BOOTSTRAP;
611 SPAGAIN;
612
613 /*PL_curcop = 0;*/ 595 /*PL_curcop = 0;*/
596 /*PL_in_eval = PL_in_eval;*/ /* inherit */
614 SvREFCNT_dec (GvAV (PL_defgv)); 597 SvREFCNT_dec (GvAV (PL_defgv));
615 GvAV (PL_defgv) = ctx->args; 598 GvAV (PL_defgv) = ctx->args;
616 599
600 SPAGAIN;
601
617 if (ctx->stack) 602 if (ctx->stack)
618 { 603 {
619 ctx->cursp = 0; 604 ctx->cursp = 0;
620 605
621 PUSHMARK(SP); 606 PUSHMARK(SP);
622 PUTBACK; 607 PUTBACK;
623 (void) call_sv (sub_init, G_VOID|G_NOARGS); 608 (void) call_sv (sub_init, G_VOID|G_NOARGS|G_EVAL);
609
610 if (SvTRUE (ERRSV))
611 croak (NULL);
612 else
624 croak ("FATAL: CCTXT coroutine returned!"); 613 croak ("FATAL: CCTXT coroutine returned!");
625 } 614 }
626 else 615 else
627 { 616 {
628 UNOP myop; 617 UNOP myop;
629 618
656 /* 645 /*
657 * this is a _very_ stripped down perl interpreter ;) 646 * this is a _very_ stripped down perl interpreter ;)
658 */ 647 */
659 Coro__State ctx = (Coro__State)arg; 648 Coro__State ctx = (Coro__State)arg;
660 649
650 /*FIXME*//* must set up top_env here */
661 ctx->cursp = 0; 651 ctx->cursp = 0;
662 PL_op = PL_op->op_next; 652 PL_op = PL_op->op_next;
663 CALLRUNOPS(aTHX); 653 CALLRUNOPS(aTHX);
664 /*NORETURN*/ 654
665 abort (); 655 abort ();
666} 656}
667 657
668STATIC void 658STATIC void
669transfer(pTHX_ struct coro *prev, struct coro *next, int flags) 659transfer(pTHX_ struct coro *prev, struct coro *next, int flags)
670{ 660{
671 dSP;
672 dSTACKLEVEL; 661 dSTACKLEVEL;
662 static struct coro *xnext;
673 663
674 if (prev != next) 664 if (prev != next)
675 { 665 {
666 xnext = next;
667
676 if (next->mainstack) 668 if (next->mainstack)
677 { 669 {
678 SAVE (prev, flags); 670 SAVE (prev, flags);
679 LOAD (next); 671 LOAD (next);
680 672
703 continue_coro, (void *)next, 695 continue_coro, (void *)next,
704 next->stack->sptr, labs (next->stack->ssize)); 696 next->stack->sptr, labs (next->stack->ssize));
705 } 697 }
706 698
707 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); 699 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx));
700 /* don't add any code here */
708 } 701 }
709 702
710 } 703 }
711 else if (next->tmps_ix == -2) 704 else if (next->tmps_ix == -2)
712 croak ("tried to transfer to running coroutine"); 705 croak ("tried to transfer to running coroutine");
733 allocate_stack (next, 1); 726 allocate_stack (next, 1);
734 coro_create (&(next->stack->cctx), 727 coro_create (&(next->stack->cctx),
735 setup_coro, (void *)next, 728 setup_coro, (void *)next,
736 next->stack->sptr, labs (next->stack->ssize)); 729 next->stack->sptr, labs (next->stack->ssize));
737 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx)); 730 coro_transfer (&(prev->stack->cctx), &(next->stack->cctx));
731 /* don't add any code here */
738 } 732 }
739 } 733 }
740 else 734 else
741 setup_coro (next); 735 setup_coro (next);
742 } 736 }
743 } 737 }
744 738
739 /*
740 * xnext is now either prev or next, depending on wether
741 * we switched the c stack or not. that's why i use a global
742 * variable, that should become thread-specific at one point.
743 */
745 next->cursp = stacklevel; 744 xnext->cursp = stacklevel;
745}
746
747static struct coro *
748sv_to_coro (SV *arg, const char *funcname, const char *varname)
749{
750 if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVHV)
751 {
752 HE *he = hv_fetch_ent((HV *)SvRV(arg), ucoro_state_sv, 0, ucoro_state_hash);
753
754 if (!he)
755 croak ("%s() -- %s is a hashref but lacks the " UCORO_STATE " key", funcname, varname);
756
757 arg = HeVAL(he);
758 }
759
760 /* must also be changed inside Coro::Cont::yield */
761 if (SvROK(arg) && SvSTASH(SvRV(arg)) == coro_state_stash)
762 return (struct coro *) SvIV((SV*)SvRV(arg));
763
764 croak ("%s() -- %s is not (and contains not) a Coro::State object", funcname, varname);
765 /*NORETURN*/
766}
767
768static void
769api_transfer(pTHX_ SV *prev, SV *next, int flags)
770{
771 transfer(aTHX_
772 sv_to_coro (prev, "Coro::transfer", "prev"),
773 sv_to_coro (next, "Coro::transfer", "next"),
774 flags);
775}
776
777/** Coro ********************************************************************/
778
779#define PRIO_MAX 3
780#define PRIO_HIGH 1
781#define PRIO_NORMAL 0
782#define PRIO_LOW -1
783#define PRIO_IDLE -3
784#define PRIO_MIN -4
785
786/* for Coro.pm */
787static GV *coro_current, *coro_idle;
788static AV *coro_ready[PRIO_MAX-PRIO_MIN+1];
789static int coro_nready;
790
791static void
792coro_enq (SV *sv)
793{
794 if (SvROK (sv))
795 {
796 SV *hv = SvRV (sv);
797 if (SvTYPE (hv) == SVt_PVHV)
798 {
799 SV **xprio = hv_fetch ((HV *)hv, "prio", 4, 0);
800 int prio = xprio ? SvIV (*xprio) : PRIO_NORMAL;
801
802 prio = prio > PRIO_MAX ? PRIO_MAX
803 : prio < PRIO_MIN ? PRIO_MIN
804 : prio;
805
806 av_push (coro_ready [prio - PRIO_MIN], sv);
807 coro_nready++;
808
809 return;
810 }
811 }
812
813 croak ("Coro::ready tried to enqueue something that is not a coroutine");
814}
815
816static SV *
817coro_deq (int min_prio)
818{
819 int prio = PRIO_MAX - PRIO_MIN;
820
821 min_prio -= PRIO_MIN;
822 if (min_prio < 0)
823 min_prio = 0;
824
825 for (prio = PRIO_MAX - PRIO_MIN + 1; --prio >= min_prio; )
826 if (av_len (coro_ready[prio]) >= 0)
827 {
828 coro_nready--;
829 return av_shift (coro_ready[prio]);
830 }
831
832 return 0;
833}
834
835static void
836api_ready (SV *coro)
837{
838 coro_enq (SvREFCNT_inc (coro));
839}
840
841static void
842api_schedule (int cede)
843{
844 SV *prev, *next;
845
846 prev = GvSV (coro_current);
847
848 if (cede)
849 coro_enq (SvREFCNT_inc (prev));
850
851 next = coro_deq (PRIO_MIN);
852
853 if (!next)
854 next = SvREFCNT_inc (GvSV (coro_idle));
855
856 GvSV (coro_current) = SvREFCNT_inc (next);
857 transfer (aTHX_
858 sv_to_coro (prev, "Coro::schedule", "current coroutine"),
859 sv_to_coro (next, "Coro::schedule", "next coroutine"),
860 TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK);
861 SvREFCNT_dec (next);
862 SvREFCNT_dec (prev);
746} 863}
747 864
748MODULE = Coro::State PACKAGE = Coro::State 865MODULE = Coro::State PACKAGE = Coro::State
749 866
750PROTOTYPES: ENABLE 867PROTOTYPES: ENABLE
762 879
763 if (!padlist_cache) 880 if (!padlist_cache)
764 padlist_cache = newHV (); 881 padlist_cache = newHV ();
765 882
766 main_mainstack = PL_mainstack; 883 main_mainstack = PL_mainstack;
884
885 coroapi.ver = CORO_API_VERSION;
886 coroapi.transfer = api_transfer;
767} 887}
768 888
769Coro::State 889Coro::State
770_newprocess(args) 890_newprocess(args)
771 SV * args 891 SV * args
785 RETVAL = coro; 905 RETVAL = coro;
786 OUTPUT: 906 OUTPUT:
787 RETVAL 907 RETVAL
788 908
789void 909void
790transfer(prev, next, flags = TRANSFER_SAVE_ALL | TRANSFER_LAZY_STACK) 910transfer(prev, next, flags)
791 Coro::State_or_hashref prev 911 Coro::State_or_hashref prev
792 Coro::State_or_hashref next 912 Coro::State_or_hashref next
793 int flags 913 int flags
794 PROTOTYPE: @ 914 PROTOTYPE: @
795 CODE: 915 CODE:
916 PUTBACK;
796 transfer (aTHX_ prev, next, flags); 917 transfer (aTHX_ prev, next, flags);
918 SPAGAIN;
797 919
798void 920void
799DESTROY(coro) 921DESTROY(coro)
800 Coro::State coro 922 Coro::State coro
801 CODE: 923 CODE:
802 924
803 if (coro->mainstack && coro->mainstack != main_mainstack) 925 if (coro->mainstack && coro->mainstack != main_mainstack)
804 { 926 {
805 struct coro temp; 927 struct coro temp;
806 928
929 PUTBACK;
807 SAVE(aTHX_ (&temp), TRANSFER_SAVE_ALL); 930 SAVE(aTHX_ (&temp), TRANSFER_SAVE_ALL);
808 LOAD(aTHX_ coro); 931 LOAD(aTHX_ coro);
932 SPAGAIN;
809 933
810 destroy_stacks (aTHX); 934 destroy_stacks (aTHX);
811 935
812 LOAD((&temp)); /* this will get rid of defsv etc.. */ 936 LOAD((&temp)); /* this will get rid of defsv etc.. */
937 SPAGAIN;
813 938
814 coro->mainstack = 0; 939 coro->mainstack = 0;
815 } 940 }
816 941
817 deallocate_stack (coro); 942 deallocate_stack (coro);
823 CODE: 948 CODE:
824#ifdef MAY_FLUSH 949#ifdef MAY_FLUSH
825 flush_padlist_cache (); 950 flush_padlist_cache ();
826#endif 951#endif
827 952
953void
954_exit(code)
955 int code
956 PROTOTYPE: $
957 CODE:
958#if defined(__GLIBC__) || _POSIX_C_SOURCE
959 _exit (code);
960#else
961 signal (SIGTERM, SIG_DFL);
962 raise (SIGTERM);
963 exit (code);
964#endif
965
828MODULE = Coro::State PACKAGE = Coro::Cont 966MODULE = Coro::State PACKAGE = Coro::Cont
829 967
830# this is slightly dirty 968# this is slightly dirty (should expose a c-level api)
831 969
832void 970void
833yield(...) 971yield(...)
834 PROTOTYPE: @ 972 PROTOTYPE: @
835 CODE: 973 CODE:
853 next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0))); 991 next = (struct coro *)SvIV ((SV*)SvRV (*av_fetch ((AV *)SvRV (sv), 1, 0)));
854 SvREFCNT_dec (sv); 992 SvREFCNT_dec (sv);
855 993
856 transfer(aTHX_ prev, next, 0); 994 transfer(aTHX_ prev, next, 0);
857 995
996MODULE = Coro::State PACKAGE = Coro
997
998# this is slightly dirty (should expose a c-level api)
999
1000BOOT:
1001{
1002 int i;
1003 HV *stash = gv_stashpv ("Coro", TRUE);
1004
1005 newCONSTSUB (stash, "PRIO_MAX", newSViv (PRIO_MAX));
1006 newCONSTSUB (stash, "PRIO_HIGH", newSViv (PRIO_HIGH));
1007 newCONSTSUB (stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL));
1008 newCONSTSUB (stash, "PRIO_LOW", newSViv (PRIO_LOW));
1009 newCONSTSUB (stash, "PRIO_IDLE", newSViv (PRIO_IDLE));
1010 newCONSTSUB (stash, "PRIO_MIN", newSViv (PRIO_MIN));
1011
1012 coro_current = gv_fetchpv ("Coro::current", TRUE, SVt_PV);
1013 coro_idle = gv_fetchpv ("Coro::idle" , TRUE, SVt_PV);
1014
1015 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
1016 coro_ready[i] = newAV ();
1017
1018 {
1019 SV *sv = perl_get_sv("Coro::API", 1);
1020
1021 coroapi.schedule = api_schedule;
1022 coroapi.ready = api_ready;
1023 coroapi.nready = &coro_nready;
1024 coroapi.current = coro_current;
1025
1026 GCoroAPI = &coroapi;
1027 sv_setiv(sv, (IV)&coroapi);
1028 SvREADONLY_on(sv);
1029 }
1030}
1031
1032void
1033ready(self)
1034 SV * self
1035 CODE:
1036 api_ready (self);
1037
1038int
1039nready(...)
1040 PROTOTYPE:
1041 CODE:
1042 RETVAL = coro_nready;
1043 OUTPUT:
1044 RETVAL
1045
1046void
1047schedule(...)
1048 PROTOTYPE:
1049 ALIAS:
1050 cede = 1
1051 CODE:
1052 api_schedule (ix);
1053

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines