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.126 by root, Tue Dec 12 04:19:56 2006 UTC vs.
Revision 1.134 by root, Thu Jan 4 23:49:27 2007 UTC

4#include "perl.h" 4#include "perl.h"
5#include "XSUB.h" 5#include "XSUB.h"
6 6
7#include "patchlevel.h" 7#include "patchlevel.h"
8 8
9#if USE_VALGRIND
10# include <valgrind/valgrind.h>
11#endif
12
13/* the maximum number of idle cctx that will be pooled */
14#define MAX_IDLE_CCTX 8
15
16#define PERL_VERSION_ATLEAST(a,b,c) \
17 (PERL_REVISION > (a) \
18 || (PERL_REVISION == (a) \
19 && (PERL_VERSION > (b) \
20 || (PERL_VERSION == (b) && PERLSUBVERSION >= (c)))))
21
22#if !PERL_VERSION_ATLEAST (5,6,0)
23# ifndef PL_ppaddr
24# define PL_ppaddr ppaddr
25# endif
26# ifndef call_sv
27# define call_sv perl_call_sv
28# endif
29# ifndef get_sv
30# define get_sv perl_get_sv
31# endif
32# ifndef get_cv
33# define get_cv perl_get_cv
34# endif
35# ifndef IS_PADGV
36# define IS_PADGV(v) 0
37# endif
38# ifndef IS_PADCONST
39# define IS_PADCONST(v) 0
40# endif
41#endif
42
43/* 5.8.7 */
44#ifndef SvRV_set
45# define SvRV_set(s,v) SvRV(s) = (v)
46#endif
47
48#include <stdio.h> 9#include <stdio.h>
49#include <errno.h> 10#include <errno.h>
50#include <assert.h> 11#include <assert.h>
51
52#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
53# undef STACKGUARD
54#endif
55
56#ifndef STACKGUARD
57# define STACKGUARD 0
58#endif
59 12
60#ifdef HAVE_MMAP 13#ifdef HAVE_MMAP
61# include <unistd.h> 14# include <unistd.h>
62# include <sys/mman.h> 15# include <sys/mman.h>
63# ifndef MAP_ANONYMOUS 16# ifndef MAP_ANONYMOUS
78#else 31#else
79# define PAGESIZE 0 32# define PAGESIZE 0
80# define BOOT_PAGESIZE (void)0 33# define BOOT_PAGESIZE (void)0
81#endif 34#endif
82 35
36#if USE_VALGRIND
37# include <valgrind/valgrind.h>
38#endif
39
40/* the maximum number of idle cctx that will be pooled */
41#define MAX_IDLE_CCTX 8
42
43#define PERL_VERSION_ATLEAST(a,b,c) \
44 (PERL_REVISION > (a) \
45 || (PERL_REVISION == (a) \
46 && (PERL_VERSION > (b) \
47 || (PERL_VERSION == (b) && PERLSUBVERSION >= (c)))))
48
49#if !PERL_VERSION_ATLEAST (5,6,0)
50# ifndef PL_ppaddr
51# define PL_ppaddr ppaddr
52# endif
53# ifndef call_sv
54# define call_sv perl_call_sv
55# endif
56# ifndef get_sv
57# define get_sv perl_get_sv
58# endif
59# ifndef get_cv
60# define get_cv perl_get_cv
61# endif
62# ifndef IS_PADGV
63# define IS_PADGV(v) 0
64# endif
65# ifndef IS_PADCONST
66# define IS_PADCONST(v) 0
67# endif
68#endif
69
70/* 5.8.7 */
71#ifndef SvRV_set
72# define SvRV_set(s,v) SvRV(s) = (v)
73#endif
74
75#if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64
76# undef STACKGUARD
77#endif
78
79#ifndef STACKGUARD
80# define STACKGUARD 0
81#endif
82
83/* prefer perl internal functions over our own? */
84#ifndef PREFER_PERL_FUNCTIONS
85# define PREFER_PERL_FUNCTIONS 0
86#endif
87
83/* The next macro should declare a variable stacklevel that contains and approximation 88/* The next macro should declare a variable stacklevel that contains and approximation
84 * to the current C stack pointer. Its property is that it changes with each call 89 * to the current C stack pointer. Its property is that it changes with each call
85 * and should be unique. */ 90 * and should be unique. */
86#define dSTACKLEVEL int stacklevel 91#define dSTACKLEVEL int stacklevel
87#define STACKLEVEL ((void *)&stacklevel) 92#define STACKLEVEL ((void *)&stacklevel)
88 93
89#define IN_DESTRUCT (PL_main_cv == Nullcv) 94#define IN_DESTRUCT (PL_main_cv == Nullcv)
90 95
91#if __GNUC__ >= 3 96#if __GNUC__ >= 3
92# define attribute(x) __attribute__(x) 97# define attribute(x) __attribute__(x)
98# define BARRIER __asm__ __volatile__ ("" : : : "memory")
93#else 99#else
94# define attribute(x) 100# define attribute(x)
101# define BARRIER
95#endif 102#endif
96 103
97#define NOINLINE attribute ((noinline)) 104#define NOINLINE attribute ((noinline))
98 105
99#include "CoroAPI.h" 106#include "CoroAPI.h"
130 /* the stack */ 137 /* the stack */
131 void *sptr; 138 void *sptr;
132 long ssize; /* positive == mmap, otherwise malloc */ 139 long ssize; /* positive == mmap, otherwise malloc */
133 140
134 /* cpu state */ 141 /* cpu state */
135 void *idle_sp; /* sp of top-level transfer/schedule/cede call */ 142 void *idle_sp; /* sp of top-level transfer/schedule/cede call */
143 JMPENV *idle_te; /* same as idle_sp, but for top_env, TODO: remove once stable */
136 JMPENV *top_env; 144 JMPENV *top_env;
137 coro_context cctx; 145 coro_context cctx;
138 146
139 int inuse; 147 int inuse;
140 148
142 int valgrind_id; 150 int valgrind_id;
143#endif 151#endif
144} coro_cctx; 152} coro_cctx;
145 153
146enum { 154enum {
147 CF_RUNNING = 0x0001, /* coroutine is running */ 155 CF_RUNNING = 0x0001, /* coroutine is running */
148 CF_READY = 0x0002, /* coroutine is ready */ 156 CF_READY = 0x0002, /* coroutine is ready */
149 CF_NEW = 0x0004, /* ahs never been switched to */ 157 CF_NEW = 0x0004, /* has never been switched to */
158 CF_DESTROYED = 0x0008, /* coroutine data has been freed */
150}; 159};
151 160
152/* this is a structure representing a perl-level coroutine */ 161/* this is a structure representing a perl-level coroutine */
153struct coro { 162struct coro {
154 /* the c coroutine allocated to this perl coroutine, if any */ 163 /* the c coroutine allocated to this perl coroutine, if any */
259 268
260 if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0) 269 if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0)
261 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; 270 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--];
262 else 271 else
263 { 272 {
264#if 0 273#if PREFER_PERL_FUNCTIONS
265 /* this is probably cleaner, but also slower? */ 274 /* this is probably cleaner, but also slower? */
266 CV *cp = Perl_cv_clone (cv); 275 CV *cp = Perl_cv_clone (cv);
267 CvPADLIST (cv) = CvPADLIST (cp); 276 CvPADLIST (cv) = CvPADLIST (cp);
268 CvPADLIST (cp) = 0; 277 CvPADLIST (cp) = 0;
269 SvREFCNT_dec (cp); 278 SvREFCNT_dec (cp);
403 * allocate various perl stacks. This is an exact copy 412 * allocate various perl stacks. This is an exact copy
404 * of perl.c:init_stacks, except that it uses less memory 413 * of perl.c:init_stacks, except that it uses less memory
405 * on the (sometimes correct) assumption that coroutines do 414 * on the (sometimes correct) assumption that coroutines do
406 * not usually need a lot of stackspace. 415 * not usually need a lot of stackspace.
407 */ 416 */
408#if USE_PERL_INIT_STACKS 417#if PREFER_PERL_FUNCTIONS
409# define coro_init_stacks init_stacks 418# define coro_init_stacks init_stacks
410#else 419#else
411
412static void 420static void
413coro_init_stacks () 421coro_init_stacks ()
414{ 422{
415 PL_curstackinfo = new_stackinfo(128, 1024/sizeof(PERL_CONTEXT)); 423 PL_curstackinfo = new_stackinfo(128, 1024/sizeof(PERL_CONTEXT));
416 PL_curstackinfo->si_type = PERLSI_MAIN; 424 PL_curstackinfo->si_type = PERLSI_MAIN;
446 New(54,PL_retstack,16,OP*); 454 New(54,PL_retstack,16,OP*);
447 PL_retstack_ix = 0; 455 PL_retstack_ix = 0;
448 PL_retstack_max = 16; 456 PL_retstack_max = 16;
449#endif 457#endif
450} 458}
459#endif
451 460
452/* 461/*
453 * destroy the stacks, the callchain etc... 462 * destroy the stacks, the callchain etc...
454 */ 463 */
455static void 464static void
463 472
464 /* free all temporaries */ 473 /* free all temporaries */
465 FREETMPS; 474 FREETMPS;
466 assert (PL_tmps_ix == -1); 475 assert (PL_tmps_ix == -1);
467 476
477 /* unwind all extra stacks */
468 POPSTACK_TO (PL_mainstack); 478 POPSTACK_TO (PL_mainstack);
479
480 /* unwind main stack */
481 dounwind (-1);
469 } 482 }
470 483
471 while (PL_curstackinfo->si_next) 484 while (PL_curstackinfo->si_next)
472 PL_curstackinfo = PL_curstackinfo->si_next; 485 PL_curstackinfo = PL_curstackinfo->si_next;
473 486
489 Safefree (PL_savestack); 502 Safefree (PL_savestack);
490#if !PERL_VERSION_ATLEAST (5,9,0) 503#if !PERL_VERSION_ATLEAST (5,9,0)
491 Safefree (PL_retstack); 504 Safefree (PL_retstack);
492#endif 505#endif
493} 506}
494#endif
495 507
496static void 508static void
497setup_coro (struct coro *coro) 509setup_coro (struct coro *coro)
498{ 510{
499 /* 511 /*
702 714
703 /* sometimes transfer is only called to set idle_sp */ 715 /* sometimes transfer is only called to set idle_sp */
704 if (!next) 716 if (!next)
705 { 717 {
706 ((coro_cctx *)prev)->idle_sp = STACKLEVEL; 718 ((coro_cctx *)prev)->idle_sp = STACKLEVEL;
707 assert (((coro_cctx *)prev)->top_env = PL_top_env); /* just for the side effetc when assert is enabled */ 719 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */
708 } 720 }
709 else if (prev != next) 721 else if (prev != next)
710 { 722 {
711 coro_cctx *prev__cctx; 723 coro_cctx *prev__cctx;
712 724
723 if (!prev->flags & CF_RUNNING) 735 if (!prev->flags & CF_RUNNING)
724 croak ("Coro::State::transfer called with non-running prev Coro::State, but can only transfer from running states"); 736 croak ("Coro::State::transfer called with non-running prev Coro::State, but can only transfer from running states");
725 737
726 if (next->flags & CF_RUNNING) 738 if (next->flags & CF_RUNNING)
727 croak ("Coro::State::transfer called with running next Coro::State, but can only transfer to inactive states"); 739 croak ("Coro::State::transfer called with running next Coro::State, but can only transfer to inactive states");
740
741 if (next->flags & CF_DESTROYED)
742 croak ("Coro::State::transfer called with destroyed next Coro::State, but can only transfer to inactive states");
728 743
729 prev->flags &= ~CF_RUNNING; 744 prev->flags &= ~CF_RUNNING;
730 next->flags |= CF_RUNNING; 745 next->flags |= CF_RUNNING;
731 746
732 LOCK; 747 LOCK;
753 768
754 /* possibly "free" the cctx */ 769 /* possibly "free" the cctx */
755 if (prev__cctx->idle_sp == STACKLEVEL) 770 if (prev__cctx->idle_sp == STACKLEVEL)
756 { 771 {
757 /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */ 772 /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */
758 assert (PL_top_env == prev__cctx->top_env); 773 assert (("ERROR: current top_env must equal previous top_env", PL_top_env == prev__cctx->idle_te));
759 774
760 prev->cctx = 0; 775 prev->cctx = 0;
761 776
762 cctx_put (prev__cctx); 777 cctx_put (prev__cctx);
763 prev__cctx->inuse = 0; 778 prev__cctx->inuse = 0;
776 PL_top_env = next->cctx->top_env; 791 PL_top_env = next->cctx->top_env;
777 coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); 792 coro_transfer (&prev__cctx->cctx, &next->cctx->cctx);
778 } 793 }
779 794
780 free_coro_mortal (); 795 free_coro_mortal ();
781
782 UNLOCK; 796 UNLOCK;
783 } 797 }
784} 798}
785 799
786struct transfer_args 800struct transfer_args
788 struct coro *prev, *next; 802 struct coro *prev, *next;
789}; 803};
790 804
791#define TRANSFER(ta) transfer ((ta).prev, (ta).next) 805#define TRANSFER(ta) transfer ((ta).prev, (ta).next)
792 806
793static void 807static int
794coro_state_destroy (struct coro *coro) 808coro_state_destroy (struct coro *coro)
795{ 809{
796 if (coro->refcnt--) 810 if (coro->flags & CF_DESTROYED)
797 return; 811 return 0;
812
813 coro->flags |= CF_DESTROYED;
798 814
799 if (coro->mainstack && coro->mainstack != main_mainstack) 815 if (coro->mainstack && coro->mainstack != main_mainstack)
800 { 816 {
817 assert (!(coro->flags & CF_RUNNING));
818
801 struct coro temp; 819 struct coro temp;
802 Zero (&temp, 1, struct coro); 820 Zero (&temp, 1, struct coro);
803 temp.save = CORO_SAVE_ALL; 821 temp.save = CORO_SAVE_ALL;
804 822
805 if (coro->flags & CF_RUNNING) 823 if (coro->flags & CF_RUNNING)
815 coro->mainstack = 0; 833 coro->mainstack = 0;
816 } 834 }
817 835
818 cctx_destroy (coro->cctx); 836 cctx_destroy (coro->cctx);
819 SvREFCNT_dec (coro->args); 837 SvREFCNT_dec (coro->args);
820 Safefree (coro); 838
839 return 1;
821} 840}
822 841
823static int 842static int
824coro_state_clear (pTHX_ SV *sv, MAGIC *mg) 843coro_state_free (pTHX_ SV *sv, MAGIC *mg)
825{ 844{
826 struct coro *coro = (struct coro *)mg->mg_ptr; 845 struct coro *coro = (struct coro *)mg->mg_ptr;
827 mg->mg_ptr = 0; 846 mg->mg_ptr = 0;
828 847
848 if (--coro->refcnt < 0)
849 {
829 coro_state_destroy (coro); 850 coro_state_destroy (coro);
851 Safefree (coro);
852 }
830 853
831 return 0; 854 return 0;
832} 855}
833 856
834static int 857static int
841 return 0; 864 return 0;
842} 865}
843 866
844static MGVTBL coro_state_vtbl = { 867static MGVTBL coro_state_vtbl = {
845 0, 0, 0, 0, 868 0, 0, 0, 0,
846 coro_state_clear, 869 coro_state_free,
847 0, 870 0,
848#ifdef MGf_DUP 871#ifdef MGf_DUP
849 coro_state_dup, 872 coro_state_dup,
850#else 873#else
851# define MGf_DUP 0 874# define MGf_DUP 0
953 coro = SvSTATE (coro_sv); 976 coro = SvSTATE (coro_sv);
954 977
955 if (coro->flags & CF_READY) 978 if (coro->flags & CF_READY)
956 return 0; 979 return 0;
957 980
958#if 0 /* this is actually harmless */
959 if (coro->flags & CF_RUNNING)
960 croak ("Coro::ready called on currently running coroutine");
961#endif
962
963 coro->flags |= CF_READY; 981 coro->flags |= CF_READY;
964 982
965 LOCK; 983 LOCK;
966 coro_enq (SvREFCNT_inc (coro_sv)); 984 coro_enq (SvREFCNT_inc (coro_sv));
967 UNLOCK; 985 UNLOCK;
970} 988}
971 989
972static int 990static int
973api_is_ready (SV *coro_sv) 991api_is_ready (SV *coro_sv)
974{ 992{
975 return !!SvSTATE (coro_sv)->flags & CF_READY; 993 return !!(SvSTATE (coro_sv)->flags & CF_READY);
976} 994}
977 995
978static void 996static void
979prepare_schedule (struct transfer_args *ta) 997prepare_schedule (struct transfer_args *ta)
980{ 998{
981 SV *prev, *next; 999 SV *prev_sv, *next_sv;
982 1000
983 for (;;) 1001 for (;;)
984 { 1002 {
985 LOCK; 1003 LOCK;
986 next = coro_deq (PRIO_MIN); 1004 next_sv = coro_deq (PRIO_MIN);
987 UNLOCK; 1005 UNLOCK;
988 1006
1007 /* nothing to schedule: call the idle handler */
989 if (next) 1008 if (!next_sv)
990 break;
991
992 { 1009 {
993 dSP; 1010 dSP;
994 1011
995 ENTER; 1012 ENTER;
996 SAVETMPS; 1013 SAVETMPS;
997 1014
998 PUSHMARK (SP); 1015 PUSHMARK (SP);
999 PUTBACK; 1016 PUTBACK;
1000 call_sv (get_sv ("Coro::idle", FALSE), G_DISCARD); 1017 call_sv (get_sv ("Coro::idle", FALSE), G_DISCARD);
1001 1018
1002 FREETMPS; 1019 FREETMPS;
1003 LEAVE; 1020 LEAVE;
1021 continue;
1004 } 1022 }
1005 }
1006 1023
1007 prev = SvRV (coro_current); 1024 ta->next = SvSTATE (next_sv);
1008 SvRV_set (coro_current, next); 1025
1026 /* cannot transfer to destroyed coros, skip and look for next */
1027 if (ta->next->flags & CF_DESTROYED)
1028 {
1029 SvREFCNT_dec (next_sv);
1030 continue;
1031 }
1032
1033 break;
1034 }
1009 1035
1010 /* free this only after the transfer */ 1036 /* free this only after the transfer */
1037 prev_sv = SvRV (coro_current);
1038 SvRV_set (coro_current, next_sv);
1039 ta->prev = SvSTATE (prev_sv);
1040
1041 assert (ta->next->flags & CF_READY);
1042 ta->next->flags &= ~CF_READY;
1043
1011 LOCK; 1044 LOCK;
1012 free_coro_mortal (); 1045 free_coro_mortal ();
1046 coro_mortal = prev_sv;
1013 UNLOCK; 1047 UNLOCK;
1014 coro_mortal = prev;
1015
1016 assert (!SvROK(prev));//D
1017 assert (!SvROK(next));//D
1018
1019 ta->prev = SvSTATE (prev);
1020 ta->next = SvSTATE (next);
1021
1022 assert (ta->next->flags & CF_READY);
1023 ta->next->flags &= ~CF_READY;
1024} 1048}
1025 1049
1026static void 1050static void
1027prepare_cede (struct transfer_args *ta) 1051prepare_cede (struct transfer_args *ta)
1028{ 1052{
1029 api_ready (coro_current); 1053 api_ready (coro_current);
1030
1031 prepare_schedule (ta); 1054 prepare_schedule (ta);
1055}
1056
1057static int
1058prepare_cede_notself (struct transfer_args *ta)
1059{
1060 if (coro_nready)
1061 {
1062 SV *prev = SvRV (coro_current);
1063 prepare_schedule (ta);
1064 api_ready (prev);
1065 return 1;
1066 }
1067 else
1068 return 0;
1032} 1069}
1033 1070
1034static void 1071static void
1035api_schedule (void) 1072api_schedule (void)
1036{ 1073{
1038 1075
1039 prepare_schedule (&ta); 1076 prepare_schedule (&ta);
1040 TRANSFER (ta); 1077 TRANSFER (ta);
1041} 1078}
1042 1079
1043static void 1080static int
1044api_cede (void) 1081api_cede (void)
1045{ 1082{
1046 struct transfer_args ta; 1083 struct transfer_args ta;
1047 1084
1048 prepare_cede (&ta); 1085 prepare_cede (&ta);
1086
1087 if (ta.prev != ta.next)
1088 {
1049 TRANSFER (ta); 1089 TRANSFER (ta);
1090 return 1;
1091 }
1092 else
1093 return 0;
1094}
1095
1096static int
1097api_cede_notself (void)
1098{
1099 struct transfer_args ta;
1100
1101 if (prepare_cede_notself (&ta))
1102 {
1103 TRANSFER (ta);
1104 return 1;
1105 }
1106 else
1107 return 0;
1050} 1108}
1051 1109
1052MODULE = Coro::State PACKAGE = Coro::State 1110MODULE = Coro::State PACKAGE = Coro::State
1053 1111
1054PROTOTYPES: DISABLE 1112PROTOTYPES: DISABLE
1110_set_stacklevel (...) 1168_set_stacklevel (...)
1111 ALIAS: 1169 ALIAS:
1112 Coro::State::transfer = 1 1170 Coro::State::transfer = 1
1113 Coro::schedule = 2 1171 Coro::schedule = 2
1114 Coro::cede = 3 1172 Coro::cede = 3
1173 Coro::cede_notself = 4
1115 CODE: 1174 CODE:
1116{ 1175{
1117 struct transfer_args ta; 1176 struct transfer_args ta;
1118 1177
1119 switch (ix) 1178 switch (ix)
1135 break; 1194 break;
1136 1195
1137 case 3: 1196 case 3:
1138 prepare_cede (&ta); 1197 prepare_cede (&ta);
1139 break; 1198 break;
1199
1200 case 4:
1201 if (!prepare_cede_notself (&ta))
1202 XSRETURN_EMPTY;
1203
1204 break;
1140 } 1205 }
1141 1206
1207 BARRIER;
1142 TRANSFER (ta); 1208 TRANSFER (ta);
1143} 1209}
1144 1210
1145void 1211bool
1146_clone_state_from (SV *dst, SV *src) 1212_destroy (SV *coro_sv)
1147 CODE: 1213 CODE:
1148{ 1214 RETVAL = coro_state_destroy (SvSTATE (coro_sv));
1149 struct coro *coro_src = SvSTATE (src); 1215 OUTPUT:
1150 1216 RETVAL
1151 sv_unmagic (SvRV (dst), PERL_MAGIC_ext);
1152
1153 ++coro_src->refcnt;
1154 sv_magicext (SvRV (dst), 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro_src, 0)->mg_flags |= MGf_DUP;
1155}
1156 1217
1157void 1218void
1158_exit (code) 1219_exit (code)
1159 int code 1220 int code
1160 PROTOTYPE: $ 1221 PROTOTYPE: $
1197 coro_ready[i] = newAV (); 1258 coro_ready[i] = newAV ();
1198 1259
1199 { 1260 {
1200 SV *sv = perl_get_sv("Coro::API", 1); 1261 SV *sv = perl_get_sv("Coro::API", 1);
1201 1262
1202 coroapi.schedule = api_schedule; 1263 coroapi.schedule = api_schedule;
1203 coroapi.save = api_save; 1264 coroapi.save = api_save;
1204 coroapi.cede = api_cede; 1265 coroapi.cede = api_cede;
1266 coroapi.cede_notself = api_cede_notself;
1205 coroapi.ready = api_ready; 1267 coroapi.ready = api_ready;
1206 coroapi.is_ready = api_is_ready; 1268 coroapi.is_ready = api_is_ready;
1207 coroapi.nready = &coro_nready; 1269 coroapi.nready = &coro_nready;
1208 coroapi.current = coro_current; 1270 coroapi.current = coro_current;
1209 1271
1210 GCoroAPI = &coroapi; 1272 GCoroAPI = &coroapi;
1211 sv_setiv (sv, (IV)&coroapi); 1273 sv_setiv (sv, (IV)&coroapi);
1212 SvREADONLY_on (sv); 1274 SvREADONLY_on (sv);
1213 } 1275 }
1229 RETVAL = coro->prio; 1291 RETVAL = coro->prio;
1230 1292
1231 if (items > 1) 1293 if (items > 1)
1232 { 1294 {
1233 if (ix) 1295 if (ix)
1234 newprio += coro->prio; 1296 newprio = coro->prio - newprio;
1235 1297
1236 if (newprio < PRIO_MIN) newprio = PRIO_MIN; 1298 if (newprio < PRIO_MIN) newprio = PRIO_MIN;
1237 if (newprio > PRIO_MAX) newprio = PRIO_MAX; 1299 if (newprio > PRIO_MAX) newprio = PRIO_MAX;
1238 1300
1239 coro->prio = newprio; 1301 coro->prio = newprio;
1240 } 1302 }
1241} 1303}
1304 OUTPUT:
1305 RETVAL
1242 1306
1243SV * 1307SV *
1244ready (SV *self) 1308ready (SV *self)
1245 PROTOTYPE: $ 1309 PROTOTYPE: $
1246 CODE: 1310 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines