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.90 by root, Sat Nov 25 00:56:35 2006 UTC vs.
Revision 1.93 by root, Sun Nov 26 03:22:50 2006 UTC

27# ifndef IS_PADCONST 27# ifndef IS_PADCONST
28# define IS_PADCONST(v) 0 28# define IS_PADCONST(v) 0
29# endif 29# endif
30#endif 30#endif
31 31
32#include <stdio.h>
32#include <errno.h> 33#include <errno.h>
33 34
34#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 35#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
35# undef STACKGUARD 36# undef STACKGUARD
36#endif 37#endif
57# else 58# else
58# define BOOT_PAGESIZE 59# define BOOT_PAGESIZE
59# endif 60# endif
60#endif 61#endif
61 62
62#define SUB_INIT "Coro::State::initialize"
63
64/* The next macro should declare a variable stacklevel that contains and approximation 63/* The next macro should declare a variable stacklevel that contains and approximation
65 * to the current C stack pointer. Its property is that it changes with each call 64 * to the current C stack pointer. Its property is that it changes with each call
66 * and should be unique. */ 65 * and should be unique. */
66#define dSTACKLEVEL int stacklevel
67#define dSTACKLEVEL void *stacklevel = &stacklevel 67#define STACKLEVEL ((void *)&stacklevel)
68 68
69#define IN_DESTRUCT (PL_main_cv == Nullcv) 69#define IN_DESTRUCT (PL_main_cv == Nullcv)
70 70
71#define labs(l) ((l) >= 0 ? (l) : -(l)) 71#define labs(l) ((l) >= 0 ? (l) : -(l))
72 72
73#include "CoroAPI.h" 73#include "CoroAPI.h"
74
75#define TRANSFER_SET_STACKLEVEL 0x8bfbfbfb /* magic cookie */
74 76
75#ifdef USE_ITHREADS 77#ifdef USE_ITHREADS
76static perl_mutex coro_mutex; 78static perl_mutex coro_mutex;
77# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) 79# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0)
78# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) 80# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0)
84static struct CoroAPI coroapi; 86static struct CoroAPI coroapi;
85static AV *main_mainstack; /* used to differentiate between $main and others */ 87static AV *main_mainstack; /* used to differentiate between $main and others */
86static HV *coro_state_stash, *coro_stash; 88static HV *coro_state_stash, *coro_stash;
87static SV *coro_mortal; /* will be freed after next transfer */ 89static SV *coro_mortal; /* will be freed after next transfer */
88 90
89/* this is actually not just the c stack but also c registers etc... */ 91/* this is a structure representing a c-level coroutine */
90typedef struct coro_stack { 92typedef struct coro_stack {
91 struct coro_stack *next; 93 struct coro_stack *next;
92 94
93 void *idle_sp; 95 /* the stack */
94 void *sptr; 96 void *sptr;
95 long ssize; /* positive == mmap, otherwise malloc */ 97 long ssize; /* positive == mmap, otherwise malloc */
96 98
97 /* cpu state */ 99 /* cpu state */
100 void *idle_sp; /* original stacklevel when coroutine was created */
101 JMPENV *top_env;
98 coro_context cctx; 102 coro_context cctx;
99} coro_stack; 103} coro_stack;
100 104
105/* the (fake) coro_stack representing the main program */
101static coro_stack *main_stack; 106static coro_stack *main_stack;
102 107
108/* this is a structure representing a perl-level coroutine */
103struct coro { 109struct coro {
110 /* the c coroutine allocated to this perl coroutine, if any */
111 coro_stack *stack;
112
113 /* data associated with this coroutine (initial args) */
114 AV *args;
115 int refcnt;
116
104 /* optionally saved, might be zero */ 117 /* optionally saved, might be zero */
105 AV *defav; 118 AV *defav;
106 SV *defsv; 119 SV *defsv;
107 SV *errsv; 120 SV *errsv;
108 121
109 /* saved global state not related to stacks */ 122 /* saved global state not related to stacks */
110 U8 dowarn; 123 U8 dowarn;
111 I32 in_eval; 124 I32 in_eval;
112
113 /* the c stack, if any */
114 coro_stack *stack;
115 125
116 /* the stacks and related info (callchain etc..) */ 126 /* the stacks and related info (callchain etc..) */
117 PERL_SI *curstackinfo; 127 PERL_SI *curstackinfo;
118 AV *curstack; 128 AV *curstack;
119 AV *mainstack; 129 AV *mainstack;
140 OP **retstack; 150 OP **retstack;
141 I32 retstack_ix; 151 I32 retstack_ix;
142 I32 retstack_max; 152 I32 retstack_max;
143 PMOP *curpm; 153 PMOP *curpm;
144 COP *curcop; 154 COP *curcop;
145 JMPENV *top_env;
146 155
147 /* coro process data */ 156 /* coro process data */
148 int prio; 157 int prio;
149
150 /* data associated with this coroutine (initial args) */
151 AV *args;
152 int refcnt;
153}; 158};
154 159
155typedef struct coro *Coro__State; 160typedef struct coro *Coro__State;
156typedef struct coro *Coro__State_or_hashref; 161typedef struct coro *Coro__State_or_hashref;
157 162
300 PL_retstack_ix = c->retstack_ix; 305 PL_retstack_ix = c->retstack_ix;
301 PL_retstack_max = c->retstack_max; 306 PL_retstack_max = c->retstack_max;
302#endif 307#endif
303 PL_curpm = c->curpm; 308 PL_curpm = c->curpm;
304 PL_curcop = c->curcop; 309 PL_curcop = c->curcop;
305 PL_top_env = c->top_env;
306 310
307 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav); 311 if (c->defav) REPLACE_SV (GvAV (PL_defgv), c->defav);
308 if (c->defsv) REPLACE_SV (DEFSV , c->defsv); 312 if (c->defsv) REPLACE_SV (DEFSV , c->defsv);
309 if (c->errsv) REPLACE_SV (ERRSV , c->errsv); 313 if (c->errsv) REPLACE_SV (ERRSV , c->errsv);
310 314
428 c->retstack_ix = PL_retstack_ix; 432 c->retstack_ix = PL_retstack_ix;
429 c->retstack_max = PL_retstack_max; 433 c->retstack_max = PL_retstack_max;
430#endif 434#endif
431 c->curpm = PL_curpm; 435 c->curpm = PL_curpm;
432 c->curcop = PL_curcop; 436 c->curcop = PL_curcop;
433 c->top_env = PL_top_env;
434} 437}
435 438
436/* 439/*
437 * allocate various perl stacks. This is an exact copy 440 * allocate various perl stacks. This is an exact copy
438 * of perl.c:init_stacks, except that it uses less memory 441 * of perl.c:init_stacks, except that it uses less memory
540 * emulate part of the perl startup here. 543 * emulate part of the perl startup here.
541 */ 544 */
542 dTHX; 545 dTHX;
543 dSP; 546 dSP;
544 UNOP myop; 547 UNOP myop;
545 SV *sub_init = (SV *)get_cv (SUB_INIT, FALSE); 548 SV *sub_init = (SV *)get_cv ("Coro::State::coro_init", FALSE);
546 549
547 coro_init_stacks (aTHX); 550 coro_init_stacks (aTHX);
548 /*PL_curcop = 0;*/ 551 /*PL_curcop = 0;*/
549 /*PL_in_eval = PL_in_eval;*/ /* inherit */ 552 /*PL_in_eval = PL_in_eval;*/ /* inherit */
550 SvREFCNT_dec (GvAV (PL_defgv)); 553 SvREFCNT_dec (GvAV (PL_defgv));
566 569
567 ENTER; /* necessary e.g. for dounwind */ 570 ENTER; /* necessary e.g. for dounwind */
568} 571}
569 572
570static void 573static void
571transfer_tail () 574free_coro_mortal ()
572{ 575{
573 if (coro_mortal) 576 if (coro_mortal)
574 { 577 {
575 SvREFCNT_dec (coro_mortal); 578 SvREFCNT_dec (coro_mortal);
576 coro_mortal = 0; 579 coro_mortal = 0;
577 } 580 }
578
579 UNLOCK;
580} 581}
581 582
582static void 583static void
583coro_run (void *arg) 584coro_run (void *arg)
584{ 585{
585 /* 586 /*
586 * this is a _very_ stripped down perl interpreter ;) 587 * this is a _very_ stripped down perl interpreter ;)
587 */ 588 */
588 dTHX; 589 dTHX;
589 590
590 transfer_tail (); 591 UNLOCK;
591 592
592 PL_top_env = &PL_start_env; 593 PL_top_env = &PL_start_env;
593 PL_restartop = PL_op->op_next; 594
595 sv_setiv (get_sv ("Coro::State::cctx_stack", FALSE), PTR2IV ((coro_stack *)arg));
596 sv_setiv (get_sv ("Coro::State::cctx_restartop", FALSE), PTR2IV (PL_op));
597
598 /* continue at cctx_init, without entersub */
599 PL_restartop = CvSTART (get_cv ("Coro::State::cctx_init", FALSE));
600
594 /* somebody will hit me for both perl_run and PL_restart_top */ 601 /* somebody will hit me for both perl_run and PL_restart_op */
595 perl_run (aTHX_ PERL_GET_CONTEXT); 602 perl_run (aTHX_ PERL_GET_CONTEXT);
596 603
597 abort (); 604 abort ();
598} 605}
599 606
609 stack->ssize = ((STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + STACKGUARD) * PAGESIZE; /* mmap should do allocate-on-write for us */ 616 stack->ssize = ((STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + STACKGUARD) * PAGESIZE; /* mmap should do allocate-on-write for us */
610 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); 617 stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
611 618
612 if (stack->sptr == (void *)-1) 619 if (stack->sptr == (void *)-1)
613 { 620 {
614 fprintf (stderr, "FATAL: unable to mmap stack for coroutine\n"); 621 perror ("FATAL: unable to mmap stack for coroutine");
615 _exit (EXIT_FAILURE); 622 _exit (EXIT_FAILURE);
616 } 623 }
617 624
618 mprotect (stack->sptr, STACKGUARD * PAGESIZE, PROT_NONE); 625 mprotect (stack->sptr, STACKGUARD * PAGESIZE, PROT_NONE);
619 626
622 stack->ssize = STACKSIZE * (long)sizeof (long); 629 stack->ssize = STACKSIZE * (long)sizeof (long);
623 New (0, stack->sptr, STACKSIZE, long); 630 New (0, stack->sptr, STACKSIZE, long);
624 631
625 if (!stack->sptr) 632 if (!stack->sptr)
626 { 633 {
627 fprintf (stderr, "FATAL: unable to malloc stack for coroutine\n"); 634 perror (stderr, "FATAL: unable to malloc stack for coroutine");
628 _exit (EXIT_FAILURE); 635 _exit (EXIT_FAILURE);
629 } 636 }
630 637
631#endif 638#endif
632 639
633 coro_create (&stack->cctx, coro_run, 0, stack->sptr, stack->ssize); 640 coro_create (&stack->cctx, coro_run, (void *)stack, stack->sptr, stack->ssize);
634 641
635 return stack; 642 return stack;
636} 643}
637 644
638static void 645static void
650 Safefree (stack); 657 Safefree (stack);
651} 658}
652 659
653static coro_stack *stack_first; 660static coro_stack *stack_first;
654 661
655static void 662static coro_stack *
656stack_get (struct coro *coro) 663stack_get ()
657{ 664{
665 coro_stack *stack;
666
658 if (stack_first) 667 if (stack_first)
659 { 668 {
660 coro->stack = stack_first; 669 stack = stack_first;
661 stack_first = stack_first->next; 670 stack_first = stack->next;
662 } 671 }
663 else 672 else
673 {
664 coro->stack = stack_new (); 674 stack = stack_new ();
675 PL_op = PL_op->op_next;
676 }
677
678 return stack;
665} 679}
666 680
667static void 681static void
668stack_put (coro_stack *stack) 682stack_put (coro_stack *stack)
669{ 683{
676transfer_impl (pTHX_ struct coro *prev, struct coro *next, int flags) 690transfer_impl (pTHX_ struct coro *prev, struct coro *next, int flags)
677{ 691{
678 dSTACKLEVEL; 692 dSTACKLEVEL;
679 693
680 /* sometimes transfer is only called to set idle_sp */ 694 /* sometimes transfer is only called to set idle_sp */
681 if (!prev->stack->idle_sp) 695 if (flags == TRANSFER_SET_STACKLEVEL)
682 prev->stack->idle_sp = stacklevel; 696 ((coro_stack *)prev)->idle_sp = STACKLEVEL;
683
684 LOCK;
685
686 if (prev != next) 697 else if (prev != next)
687 { 698 {
688 coro_stack *prev_stack = prev->stack; 699 coro_stack *prev__stack;
689 700
690 /* possibly "free" the stack */ 701 LOCK;
691 if (prev_stack->idle_sp == stacklevel)
692 {
693 stack_put (prev_stack);
694 prev->stack = 0;
695 }
696 702
697 if (next->mainstack) 703 if (next->mainstack)
698 { 704 {
699 /* coroutine already started */ 705 /* coroutine already started */
700 SAVE (prev, flags); 706 SAVE (prev, flags);
705 /* need to start coroutine */ 711 /* need to start coroutine */
706 /* first get rid of the old state */ 712 /* first get rid of the old state */
707 SAVE (prev, -1); 713 SAVE (prev, -1);
708 /* setup coroutine call */ 714 /* setup coroutine call */
709 setup_coro (next); 715 setup_coro (next);
710 /* need to change stack from main_stack to real one */ 716 /* need a stack */
711 next->stack = 0; 717 next->stack = 0;
712 } 718 }
713 719
720 prev__stack = prev->stack;
721
722 /* possibly "free" the stack */
723 if (prev__stack->idle_sp == STACKLEVEL)
724 {
725 stack_put (prev__stack);
726 prev->stack = 0;
727 }
728
714 if (!next->stack) 729 if (!next->stack)
715 stack_get (next); 730 next->stack = stack_get ();
716 731
717 if (prev_stack != next->stack) 732 if (prev__stack != next->stack)
733 {
734 prev__stack->top_env = PL_top_env;
735 PL_top_env = next->stack->top_env;
718 coro_transfer (&prev_stack->cctx, &next->stack->cctx); 736 coro_transfer (&prev__stack->cctx, &next->stack->cctx);
737 }
738
739 free_coro_mortal ();
740
741 UNLOCK;
719 } 742 }
720
721 transfer_tail ();
722} 743}
723 744
724/* use this function pointer to call the above function */ 745/* use this function pointer to call the above function */
725/* this is done to increase chances of the compiler not inlining the call */ 746/* this is done to increase chances of the compiler not inlining the call */
747/* not static to make it even harder for the compiler (and theoretically impossible in most cases */
726void (*coro_state_transfer)(pTHX_ struct coro *prev, struct coro *next, int flags) = transfer_impl; 748void (*coro_state_transfer)(pTHX_ struct coro *prev, struct coro *next, int flags) = transfer_impl;
749
750struct transfer_args
751{
752 struct coro *prev, *next;
753 int flags;
754};
755
756#define TRANSFER(ta) coro_state_transfer ((ta).prev, (ta).next, (ta).flags)
727 757
728static void 758static void
729coro_state_destroy (struct coro *coro) 759coro_state_destroy (struct coro *coro)
730{ 760{
731 if (coro->refcnt--) 761 if (coro->refcnt--)
794 assert (mg->mg_type == PERL_MAGIC_ext); 824 assert (mg->mg_type == PERL_MAGIC_ext);
795 return (struct coro *)mg->mg_ptr; 825 return (struct coro *)mg->mg_ptr;
796} 826}
797 827
798static void 828static void
829prepare_transfer (pTHX_ struct transfer_args *ta, SV *prev, SV *next, int flags)
830{
831 ta->prev = SvSTATE (prev);
832 ta->next = SvSTATE (next);
833 ta->flags = flags;
834}
835
836static void
799api_transfer (pTHX_ SV *prev, SV *next, int flags) 837api_transfer (SV *prev, SV *next, int flags)
800{ 838{
801 coro_state_transfer (aTHX_ SvSTATE (prev), SvSTATE (next), flags); 839 dTHX;
840 struct transfer_args ta;
841
842 prepare_transfer (aTHX_ &ta, prev, next, flags);
843 TRANSFER (ta);
802} 844}
803 845
804/** Coro ********************************************************************/ 846/** Coro ********************************************************************/
805 847
806#define PRIO_MAX 3 848#define PRIO_MAX 3
860 coro_enq (aTHX_ SvREFCNT_inc (coro)); 902 coro_enq (aTHX_ SvREFCNT_inc (coro));
861 UNLOCK; 903 UNLOCK;
862} 904}
863 905
864static void 906static void
865api_schedule (void) 907prepare_schedule (aTHX_ struct transfer_args *ta)
866{ 908{
867 dTHX;
868
869 SV *prev, *next; 909 SV *current, *prev, *next;
910
911 LOCK;
912
870 SV *current = GvSV (coro_current); 913 current = GvSV (coro_current);
871 914
872 for (;;) 915 for (;;)
873 { 916 {
874 LOCK; 917 LOCK;
875 918
897 940
898 prev = SvRV (current); 941 prev = SvRV (current);
899 SvRV (current) = next; 942 SvRV (current) = next;
900 943
901 /* free this only after the transfer */ 944 /* free this only after the transfer */
945 free_coro_mortal ();
902 coro_mortal = prev; 946 coro_mortal = prev;
903 947
948 ta->prev = SvSTATE (prev);
949 ta->next = SvSTATE (next);
950 ta->flags = TRANSFER_SAVE_ALL;
951
904 UNLOCK; 952 UNLOCK;
905
906 coro_state_transfer (aTHX_ SvSTATE (prev), SvSTATE (next), TRANSFER_SAVE_ALL);
907} 953}
908 954
909static int coro_cede_self; 955static void
956prepare_cede (aTHX_ struct transfer_args *ta)
957{
958 LOCK;
959 coro_enq (aTHX_ SvREFCNT_inc (SvRV (GvSV (coro_current))));
960 UNLOCK;
961
962 prepare_schedule (ta);
963}
964
965static void
966api_schedule (void)
967{
968 dTHX;
969 struct transfer_args ta;
970
971 prepare_schedule (&ta);
972 TRANSFER (ta);
973}
910 974
911static void 975static void
912api_cede (void) 976api_cede (void)
913{ 977{
914 dTHX; 978 dTHX;
915 SV *current = SvREFCNT_inc (SvRV (GvSV (coro_current))); 979 struct transfer_args ta;
916 980
917 LOCK; 981 prepare_cede (&ta);
918 982 TRANSFER (ta);
919 if (coro_cede_self)
920 {
921 AV *runqueue = coro_ready [PRIO_MAX - PRIO_MIN];
922 av_unshift (runqueue, 1);
923 av_store (runqueue, 0, current);
924 coro_nready++;
925 coro_cede_self = 0;
926 }
927 else
928 coro_enq (aTHX_ current);
929
930 UNLOCK;
931
932 api_schedule ();
933} 983}
934 984
935MODULE = Coro::State PACKAGE = Coro::State 985MODULE = Coro::State PACKAGE = Coro::State
936 986
937PROTOTYPES: DISABLE 987PROTOTYPES: DISABLE
973 1023
974 hv = newHV (); 1024 hv = newHV ();
975 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP; 1025 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP;
976 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 1026 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
977 1027
978 av_push (coro->args, newSVsv (RETVAL));
979 for (i = 1; i < items; i++) 1028 for (i = 1; i < items; i++)
980 av_push (coro->args, newSVsv (ST (i))); 1029 av_push (coro->args, newSVsv (ST (i)));
981 1030
982 coro->stack = main_stack; 1031 coro->stack = main_stack;
983 /*coro->mainstack = 0; *//*actual work is done inside transfer */ 1032 /*coro->mainstack = 0; *//*actual work is done inside transfer */
985} 1034}
986 OUTPUT: 1035 OUTPUT:
987 RETVAL 1036 RETVAL
988 1037
989void 1038void
990transfer (prev, next, flags) 1039transfer (...)
991 SV *prev 1040 ALIAS:
992 SV *next 1041 Coro::schedule = 1
993 int flags 1042 Coro::cede = 2
1043 _set_stacklevel = 3
994 CODE: 1044 CODE:
995 PUTBACK;
996 coro_state_transfer (aTHX_ SvSTATE (prev), SvSTATE (next), flags);
997 SPAGAIN;
998
999int
1000prio (Coro::State coro, int newprio = 0)
1001 ALIAS:
1002 nice = 1
1003 CODE:
1004{ 1045{
1005 RETVAL = coro->prio; 1046 struct transfer_args ta;
1006 1047
1007 if (items > 1) 1048 switch (ix)
1008 { 1049 {
1050 case 0:
1009 if (ix) 1051 if (items != 3)
1010 newprio += coro->prio; 1052 croak ("Coro::State::transfer(prev,next,flags) expects three arguments, not %d", items);
1011 1053
1012 if (newprio < PRIO_MIN) newprio = PRIO_MIN; 1054 prepare_transfer (&ta, ST (0), ST (1), SvIV (ST (2)));
1013 if (newprio > PRIO_MAX) newprio = PRIO_MAX; 1055 break;
1014 1056
1015 coro->prio = newprio; 1057 case 1:
1058 prepare_schedule (&ta);
1059 break;
1060
1061 case 2:
1062 prepare_cede (&ta);
1063 break;
1064
1065 case 3:
1066 ta.prev = (struct coro *)INT2PTR (coro_stack *, SvIV (ST (0)));
1067 ta.next = 0;
1068 ta.flags = TRANSFER_SET_STACKLEVEL;
1069 break;
1016 } 1070 }
1017}
1018 1071
1019void 1072 TRANSFER (ta);
1020_clear_idle_sp (Coro::State self) 1073}
1021 CODE:
1022 self->stack->idle_sp = 0;
1023 1074
1024void 1075void
1025_clone_state_from (SV *dst, SV *src) 1076_clone_state_from (SV *dst, SV *src)
1026 CODE: 1077 CODE:
1027{ 1078{
1030 sv_unmagic (SvRV (dst), PERL_MAGIC_ext); 1081 sv_unmagic (SvRV (dst), PERL_MAGIC_ext);
1031 1082
1032 ++coro_src->refcnt; 1083 ++coro_src->refcnt;
1033 sv_magicext (SvRV (dst), 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro_src, 0)->mg_flags |= MGf_DUP; 1084 sv_magicext (SvRV (dst), 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro_src, 0)->mg_flags |= MGf_DUP;
1034} 1085}
1086
1087void
1088_nonlocal_goto (IV nextop)
1089 CODE:
1090 /* uuh, somebody will kill me again for this */
1091 PL_op->op_next = INT2PTR (OP *, nextop);
1035 1092
1036void 1093void
1037_exit (code) 1094_exit (code)
1038 int code 1095 int code
1039 PROTOTYPE: $ 1096 PROTOTYPE: $
1104 1161
1105 GCoroAPI = &coroapi; 1162 GCoroAPI = &coroapi;
1106 sv_setiv (sv, (IV)&coroapi); 1163 sv_setiv (sv, (IV)&coroapi);
1107 SvREADONLY_on (sv); 1164 SvREADONLY_on (sv);
1108 } 1165 }
1166}
1167
1168int
1169prio (Coro::State coro, int newprio = 0)
1170 ALIAS:
1171 nice = 1
1172 CODE:
1173{
1174 RETVAL = coro->prio;
1175
1176 if (items > 1)
1177 {
1178 if (ix)
1179 newprio += coro->prio;
1180
1181 if (newprio < PRIO_MIN) newprio = PRIO_MIN;
1182 if (newprio > PRIO_MAX) newprio = PRIO_MAX;
1183
1184 coro->prio = newprio;
1185 }
1109} 1186}
1110 1187
1111void 1188void
1112ready (SV *self) 1189ready (SV *self)
1113 PROTOTYPE: $ 1190 PROTOTYPE: $
1120 CODE: 1197 CODE:
1121 RETVAL = coro_nready; 1198 RETVAL = coro_nready;
1122 OUTPUT: 1199 OUTPUT:
1123 RETVAL 1200 RETVAL
1124 1201
1125void
1126schedule (...)
1127 PROTOTYPE:
1128 CODE:
1129 api_schedule ();
1130
1131void
1132_set_cede_self ()
1133 CODE:
1134 coro_cede_self = 1;
1135
1136void
1137cede (...)
1138 PROTOTYPE:
1139 CODE:
1140 api_cede ();
1141
1142MODULE = Coro::State PACKAGE = Coro::AIO 1202MODULE = Coro::State PACKAGE = Coro::AIO
1143 1203
1144SV * 1204SV *
1145_get_state () 1205_get_state ()
1146 CODE: 1206 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines