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.111 by root, Thu Nov 30 18:21:14 2006 UTC vs.
Revision 1.117 by root, Fri Dec 1 19:41:06 2006 UTC

7#include "patchlevel.h" 7#include "patchlevel.h"
8 8
9#if USE_VALGRIND 9#if USE_VALGRIND
10# include <valgrind/valgrind.h> 10# include <valgrind/valgrind.h>
11#endif 11#endif
12
13/* the maximum number of idle cctx that will be pooled */
14#define MAX_IDLE_CCTX 8
12 15
13#define PERL_VERSION_ATLEAST(a,b,c) \ 16#define PERL_VERSION_ATLEAST(a,b,c) \
14 (PERL_REVISION > (a) \ 17 (PERL_REVISION > (a) \
15 || (PERL_REVISION == (a) \ 18 || (PERL_REVISION == (a) \
16 && (PERL_VERSION > (b) \ 19 && (PERL_VERSION > (b) \
127 int valgrind_id; 130 int valgrind_id;
128#endif 131#endif
129} coro_cctx; 132} coro_cctx;
130 133
131enum { 134enum {
132 CF_RUNNING, /* coroutine is running */ 135 CF_RUNNING = 0x0001, /* coroutine is running */
133 CF_READY, /* coroutine is ready */ 136 CF_READY = 0x0002, /* coroutine is ready */
137 CF_NEW = 0x0004, /* ahs never been switched to */
134}; 138};
135 139
136/* this is a structure representing a perl-level coroutine */ 140/* this is a structure representing a perl-level coroutine */
137struct coro { 141struct coro {
138 /* the c coroutine allocated to this perl coroutine, if any */ 142 /* the c coroutine allocated to this perl coroutine, if any */
277} 281}
278 282
279#define SB do { 283#define SB do {
280#define SE } while (0) 284#define SE } while (0)
281 285
282#define LOAD(state) load_state((state)); 286#define LOAD(state) load_state ((state))
283#define SAVE(state,flags) save_state((state),(flags)); 287#define SAVE(state,flags) save_state ((state),(flags))
284 288
285#define REPLACE_SV(sv,val) SB SvREFCNT_dec(sv); (sv) = (val); (val) = 0; SE 289#define REPLACE_SV(sv,val) SB SvREFCNT_dec (sv); (sv) = (val); (val) = 0; SE
286 290
287static void 291static void
288load_state(Coro__State c) 292load_state (Coro__State c)
289{ 293{
290#define VAR(name,type) PL_ ## name = c->name; 294#define VAR(name,type) PL_ ## name = c->name;
291# include "state.h" 295# include "state.h"
292#undef VAR 296#undef VAR
293 297
310 PUTBACK; 314 PUTBACK;
311 } 315 }
312} 316}
313 317
314static void 318static void
315save_state(Coro__State c, int flags) 319save_state (Coro__State c, int flags)
316{ 320{
317 { 321 {
318 dSP; 322 dSP;
319 I32 cxix = cxstack_ix; 323 I32 cxix = cxstack_ix;
320 PERL_CONTEXT *ccstk = cxstack; 324 PERL_CONTEXT *ccstk = cxstack;
331 { 335 {
332 while (cxix >= 0) 336 while (cxix >= 0)
333 { 337 {
334 PERL_CONTEXT *cx = &ccstk[cxix--]; 338 PERL_CONTEXT *cx = &ccstk[cxix--];
335 339
336 if (CxTYPE(cx) == CXt_SUB) 340 if (CxTYPE (cx) == CXt_SUB)
337 { 341 {
338 CV *cv = cx->blk_sub.cv; 342 CV *cv = cx->blk_sub.cv;
339 343
340 if (CvDEPTH (cv)) 344 if (CvDEPTH (cv))
341 { 345 {
342 EXTEND (SP, 3); 346 EXTEND (SP, 3);
343 347
344 PUSHs ((SV *)CvPADLIST(cv)); 348 PUSHs ((SV *)CvPADLIST (cv));
345 PUSHs (INT2PTR (SV *, CvDEPTH (cv))); 349 PUSHs (INT2PTR (SV *, CvDEPTH (cv)));
346 PUSHs ((SV *)cv); 350 PUSHs ((SV *)cv);
347 351
348 CvDEPTH (cv) = 0; 352 CvDEPTH (cv) = 0;
349 get_padlist (cv); 353 get_padlist (cv);
350 } 354 }
351 } 355 }
352#ifdef CXt_FORMAT 356#ifdef CXt_FORMAT
353 else if (CxTYPE(cx) == CXt_FORMAT) 357 else if (CxTYPE (cx) == CXt_FORMAT)
354 { 358 {
355 /* I never used formats, so how should I know how these are implemented? */ 359 /* I never used formats, so how should I know how these are implemented? */
356 /* my bold guess is as a simple, plain sub... */ 360 /* my bold guess is as a simple, plain sub... */
357 croak ("CXt_FORMAT not yet handled. Don't switch coroutines from within formats"); 361 croak ("CXt_FORMAT not yet handled. Don't switch coroutines from within formats");
358 } 362 }
386 * not usually need a lot of stackspace. 390 * not usually need a lot of stackspace.
387 */ 391 */
388static void 392static void
389coro_init_stacks () 393coro_init_stacks ()
390{ 394{
391 PL_curstackinfo = new_stackinfo(96, 1024/sizeof(PERL_CONTEXT) - 1); 395 PL_curstackinfo = new_stackinfo(128, 1024/sizeof(PERL_CONTEXT));
392 PL_curstackinfo->si_type = PERLSI_MAIN; 396 PL_curstackinfo->si_type = PERLSI_MAIN;
393 PL_curstack = PL_curstackinfo->si_stack; 397 PL_curstack = PL_curstackinfo->si_stack;
394 PL_mainstack = PL_curstack; /* remember in case we switch stacks */ 398 PL_mainstack = PL_curstack; /* remember in case we switch stacks */
395 399
396 PL_stack_base = AvARRAY(PL_curstack); 400 PL_stack_base = AvARRAY(PL_curstack);
397 PL_stack_sp = PL_stack_base; 401 PL_stack_sp = PL_stack_base;
398 PL_stack_max = PL_stack_base + AvMAX(PL_curstack); 402 PL_stack_max = PL_stack_base + AvMAX(PL_curstack);
399 403
400 New(50,PL_tmps_stack,96,SV*); 404 New(50,PL_tmps_stack,128,SV*);
401 PL_tmps_floor = -1; 405 PL_tmps_floor = -1;
402 PL_tmps_ix = -1; 406 PL_tmps_ix = -1;
403 PL_tmps_max = 96; 407 PL_tmps_max = 128;
404 408
405 New(54,PL_markstack,16,I32); 409 New(54,PL_markstack,32,I32);
406 PL_markstack_ptr = PL_markstack; 410 PL_markstack_ptr = PL_markstack;
407 PL_markstack_max = PL_markstack + 16; 411 PL_markstack_max = PL_markstack + 32;
408 412
409#ifdef SET_MARK_OFFSET 413#ifdef SET_MARK_OFFSET
410 SET_MARK_OFFSET; 414 SET_MARK_OFFSET;
411#endif 415#endif
412 416
413 New(54,PL_scopestack,16,I32); 417 New(54,PL_scopestack,32,I32);
414 PL_scopestack_ix = 0; 418 PL_scopestack_ix = 0;
415 PL_scopestack_max = 16; 419 PL_scopestack_max = 32;
416 420
417 New(54,PL_savestack,96,ANY); 421 New(54,PL_savestack,64,ANY);
418 PL_savestack_ix = 0; 422 PL_savestack_ix = 0;
419 PL_savestack_max = 96; 423 PL_savestack_max = 64;
420 424
421#if !PERL_VERSION_ATLEAST (5,9,0) 425#if !PERL_VERSION_ATLEAST (5,9,0)
422 New(54,PL_retstack,8,OP*); 426 New(54,PL_retstack,16,OP*);
423 PL_retstack_ix = 0; 427 PL_retstack_ix = 0;
424 PL_retstack_max = 8; 428 PL_retstack_max = 16;
425#endif 429#endif
426} 430}
427 431
428/* 432/*
429 * destroy the stacks, the callchain etc... 433 * destroy the stacks, the callchain etc...
482 * emulate part of the perl startup here. 486 * emulate part of the perl startup here.
483 */ 487 */
484 488
485 coro_init_stacks (); 489 coro_init_stacks ();
486 490
487 PL_curcop = 0; 491 PL_curcop = &PL_compiling;
488 PL_in_eval = 0; 492 PL_in_eval = EVAL_NULL;
489 PL_curpm = 0; 493 PL_curpm = 0;
494 PL_localizing = 0;
495 PL_dirty = 0;
496 PL_restartop = 0;
490 497
491 { 498 {
492 dSP; 499 dSP;
493 LOGOP myop; 500 LOGOP myop;
494 501
507 PUSHMARK (SP); 514 PUSHMARK (SP);
508 XPUSHs ((SV *)get_cv ("Coro::State::_coro_init", FALSE)); 515 XPUSHs ((SV *)get_cv ("Coro::State::_coro_init", FALSE));
509 PUTBACK; 516 PUTBACK;
510 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); 517 PL_op = PL_ppaddr[OP_ENTERSUB](aTHX);
511 SPAGAIN; 518 SPAGAIN;
512
513 ENTER; /* necessary e.g. for dounwind */
514 } 519 }
520
521 ENTER; /* necessary e.g. for dounwind */
515} 522}
516 523
517static void 524static void
518free_coro_mortal () 525free_coro_mortal ()
519{ 526{
613 620
614 return cctx; 621 return cctx;
615} 622}
616 623
617static void 624static void
618cctx_free (coro_cctx *cctx) 625cctx_destroy (coro_cctx *cctx)
619{ 626{
620 if (!cctx) 627 if (!cctx)
621 return; 628 return;
622 629
623 --cctx_count; 630 --cctx_count;
640{ 647{
641 coro_cctx *cctx; 648 coro_cctx *cctx;
642 649
643 if (cctx_first) 650 if (cctx_first)
644 { 651 {
645 --cctx_idle;
646 cctx = cctx_first; 652 cctx = cctx_first;
647 cctx_first = cctx->next; 653 cctx_first = cctx->next;
654 --cctx_idle;
648 } 655 }
649 else 656 else
650 { 657 {
651 cctx = cctx_new (); 658 cctx = cctx_new ();
652 PL_op = PL_op->op_next; 659 PL_op = PL_op->op_next;
656} 663}
657 664
658static void 665static void
659cctx_put (coro_cctx *cctx) 666cctx_put (coro_cctx *cctx)
660{ 667{
668 /* free another cctx if overlimit */
669 if (cctx_idle >= MAX_IDLE_CCTX)
670 {
671 coro_cctx *first = cctx_first;
672 cctx_first = first->next;
673 --cctx_idle;
674
675 assert (!first->inuse);
676 cctx_destroy (first);
677 }
678
661 ++cctx_idle; 679 ++cctx_idle;
662 cctx->next = cctx_first; 680 cctx->next = cctx_first;
663 cctx_first = cctx; 681 cctx_first = cctx;
664} 682}
665 683
674 ((coro_cctx *)prev)->idle_sp = STACKLEVEL; 692 ((coro_cctx *)prev)->idle_sp = STACKLEVEL;
675 else if (prev != next) 693 else if (prev != next)
676 { 694 {
677 coro_cctx *prev__cctx; 695 coro_cctx *prev__cctx;
678 696
679 if (!prev->cctx) 697 if (prev->flags & CF_NEW)
680 { 698 {
681 /* create a new empty context */ 699 /* create a new empty context */
682 Newz (0, prev->cctx, 1, coro_cctx); 700 Newz (0, prev->cctx, 1, coro_cctx);
683 prev->cctx->inuse = 1; 701 prev->cctx->inuse = 1;
702 prev->flags &= ~CF_NEW;
684 prev->flags |= CF_RUNNING; 703 prev->flags |= CF_RUNNING;
685 } 704 }
686 705
706 /*TODO: must not croak here */
687 assert ( prev->flags & CF_RUNNING); 707 if (!prev->flags & CF_RUNNING)
708 croak ("Coro::State::transfer called with non-running prev Coro::State, but can only transfer from running states");
709
688 assert (!next->flags & CF_RUNNING); 710 if (next->flags & CF_RUNNING)
711 croak ("Coro::State::transfer called with running next Coro::State, but can only transfer to inactive states");
689 712
690 prev->flags &= ~CF_RUNNING; 713 prev->flags &= ~CF_RUNNING;
691 next->flags |= CF_RUNNING; 714 next->flags |= CF_RUNNING;
692 715
693 LOCK; 716 LOCK;
699 LOAD (next); 722 LOAD (next);
700 } 723 }
701 else 724 else
702 { 725 {
703 /* need to start coroutine */ 726 /* need to start coroutine */
727 assert (next->flags & CF_NEW);
728 next->flags &= ~CF_NEW;
704 /* first get rid of the old state */ 729 /* first get rid of the old state */
705 SAVE (prev, -1); 730 SAVE (prev, -1);
706 /* setup coroutine call */ 731 /* setup coroutine call */
707 setup_coro (next); 732 setup_coro (next);
708 /* need a stack */ 733 /* need a new stack */
709 assert (!next->stack); 734 assert (!next->stack);
710 next->cctx = 0;
711 } 735 }
712 736
713 prev__cctx = prev->cctx; 737 prev__cctx = prev->cctx;
714 738
715 /* possibly "free" the cctx */ 739 /* possibly "free" the cctx */
716 if (prev__cctx->idle_sp == STACKLEVEL) 740 if (prev__cctx->idle_sp == STACKLEVEL && 0)
717 { 741 {
742 /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */
718 assert (PL_top_env == prev__cctx->top_env);//D 743 assert (PL_top_env == prev__cctx->top_env);
744
745 prev->cctx = 0;
746
719 cctx_put (prev__cctx); 747 cctx_put (prev__cctx);
720 prev->cctx = 0; 748 prev__cctx->inuse = 0;
721 } 749 }
722 750
723 if (!next->cctx) 751 if (!next->cctx)
752 {
724 next->cctx = cctx_get (); 753 next->cctx = cctx_get ();
754 assert (!next->cctx->inuse);
755 next->cctx->inuse = 1;
756 }
725 757
726 if (prev__cctx != next->cctx) 758 if (prev__cctx != next->cctx)
727 { 759 {
728 assert ( prev__cctx->inuse);
729 assert (!next->cctx->inuse);
730
731 prev__cctx->inuse = 0;
732 next->cctx->inuse = 1;
733
734 prev__cctx->top_env = PL_top_env; 760 prev__cctx->top_env = PL_top_env;
735 PL_top_env = next->cctx->top_env; 761 PL_top_env = next->cctx->top_env;
736 coro_transfer (&prev__cctx->cctx, &next->cctx->cctx); 762 coro_transfer (&prev__cctx->cctx, &next->cctx->cctx);
737 } 763 }
738 764
758 784
759 if (coro->mainstack && coro->mainstack != main_mainstack) 785 if (coro->mainstack && coro->mainstack != main_mainstack)
760 { 786 {
761 struct coro temp; 787 struct coro temp;
762 788
789 if (coro->flags & CF_RUNNING)
790 croak ("FATAL: tried to destroy currently running coroutine");
791
763 SAVE ((&temp), TRANSFER_SAVE_ALL); 792 SAVE ((&temp), TRANSFER_SAVE_ALL);
764 LOAD (coro); 793 LOAD (coro);
765 794
766 coro_destroy_stacks (); 795 coro_destroy_stacks ();
767 796
768 LOAD ((&temp)); /* this will get rid of defsv etc.. */ 797 LOAD ((&temp)); /* this will get rid of defsv etc.. */
769 798
770 coro->mainstack = 0; 799 coro->mainstack = 0;
771 } 800 }
772 801
773 cctx_free (coro->cctx); 802 cctx_destroy (coro->cctx);
774 SvREFCNT_dec (coro->args); 803 SvREFCNT_dec (coro->args);
775 Safefree (coro); 804 Safefree (coro);
776} 805}
777 806
778static int 807static int
838} 867}
839 868
840static void 869static void
841api_transfer (SV *prev, SV *next, int flags) 870api_transfer (SV *prev, SV *next, int flags)
842{ 871{
843 dTHX;
844 struct transfer_args ta; 872 struct transfer_args ta;
845 873
846 prepare_transfer (&ta, prev, next, flags); 874 prepare_transfer (&ta, prev, next, flags);
847 TRANSFER (ta); 875 TRANSFER (ta);
848} 876}
855#define PRIO_LOW -1 883#define PRIO_LOW -1
856#define PRIO_IDLE -3 884#define PRIO_IDLE -3
857#define PRIO_MIN -4 885#define PRIO_MIN -4
858 886
859/* for Coro.pm */ 887/* for Coro.pm */
860static GV *coro_current, *coro_idle; 888static SV *coro_current;
861static AV *coro_ready [PRIO_MAX-PRIO_MIN+1]; 889static AV *coro_ready [PRIO_MAX-PRIO_MIN+1];
862static int coro_nready; 890static int coro_nready;
863 891
864static void 892static void
865coro_enq (SV *sv) 893coro_enq (SV *coro_sv)
866{ 894{
867 int prio;
868
869 if (SvTYPE (sv) != SVt_PVHV)
870 croak ("Coro::ready tried to enqueue something that is not a coroutine");
871
872 prio = SvSTATE (sv)->prio;
873
874 av_push (coro_ready [prio - PRIO_MIN], sv); 895 av_push (coro_ready [SvSTATE (coro_sv)->prio - PRIO_MIN], coro_sv);
875 coro_nready++; 896 coro_nready++;
876} 897}
877 898
878static SV * 899static SV *
879coro_deq (int min_prio) 900coro_deq (int min_prio)
901 922
902 if (SvROK (coro_sv)) 923 if (SvROK (coro_sv))
903 coro_sv = SvRV (coro_sv); 924 coro_sv = SvRV (coro_sv);
904 925
905 coro = SvSTATE (coro_sv); 926 coro = SvSTATE (coro_sv);
927
906 if (coro->flags & CF_READY) 928 if (coro->flags & CF_READY)
907 return 0; 929 return 0;
930
931#if 0 /* this is actually harmless */
932 if (coro->flags & CF_RUNNING)
933 croak ("Coro::ready called on currently running coroutine");
934#endif
908 935
909 coro->flags |= CF_READY; 936 coro->flags |= CF_READY;
910 937
911 LOCK; 938 LOCK;
912 coro_enq (SvREFCNT_inc (coro_sv)); 939 coro_enq (SvREFCNT_inc (coro_sv));
916} 943}
917 944
918static int 945static int
919api_is_ready (SV *coro_sv) 946api_is_ready (SV *coro_sv)
920{ 947{
921 struct coro *coro;
922
923 return !!(SvSTATE (coro_sv)->flags & CF_READY); 948 return !!SvSTATE (coro_sv)->flags & CF_READY;
924} 949}
925 950
926static void 951static void
927prepare_schedule (struct transfer_args *ta) 952prepare_schedule (struct transfer_args *ta)
928{ 953{
929 SV *current, *prev, *next; 954 SV *prev, *next;
930
931 current = GvSV (coro_current);
932 955
933 for (;;) 956 for (;;)
934 { 957 {
935 LOCK; 958 LOCK;
936 next = coro_deq (PRIO_MIN); 959 next = coro_deq (PRIO_MIN);
945 ENTER; 968 ENTER;
946 SAVETMPS; 969 SAVETMPS;
947 970
948 PUSHMARK (SP); 971 PUSHMARK (SP);
949 PUTBACK; 972 PUTBACK;
950 call_sv (GvSV (coro_idle), G_DISCARD); 973 call_sv (get_sv ("Coro::idle", FALSE), G_DISCARD);
951 974
952 FREETMPS; 975 FREETMPS;
953 LEAVE; 976 LEAVE;
954 } 977 }
955 } 978 }
956 979
957 prev = SvRV (current); 980 prev = SvRV (coro_current);
958 SvRV (current) = next; 981 SvRV_set (coro_current, next);
959 982
960 /* free this only after the transfer */ 983 /* free this only after the transfer */
961 LOCK; 984 LOCK;
962 free_coro_mortal (); 985 free_coro_mortal ();
963 UNLOCK; 986 UNLOCK;
964 coro_mortal = prev; 987 coro_mortal = prev;
965 988
989 assert (!SvROK(prev));//D
990 assert (!SvROK(next));//D
991
966 ta->prev = SvSTATE (prev); 992 ta->prev = SvSTATE (prev);
967 ta->next = SvSTATE (next); 993 ta->next = SvSTATE (next);
968 ta->flags = TRANSFER_SAVE_ALL; 994 ta->flags = TRANSFER_SAVE_ALL;
969 995
996 assert (ta->flags & CF_READY);
970 ta->next->flags &= ~CF_READY; 997 ta->next->flags &= ~CF_READY;
971} 998}
972 999
973static void 1000static void
974prepare_cede (struct transfer_args *ta) 1001prepare_cede (struct transfer_args *ta)
975{ 1002{
976 api_ready (GvSV (coro_current)); 1003 api_ready (coro_current);
977 1004
978 prepare_schedule (ta); 1005 prepare_schedule (ta);
979} 1006}
980 1007
981static void 1008static void
982api_schedule (void) 1009api_schedule (void)
983{ 1010{
984 dTHX;
985 struct transfer_args ta; 1011 struct transfer_args ta;
986 1012
987 prepare_schedule (&ta); 1013 prepare_schedule (&ta);
988 TRANSFER (ta); 1014 TRANSFER (ta);
989} 1015}
990 1016
991static void 1017static void
992api_cede (void) 1018api_cede (void)
993{ 1019{
994 dTHX;
995 struct transfer_args ta; 1020 struct transfer_args ta;
996 1021
997 prepare_cede (&ta); 1022 prepare_cede (&ta);
998 TRANSFER (ta); 1023 TRANSFER (ta);
999} 1024}
1031 HV *hv; 1056 HV *hv;
1032 int i; 1057 int i;
1033 1058
1034 Newz (0, coro, 1, struct coro); 1059 Newz (0, coro, 1, struct coro);
1035 coro->args = newAV (); 1060 coro->args = newAV ();
1061 coro->flags = CF_NEW;
1036 1062
1037 hv = newHV (); 1063 hv = newHV ();
1038 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP; 1064 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP;
1039 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 1065 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
1040 1066
1063 ta.flags = TRANSFER_SET_STACKLEVEL; 1089 ta.flags = TRANSFER_SET_STACKLEVEL;
1064 break; 1090 break;
1065 1091
1066 case 1: 1092 case 1:
1067 if (items != 3) 1093 if (items != 3)
1068 croak ("Coro::State::transfer(prev,next,flags) expects three arguments, not %d", items); 1094 croak ("Coro::State::transfer (prev,next,flags) expects three arguments, not %d", items);
1069 1095
1070 prepare_transfer (&ta, ST (0), ST (1), SvIV (ST (2))); 1096 prepare_transfer (&ta, ST (0), ST (1), SvIV (ST (2)));
1071 break; 1097 break;
1072 1098
1073 case 2: 1099 case 2:
1083 SV *yieldstack; 1109 SV *yieldstack;
1084 SV *sv; 1110 SV *sv;
1085 AV *defav = GvAV (PL_defgv); 1111 AV *defav = GvAV (PL_defgv);
1086 1112
1087 yieldstack = *hv_fetch ( 1113 yieldstack = *hv_fetch (
1088 (HV *)SvRV (GvSV (coro_current)), 1114 (HV *)SvRV (coro_current),
1089 "yieldstack", sizeof ("yieldstack") - 1, 1115 "yieldstack", sizeof ("yieldstack") - 1,
1090 0 1116 0
1091 ); 1117 );
1092 1118
1093 /* set up @_ -- ugly */ 1119 /* set up @_ -- ugly */
1155 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL)); 1181 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL));
1156 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW)); 1182 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW));
1157 newCONSTSUB (coro_stash, "PRIO_IDLE", newSViv (PRIO_IDLE)); 1183 newCONSTSUB (coro_stash, "PRIO_IDLE", newSViv (PRIO_IDLE));
1158 newCONSTSUB (coro_stash, "PRIO_MIN", newSViv (PRIO_MIN)); 1184 newCONSTSUB (coro_stash, "PRIO_MIN", newSViv (PRIO_MIN));
1159 1185
1160 coro_current = gv_fetchpv ("Coro::current", TRUE, SVt_PV); 1186 coro_current = get_sv ("Coro::current", FALSE);
1161 coro_idle = gv_fetchpv ("Coro::idle" , TRUE, SVt_PV); 1187 SvREADONLY_on (coro_current);
1162 1188
1163 for (i = PRIO_MAX - PRIO_MIN + 1; i--; ) 1189 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
1164 coro_ready[i] = newAV (); 1190 coro_ready[i] = newAV ();
1165 1191
1166 { 1192 {
1221 CODE: 1247 CODE:
1222 RETVAL = coro_nready; 1248 RETVAL = coro_nready;
1223 OUTPUT: 1249 OUTPUT:
1224 RETVAL 1250 RETVAL
1225 1251
1252void
1253_set_current (SV *current)
1254 PROTOTYPE: $
1255 CODE:
1256 SvREFCNT_dec (SvRV (coro_current));
1257 SvRV_set (coro_current, SvREFCNT_inc (SvRV (current)));
1258
1226MODULE = Coro::State PACKAGE = Coro::AIO 1259MODULE = Coro::State PACKAGE = Coro::AIO
1227 1260
1228SV * 1261SV *
1229_get_state () 1262_get_state ()
1230 CODE: 1263 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines