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.236 by root, Sat May 10 17:43:41 2008 UTC vs.
Revision 1.253 by root, Fri Nov 7 20:12:26 2008 UTC

4#define PERL_EXT 4#define PERL_EXT
5 5
6#include "EXTERN.h" 6#include "EXTERN.h"
7#include "perl.h" 7#include "perl.h"
8#include "XSUB.h" 8#include "XSUB.h"
9#include "perliol.h"
9 10
10#include "patchlevel.h" 11#include "patchlevel.h"
11 12
12#include <stdio.h> 13#include <stdio.h>
13#include <errno.h> 14#include <errno.h>
80# ifndef IS_PADCONST 81# ifndef IS_PADCONST
81# define IS_PADCONST(v) 0 82# define IS_PADCONST(v) 0
82# endif 83# endif
83#endif 84#endif
84 85
86/* 5.11 */
87#ifndef CxHASARGS
88# define CxHASARGS(cx) (cx)->blk_sub.hasargs
89#endif
90
91/* 5.10.0 */
92#ifndef SvREFCNT_inc_NN
93# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv)
94#endif
95
85/* 5.8.8 */ 96/* 5.8.8 */
86#ifndef GV_NOTQUAL 97#ifndef GV_NOTQUAL
87# define GV_NOTQUAL 0 98# define GV_NOTQUAL 0
88#endif 99#endif
89#ifndef newSV 100#ifndef newSV
90# define newSV(l) NEWSV(0,l) 101# define newSV(l) NEWSV(0,l)
91#endif
92
93/* 5.11 */
94#ifndef CxHASARGS
95# define CxHASARGS(cx) (cx)->blk_sub.hasargs
96#endif 102#endif
97 103
98/* 5.8.7 */ 104/* 5.8.7 */
99#ifndef SvRV_set 105#ifndef SvRV_set
100# define SvRV_set(s,v) SvRV(s) = (v) 106# define SvRV_set(s,v) SvRV(s) = (v)
136#define NOINLINE attribute ((noinline)) 142#define NOINLINE attribute ((noinline))
137 143
138#include "CoroAPI.h" 144#include "CoroAPI.h"
139 145
140#ifdef USE_ITHREADS 146#ifdef USE_ITHREADS
141static perl_mutex coro_mutex; 147static perl_mutex coro_lock;
142# define LOCK do { MUTEX_LOCK (&coro_mutex); } while (0) 148# define LOCK do { MUTEX_LOCK (&coro_lock); } while (0)
143# define UNLOCK do { MUTEX_UNLOCK (&coro_mutex); } while (0) 149# define UNLOCK do { MUTEX_UNLOCK (&coro_lock); } while (0)
144#else 150#else
145# define LOCK (void)0 151# define LOCK (void)0
146# define UNLOCK (void)0 152# define UNLOCK (void)0
147#endif 153#endif
148 154
149/* helper storage struct for Coro::AIO */ 155/* helper storage struct for Coro::AIO */
150struct io_state 156struct io_state
151{ 157{
158 AV *res;
152 int errorno; 159 int errorno;
153 I32 laststype; 160 I32 laststype;
154 int laststatval; 161 int laststatval;
155 Stat_t statcache; 162 Stat_t statcache;
156}; 163};
157 164
165static double (*nvtime)(); /* so why doesn't it take void? */
166
158static size_t coro_stacksize = CORO_STACKSIZE; 167static size_t coro_stacksize = CORO_STACKSIZE;
159static struct CoroAPI coroapi; 168static struct CoroAPI coroapi;
160static AV *main_mainstack; /* used to differentiate between $main and others */ 169static AV *main_mainstack; /* used to differentiate between $main and others */
161static JMPENV *main_top_env; 170static JMPENV *main_top_env;
162static HV *coro_state_stash, *coro_stash; 171static HV *coro_state_stash, *coro_stash;
163static volatile SV *coro_mortal; /* will be freed after next transfer */ 172static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */
164 173
165static GV *irsgv; /* $/ */ 174static GV *irsgv; /* $/ */
166static GV *stdoutgv; /* *STDOUT */ 175static GV *stdoutgv; /* *STDOUT */
167static SV *rv_diehook; 176static SV *rv_diehook;
168static SV *rv_warnhook; 177static SV *rv_warnhook;
321 Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1); 330 Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1);
322#endif 331#endif
323 newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)]; 332 newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)];
324 --AvFILLp (padlist); 333 --AvFILLp (padlist);
325 334
326 av_store (newpadlist, 0, SvREFCNT_inc (*av_fetch (padlist, 0, FALSE))); 335 av_store (newpadlist, 0, SvREFCNT_inc_NN (*av_fetch (padlist, 0, FALSE)));
327 av_store (newpadlist, 1, (SV *)newpad); 336 av_store (newpadlist, 1, (SV *)newpad);
328 337
329 return newpadlist; 338 return newpadlist;
330} 339}
331 340
361 370
362 /* casting is fun. */ 371 /* casting is fun. */
363 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av))) 372 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av)))
364 free_padlist (aTHX_ padlist); 373 free_padlist (aTHX_ padlist);
365 374
375 SvREFCNT_dec (av); /* sv_magicext increased the refcount */
376
366 return 0; 377 return 0;
367} 378}
368 379
369#define CORO_MAGIC_type_cv PERL_MAGIC_ext 380#define CORO_MAGIC_type_cv PERL_MAGIC_ext
370#define CORO_MAGIC_type_state PERL_MAGIC_ext 381#define CORO_MAGIC_type_state PERL_MAGIC_ext
372static MGVTBL coro_cv_vtbl = { 383static MGVTBL coro_cv_vtbl = {
373 0, 0, 0, 0, 384 0, 0, 0, 0,
374 coro_cv_free 385 coro_cv_free
375}; 386};
376 387
377#define CORO_MAGIC(sv,type) \ 388#define CORO_MAGIC(sv, type) \
378 SvMAGIC (sv) \ 389 SvMAGIC (sv) \
379 ? SvMAGIC (sv)->mg_type == type \ 390 ? SvMAGIC (sv)->mg_type == type \
380 ? SvMAGIC (sv) \ 391 ? SvMAGIC (sv) \
381 : mg_find (sv, type) \ 392 : mg_find (sv, type) \
382 : 0 393 : 0
383 394
384#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv) 395#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv)
385#define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state) 396#define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state)
386 397
387static struct coro * 398static struct coro *
420 if (expect_true (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0)) 431 if (expect_true (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0))
421 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; 432 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--];
422 else 433 else
423 { 434 {
424#if CORO_PREFER_PERL_FUNCTIONS 435#if CORO_PREFER_PERL_FUNCTIONS
425 /* this is probably cleaner, but also slower? */ 436 /* this is probably cleaner? but also slower! */
437 /* in practise, it seems to be less stable */
426 CV *cp = Perl_cv_clone (cv); 438 CV *cp = Perl_cv_clone (cv);
427 CvPADLIST (cv) = CvPADLIST (cp); 439 CvPADLIST (cv) = CvPADLIST (cp);
428 CvPADLIST (cp) = 0; 440 CvPADLIST (cp) = 0;
429 SvREFCNT_dec (cp); 441 SvREFCNT_dec (cp);
430#else 442#else
616 628
617/* 629/*
618 * destroy the stacks, the callchain etc... 630 * destroy the stacks, the callchain etc...
619 */ 631 */
620static void 632static void
621coro_destroy_stacks (pTHX) 633coro_destruct_stacks (pTHX)
622{ 634{
623 while (PL_curstackinfo->si_next) 635 while (PL_curstackinfo->si_next)
624 PL_curstackinfo = PL_curstackinfo->si_next; 636 PL_curstackinfo = PL_curstackinfo->si_next;
625 637
626 while (PL_curstackinfo) 638 while (PL_curstackinfo)
663 #undef VAR 675 #undef VAR
664 } 676 }
665 else 677 else
666 slot = coro->slot; 678 slot = coro->slot;
667 679
680 if (slot)
681 {
668 rss += sizeof (slot->curstackinfo); 682 rss += sizeof (slot->curstackinfo);
669 rss += (slot->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT); 683 rss += (slot->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT);
670 rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvMAX (slot->curstack)) * sizeof (SV *); 684 rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvMAX (slot->curstack)) * sizeof (SV *);
671 rss += slot->tmps_max * sizeof (SV *); 685 rss += slot->tmps_max * sizeof (SV *);
672 rss += (slot->markstack_max - slot->markstack_ptr) * sizeof (I32); 686 rss += (slot->markstack_max - slot->markstack_ptr) * sizeof (I32);
673 rss += slot->scopestack_max * sizeof (I32); 687 rss += slot->scopestack_max * sizeof (I32);
674 rss += slot->savestack_max * sizeof (ANY); 688 rss += slot->savestack_max * sizeof (ANY);
675 689
676#if !PERL_VERSION_ATLEAST (5,10,0) 690#if !PERL_VERSION_ATLEAST (5,10,0)
677 rss += slot->retstack_max * sizeof (OP *); 691 rss += slot->retstack_max * sizeof (OP *);
678#endif 692#endif
693 }
679 } 694 }
680 695
681 return rss; 696 return rss;
682} 697}
683 698
684/** coroutine stack handling ************************************************/ 699/** coroutine stack handling ************************************************/
685 700
686static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg); 701static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg);
687static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg); 702static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg);
703static int (*orig_sigelem_clr) (pTHX_ SV *sv, MAGIC *mg);
704
705/* apparently < 5.8.8 */
706#ifndef MgPV_nolen_const
707#define MgPV_nolen_const(mg) (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \
708 SvPV_nolen((SV*)((mg)->mg_ptr)) : \
709 (const char*)(mg)->mg_ptr)
710#endif
688 711
689/* 712/*
690 * This overrides the default magic get method of %SIG elements. 713 * This overrides the default magic get method of %SIG elements.
691 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook 714 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook
692 * and instead of tryign to save and restore the hash elements, we just provide 715 * and instead of tryign to save and restore the hash elements, we just provide
700{ 723{
701 const char *s = MgPV_nolen_const (mg); 724 const char *s = MgPV_nolen_const (mg);
702 725
703 if (*s == '_') 726 if (*s == '_')
704 { 727 {
705 if (strEQ (s, "__DIE__" ) && PL_diehook ) return sv_setsv (sv, PL_diehook ), 0; 728 SV **svp = 0;
706 if (strEQ (s, "__WARN__") && PL_warnhook) return sv_setsv (sv, PL_warnhook), 0; 729
730 if (strEQ (s, "__DIE__" )) svp = &PL_diehook;
731 if (strEQ (s, "__WARN__")) svp = &PL_warnhook;
732
733 if (svp)
734 {
735 sv_setsv (sv, *svp ? *svp : &PL_sv_undef);
736 return 0;
737 }
707 } 738 }
708 739
709 return orig_sigelem_get ? orig_sigelem_get (aTHX_ sv, mg) : 0; 740 return orig_sigelem_get ? orig_sigelem_get (aTHX_ sv, mg) : 0;
741}
742
743static int
744coro_sigelem_clr (pTHX_ SV *sv, MAGIC *mg)
745{
746 const char *s = MgPV_nolen_const (mg);
747
748 if (*s == '_')
749 {
750 SV **svp = 0;
751
752 if (strEQ (s, "__DIE__" )) svp = &PL_diehook;
753 if (strEQ (s, "__WARN__")) svp = &PL_warnhook;
754
755 if (svp)
756 {
757 SV *old = *svp;
758 *svp = 0;
759 SvREFCNT_dec (old);
760 return 0;
761 }
762 }
763
764 return orig_sigelem_clr ? orig_sigelem_clr (aTHX_ sv, mg) : 0;
710} 765}
711 766
712static int 767static int
713coro_sigelem_set (pTHX_ SV *sv, MAGIC *mg) 768coro_sigelem_set (pTHX_ SV *sv, MAGIC *mg)
714{ 769{
761 GvSV (PL_defgv) = newSV (0); 816 GvSV (PL_defgv) = newSV (0);
762 GvAV (PL_defgv) = coro->args; coro->args = 0; 817 GvAV (PL_defgv) = coro->args; coro->args = 0;
763 GvSV (PL_errgv) = newSV (0); 818 GvSV (PL_errgv) = newSV (0);
764 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 819 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
765 PL_rs = newSVsv (GvSV (irsgv)); 820 PL_rs = newSVsv (GvSV (irsgv));
766 PL_defoutgv = (GV *)SvREFCNT_inc (stdoutgv); 821 PL_defoutgv = (GV *)SvREFCNT_inc_NN (stdoutgv);
767 822
768 { 823 {
769 dSP; 824 dSP;
770 LOGOP myop; 825 LOGOP myop;
771 826
788 */ 843 */
789 ENTER; 844 ENTER;
790} 845}
791 846
792static void 847static void
793coro_destroy (pTHX_ struct coro *coro) 848coro_destruct (pTHX_ struct coro *coro)
794{ 849{
795 if (!IN_DESTRUCT) 850 if (!IN_DESTRUCT)
796 { 851 {
797 /* restore all saved variables and stuff */ 852 /* restore all saved variables and stuff */
798 LEAVE_SCOPE (0); 853 LEAVE_SCOPE (0);
820 SvREFCNT_dec (PL_warnhook); 875 SvREFCNT_dec (PL_warnhook);
821 876
822 SvREFCNT_dec (coro->saved_deffh); 877 SvREFCNT_dec (coro->saved_deffh);
823 SvREFCNT_dec (coro->throw); 878 SvREFCNT_dec (coro->throw);
824 879
825 coro_destroy_stacks (aTHX); 880 coro_destruct_stacks (aTHX);
826} 881}
827 882
828static void 883static void
829free_coro_mortal (pTHX) 884free_coro_mortal (pTHX)
830{ 885{
867 : cx->blk_gimme == G_SCALAR ? bot + 1 922 : cx->blk_gimme == G_SCALAR ? bot + 1
868 : bot; 923 : bot;
869 924
870 av_extend (av, top - bot); 925 av_extend (av, top - bot);
871 while (bot < top) 926 while (bot < top)
872 av_push (av, SvREFCNT_inc (*bot++)); 927 av_push (av, SvREFCNT_inc_NN (*bot++));
873 928
874 PL_runops = RUNOPS_DEFAULT; 929 PL_runops = RUNOPS_DEFAULT;
875 ENTER; 930 ENTER;
876 SAVETMPS; 931 SAVETMPS;
877 EXTEND (SP, 3); 932 EXTEND (SP, 3);
1025 coro_cctx *cctx; 1080 coro_cctx *cctx;
1026 void *stack_start; 1081 void *stack_start;
1027 size_t stack_size; 1082 size_t stack_size;
1028 1083
1029 ++cctx_count; 1084 ++cctx_count;
1030
1031 Newz (0, cctx, 1, coro_cctx); 1085 Newz (0, cctx, 1, coro_cctx);
1032 1086
1033#if HAVE_MMAP 1087#if HAVE_MMAP
1034 cctx->ssize = ((coro_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; 1088 cctx->ssize = ((coro_stacksize * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE;
1035 /* mmap supposedly does allocate-on-write for us */ 1089 /* mmap supposedly does allocate-on-write for us */
1071{ 1125{
1072 if (!cctx) 1126 if (!cctx)
1073 return; 1127 return;
1074 1128
1075 --cctx_count; 1129 --cctx_count;
1130 coro_destroy (&cctx->cctx);
1076 1131
1132 /* coro_transfer creates new, empty cctx's */
1133 if (cctx->sptr)
1134 {
1077#if CORO_USE_VALGRIND 1135#if CORO_USE_VALGRIND
1078 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); 1136 VALGRIND_STACK_DEREGISTER (cctx->valgrind_id);
1079#endif 1137#endif
1080 1138
1081#if HAVE_MMAP 1139#if HAVE_MMAP
1082 if (cctx->flags & CC_MAPPED) 1140 if (cctx->flags & CC_MAPPED)
1083 munmap (cctx->sptr, cctx->ssize); 1141 munmap (cctx->sptr, cctx->ssize);
1084 else 1142 else
1085#endif 1143#endif
1086 Safefree (cctx->sptr); 1144 Safefree (cctx->sptr);
1145 }
1087 1146
1088 Safefree (cctx); 1147 Safefree (cctx);
1089} 1148}
1090 1149
1091/* wether this cctx should be destructed */ 1150/* wether this cctx should be destructed */
1110} 1169}
1111 1170
1112static void 1171static void
1113cctx_put (coro_cctx *cctx) 1172cctx_put (coro_cctx *cctx)
1114{ 1173{
1174 assert (("cctx_put called on non-initialised cctx", cctx->sptr));
1175
1115 /* free another cctx if overlimit */ 1176 /* free another cctx if overlimit */
1116 if (expect_false (cctx_idle >= MAX_IDLE_CCTX)) 1177 if (expect_false (cctx_idle >= MAX_IDLE_CCTX))
1117 { 1178 {
1118 coro_cctx *first = cctx_first; 1179 coro_cctx *first = cctx_first;
1119 cctx_first = first->next; 1180 cctx_first = first->next;
1153/* always use the TRANSFER macro */ 1214/* always use the TRANSFER macro */
1154static void NOINLINE 1215static void NOINLINE
1155transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx) 1216transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx)
1156{ 1217{
1157 dSTACKLEVEL; 1218 dSTACKLEVEL;
1158 static volatile int has_throw;
1159 1219
1160 /* sometimes transfer is only called to set idle_sp */ 1220 /* sometimes transfer is only called to set idle_sp */
1161 if (expect_false (!next)) 1221 if (expect_false (!next))
1162 { 1222 {
1163 ((coro_cctx *)prev)->idle_sp = STACKLEVEL; 1223 ((coro_cctx *)prev)->idle_sp = STACKLEVEL;
1164 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */ 1224 assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */
1165 } 1225 }
1166 else if (expect_true (prev != next)) 1226 else if (expect_true (prev != next))
1167 { 1227 {
1228 static volatile int has_throw;
1168 coro_cctx *prev__cctx; 1229 coro_cctx *prev__cctx;
1169 1230
1170 if (expect_false (prev->flags & CF_NEW)) 1231 if (expect_false (prev->flags & CF_NEW))
1171 { 1232 {
1172 /* create a new empty context */ 1233 /* create a new empty/source context */
1234 ++cctx_count;
1173 Newz (0, prev->cctx, 1, coro_cctx); 1235 New (0, prev->cctx, 1, coro_cctx);
1236 prev->cctx->sptr = 0;
1237 coro_create (&prev->cctx->cctx, 0, 0, 0, 0);
1238
1174 prev->flags &= ~CF_NEW; 1239 prev->flags &= ~CF_NEW;
1175 prev->flags |= CF_RUNNING; 1240 prev->flags |= CF_RUNNING;
1176 } 1241 }
1177 1242
1178 prev->flags &= ~CF_RUNNING; 1243 prev->flags &= ~CF_RUNNING;
1285 croak ("FATAL: tried to destroy currently running coroutine"); 1350 croak ("FATAL: tried to destroy currently running coroutine");
1286 1351
1287 save_perl (aTHX_ &temp); 1352 save_perl (aTHX_ &temp);
1288 load_perl (aTHX_ coro); 1353 load_perl (aTHX_ coro);
1289 1354
1290 coro_destroy (aTHX_ coro); 1355 coro_destruct (aTHX_ coro);
1291 1356
1292 load_perl (aTHX_ &temp); 1357 load_perl (aTHX_ &temp);
1293 1358
1294 coro->slot = 0; 1359 coro->slot = 0;
1295 } 1360 }
1383static int 1448static int
1384api_ready (SV *coro_sv) 1449api_ready (SV *coro_sv)
1385{ 1450{
1386 dTHX; 1451 dTHX;
1387 struct coro *coro; 1452 struct coro *coro;
1388 SV *hook; 1453 SV *sv_hook;
1454 void (*xs_hook)(void);
1389 1455
1390 if (SvROK (coro_sv)) 1456 if (SvROK (coro_sv))
1391 coro_sv = SvRV (coro_sv); 1457 coro_sv = SvRV (coro_sv);
1392 1458
1393 coro = SvSTATE (coro_sv); 1459 coro = SvSTATE (coro_sv);
1397 1463
1398 coro->flags |= CF_READY; 1464 coro->flags |= CF_READY;
1399 1465
1400 LOCK; 1466 LOCK;
1401 1467
1402 hook = coro_nready ? 0 : coro_readyhook; 1468 sv_hook = coro_nready ? 0 : coro_readyhook;
1469 xs_hook = coro_nready ? 0 : coroapi.readyhook;
1403 1470
1404 coro_enq (aTHX_ SvREFCNT_inc (coro_sv)); 1471 coro_enq (aTHX_ SvREFCNT_inc_NN (coro_sv));
1405 ++coro_nready; 1472 ++coro_nready;
1406 1473
1407 UNLOCK; 1474 UNLOCK;
1408 1475
1409 if (hook) 1476 if (sv_hook)
1410 { 1477 {
1411 dSP; 1478 dSP;
1412 1479
1413 ENTER; 1480 ENTER;
1414 SAVETMPS; 1481 SAVETMPS;
1415 1482
1416 PUSHMARK (SP); 1483 PUSHMARK (SP);
1417 PUTBACK; 1484 PUTBACK;
1418 call_sv (hook, G_DISCARD); 1485 call_sv (sv_hook, G_DISCARD);
1419 SPAGAIN; 1486 SPAGAIN;
1420 1487
1421 FREETMPS; 1488 FREETMPS;
1422 LEAVE; 1489 LEAVE;
1423 } 1490 }
1491
1492 if (xs_hook)
1493 xs_hook ();
1424 1494
1425 return 1; 1495 return 1;
1426} 1496}
1427 1497
1428static int 1498static int
1578 else 1648 else
1579 coro->slot->runops = RUNOPS_DEFAULT; 1649 coro->slot->runops = RUNOPS_DEFAULT;
1580 } 1650 }
1581} 1651}
1582 1652
1653static int
1654coro_gensub_free (pTHX_ SV *sv, MAGIC *mg)
1655{
1656 AV *padlist;
1657 AV *av = (AV *)mg->mg_obj;
1658
1659 abort ();
1660
1661 return 0;
1662}
1663
1664static MGVTBL coro_gensub_vtbl = {
1665 0, 0, 0, 0,
1666 coro_gensub_free
1667};
1668
1669/*****************************************************************************/
1670/* PerlIO::cede */
1671
1672typedef struct
1673{
1674 PerlIOBuf base;
1675 NV next, every;
1676} PerlIOCede;
1677
1678static IV
1679PerlIOCede_pushed (pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab)
1680{
1681 PerlIOCede *self = PerlIOSelf (f, PerlIOCede);
1682
1683 self->every = SvCUR (arg) ? SvNV (arg) : 0.01;
1684 self->next = nvtime () + self->every;
1685
1686 return PerlIOBuf_pushed (aTHX_ f, mode, Nullsv, tab);
1687}
1688
1689static SV *
1690PerlIOCede_getarg (pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags)
1691{
1692 PerlIOCede *self = PerlIOSelf (f, PerlIOCede);
1693
1694 return newSVnv (self->every);
1695}
1696
1697static IV
1698PerlIOCede_flush (pTHX_ PerlIO *f)
1699{
1700 PerlIOCede *self = PerlIOSelf (f, PerlIOCede);
1701 double now = nvtime ();
1702
1703 if (now >= self->next)
1704 {
1705 api_cede ();
1706 self->next = now + self->every;
1707 }
1708
1709 return PerlIOBuf_flush (aTHX_ f);
1710}
1711
1712static PerlIO_funcs PerlIO_cede =
1713{
1714 sizeof(PerlIO_funcs),
1715 "cede",
1716 sizeof(PerlIOCede),
1717 PERLIO_K_DESTRUCT | PERLIO_K_RAW,
1718 PerlIOCede_pushed,
1719 PerlIOBuf_popped,
1720 PerlIOBuf_open,
1721 PerlIOBase_binmode,
1722 PerlIOCede_getarg,
1723 PerlIOBase_fileno,
1724 PerlIOBuf_dup,
1725 PerlIOBuf_read,
1726 PerlIOBuf_unread,
1727 PerlIOBuf_write,
1728 PerlIOBuf_seek,
1729 PerlIOBuf_tell,
1730 PerlIOBuf_close,
1731 PerlIOCede_flush,
1732 PerlIOBuf_fill,
1733 PerlIOBase_eof,
1734 PerlIOBase_error,
1735 PerlIOBase_clearerr,
1736 PerlIOBase_setlinebuf,
1737 PerlIOBuf_get_base,
1738 PerlIOBuf_bufsiz,
1739 PerlIOBuf_get_ptr,
1740 PerlIOBuf_get_cnt,
1741 PerlIOBuf_set_ptrcnt,
1742};
1743
1744
1583MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ 1745MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_
1584 1746
1585PROTOTYPES: DISABLE 1747PROTOTYPES: DISABLE
1586 1748
1587BOOT: 1749BOOT:
1588{ 1750{
1589#ifdef USE_ITHREADS 1751#ifdef USE_ITHREADS
1590 MUTEX_INIT (&coro_mutex); 1752 MUTEX_INIT (&coro_lock);
1591#endif 1753#endif
1592 BOOT_PAGESIZE; 1754 BOOT_PAGESIZE;
1593 1755
1594 irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); 1756 irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV);
1595 stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); 1757 stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO);
1596 1758
1597 orig_sigelem_get = PL_vtbl_sigelem.svt_get; 1759 orig_sigelem_get = PL_vtbl_sigelem.svt_get; PL_vtbl_sigelem.svt_get = coro_sigelem_get;
1598 PL_vtbl_sigelem.svt_get = coro_sigelem_get; 1760 orig_sigelem_set = PL_vtbl_sigelem.svt_set; PL_vtbl_sigelem.svt_set = coro_sigelem_set;
1599 orig_sigelem_set = PL_vtbl_sigelem.svt_set; 1761 orig_sigelem_clr = PL_vtbl_sigelem.svt_clear; PL_vtbl_sigelem.svt_clear = coro_sigelem_clr;
1600 PL_vtbl_sigelem.svt_set = coro_sigelem_set;
1601 1762
1602 hv_sig = coro_get_hv (aTHX_ "SIG", TRUE); 1763 hv_sig = coro_get_hv (aTHX_ "SIG", TRUE);
1603 rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); 1764 rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV));
1604 rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); 1765 rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV));
1605 1766
1614 main_top_env = PL_top_env; 1775 main_top_env = PL_top_env;
1615 1776
1616 while (main_top_env->je_prev) 1777 while (main_top_env->je_prev)
1617 main_top_env = main_top_env->je_prev; 1778 main_top_env = main_top_env->je_prev;
1618 1779
1619 coroapi.ver = CORO_API_VERSION; 1780 coroapi.ver = CORO_API_VERSION;
1620 coroapi.rev = CORO_API_REVISION; 1781 coroapi.rev = CORO_API_REVISION;
1621 coroapi.transfer = api_transfer; 1782 coroapi.transfer = api_transfer;
1783
1784 {
1785 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1786
1787 if (!svp) croak ("Time::HiRes is required");
1788 if (!SvIOK (*svp)) croak ("Time::NVtime isn't a function pointer");
1789
1790 nvtime = INT2PTR (double (*)(), SvIV (*svp));
1791 }
1622 1792
1623 assert (("PRIO_NORMAL must be 0", !PRIO_NORMAL)); 1793 assert (("PRIO_NORMAL must be 0", !PRIO_NORMAL));
1624} 1794}
1625 1795
1626SV * 1796SV *
1674 ta.next = 0; 1844 ta.next = 0;
1675 break; 1845 break;
1676 1846
1677 case 1: 1847 case 1:
1678 if (items != 2) 1848 if (items != 2)
1679 croak ("Coro::State::transfer (prev,next) expects two arguments, not %d", items); 1849 croak ("Coro::State::transfer (prev, next) expects two arguments, not %d", items);
1680 1850
1681 prepare_transfer (aTHX_ &ta, ST (0), ST (1)); 1851 prepare_transfer (aTHX_ &ta, ST (0), ST (1));
1682 break; 1852 break;
1683 1853
1684 case 2: 1854 case 2:
1754call (Coro::State coro, SV *coderef) 1924call (Coro::State coro, SV *coderef)
1755 ALIAS: 1925 ALIAS:
1756 eval = 1 1926 eval = 1
1757 CODE: 1927 CODE:
1758{ 1928{
1759 if (coro->mainstack) 1929 if (coro->mainstack && ((coro->flags & CF_RUNNING) || coro->slot))
1760 { 1930 {
1761 struct coro temp; 1931 struct coro temp;
1762 1932
1763 if (!(coro->flags & CF_RUNNING)) 1933 if (!(coro->flags & CF_RUNNING))
1764 { 1934 {
1846force_cctx () 2016force_cctx ()
1847 CODE: 2017 CODE:
1848 struct coro *coro = SvSTATE (coro_current); 2018 struct coro *coro = SvSTATE (coro_current);
1849 coro->cctx->idle_sp = 0; 2019 coro->cctx->idle_sp = 0;
1850 2020
1851MODULE = Coro::State PACKAGE = Coro
1852
1853BOOT:
1854{
1855 int i;
1856
1857 av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE);
1858 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE);
1859 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE);
1860
1861 coro_current = coro_get_sv (aTHX_ "Coro::current", FALSE);
1862 SvREADONLY_on (coro_current);
1863
1864 coro_stash = gv_stashpv ("Coro", TRUE);
1865
1866 newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (PRIO_MAX));
1867 newCONSTSUB (coro_stash, "PRIO_HIGH", newSViv (PRIO_HIGH));
1868 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL));
1869 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW));
1870 newCONSTSUB (coro_stash, "PRIO_IDLE", newSViv (PRIO_IDLE));
1871 newCONSTSUB (coro_stash, "PRIO_MIN", newSViv (PRIO_MIN));
1872
1873 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
1874 coro_ready[i] = newAV ();
1875
1876 {
1877 SV *sv = perl_get_sv ("Coro::API", TRUE);
1878 perl_get_sv ("Coro::API", TRUE); /* silence 5.10 warning */
1879
1880 coroapi.schedule = api_schedule;
1881 coroapi.cede = api_cede;
1882 coroapi.cede_notself = api_cede_notself;
1883 coroapi.ready = api_ready;
1884 coroapi.is_ready = api_is_ready;
1885 coroapi.nready = &coro_nready;
1886 coroapi.current = coro_current;
1887
1888 GCoroAPI = &coroapi;
1889 sv_setiv (sv, (IV)&coroapi);
1890 SvREADONLY_on (sv);
1891 }
1892}
1893
1894void
1895_set_current (SV *current)
1896 PROTOTYPE: $
1897 CODE:
1898 SvREFCNT_dec (SvRV (coro_current));
1899 SvRV_set (coro_current, SvREFCNT_inc (SvRV (current)));
1900
1901void
1902_set_readyhook (SV *hook)
1903 PROTOTYPE: $
1904 CODE:
1905 LOCK;
1906 SvREFCNT_dec (coro_readyhook);
1907 coro_readyhook = SvOK (hook) ? newSVsv (hook) : 0;
1908 UNLOCK;
1909
1910int
1911prio (Coro::State coro, int newprio = 0)
1912 ALIAS:
1913 nice = 1
1914 CODE:
1915{
1916 RETVAL = coro->prio;
1917
1918 if (items > 1)
1919 {
1920 if (ix)
1921 newprio = coro->prio - newprio;
1922
1923 if (newprio < PRIO_MIN) newprio = PRIO_MIN;
1924 if (newprio > PRIO_MAX) newprio = PRIO_MAX;
1925
1926 coro->prio = newprio;
1927 }
1928}
1929 OUTPUT:
1930 RETVAL
1931
1932SV *
1933ready (SV *self)
1934 PROTOTYPE: $
1935 CODE:
1936 RETVAL = boolSV (api_ready (self));
1937 OUTPUT:
1938 RETVAL
1939
1940int
1941nready (...)
1942 PROTOTYPE:
1943 CODE:
1944 RETVAL = coro_nready;
1945 OUTPUT:
1946 RETVAL
1947
1948void
1949throw (Coro::State self, SV *throw = &PL_sv_undef)
1950 PROTOTYPE: $;$
1951 CODE:
1952 SvREFCNT_dec (self->throw);
1953 self->throw = SvOK (throw) ? newSVsv (throw) : 0;
1954
1955void 2021void
1956swap_defsv (Coro::State self) 2022swap_defsv (Coro::State self)
1957 PROTOTYPE: $ 2023 PROTOTYPE: $
1958 ALIAS: 2024 ALIAS:
1959 swap_defav = 1 2025 swap_defav = 1
1966 SV **dst = ix ? (SV **)&self->slot->defav : (SV **)&self->slot->defsv; 2032 SV **dst = ix ? (SV **)&self->slot->defav : (SV **)&self->slot->defsv;
1967 2033
1968 SV *tmp = *src; *src = *dst; *dst = tmp; 2034 SV *tmp = *src; *src = *dst; *dst = tmp;
1969 } 2035 }
1970 2036
2037MODULE = Coro::State PACKAGE = Coro
2038
2039BOOT:
2040{
2041 int i;
2042
2043 av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE);
2044 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE);
2045 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE);
2046
2047 coro_current = coro_get_sv (aTHX_ "Coro::current", FALSE);
2048 SvREADONLY_on (coro_current);
2049
2050 coro_stash = gv_stashpv ("Coro", TRUE);
2051
2052 newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (PRIO_MAX));
2053 newCONSTSUB (coro_stash, "PRIO_HIGH", newSViv (PRIO_HIGH));
2054 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL));
2055 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW));
2056 newCONSTSUB (coro_stash, "PRIO_IDLE", newSViv (PRIO_IDLE));
2057 newCONSTSUB (coro_stash, "PRIO_MIN", newSViv (PRIO_MIN));
2058
2059 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
2060 coro_ready[i] = newAV ();
2061
2062 {
2063 SV *sv = perl_get_sv ("Coro::API", TRUE);
2064 perl_get_sv ("Coro::API", TRUE); /* silence 5.10 warning */
2065
2066 coroapi.schedule = api_schedule;
2067 coroapi.cede = api_cede;
2068 coroapi.cede_notself = api_cede_notself;
2069 coroapi.ready = api_ready;
2070 coroapi.is_ready = api_is_ready;
2071 coroapi.nready = &coro_nready;
2072 coroapi.current = coro_current;
2073
2074 GCoroAPI = &coroapi;
2075 sv_setiv (sv, (IV)&coroapi);
2076 SvREADONLY_on (sv);
2077 }
2078}
2079
2080void
2081_set_current (SV *current)
2082 PROTOTYPE: $
2083 CODE:
2084 SvREFCNT_dec (SvRV (coro_current));
2085 SvRV_set (coro_current, SvREFCNT_inc_NN (SvRV (current)));
2086
2087void
2088_set_readyhook (SV *hook)
2089 PROTOTYPE: $
2090 CODE:
2091 LOCK;
2092 SvREFCNT_dec (coro_readyhook);
2093 coro_readyhook = SvOK (hook) ? newSVsv (hook) : 0;
2094 UNLOCK;
2095
2096int
2097prio (Coro::State coro, int newprio = 0)
2098 ALIAS:
2099 nice = 1
2100 CODE:
2101{
2102 RETVAL = coro->prio;
2103
2104 if (items > 1)
2105 {
2106 if (ix)
2107 newprio = coro->prio - newprio;
2108
2109 if (newprio < PRIO_MIN) newprio = PRIO_MIN;
2110 if (newprio > PRIO_MAX) newprio = PRIO_MAX;
2111
2112 coro->prio = newprio;
2113 }
2114}
2115 OUTPUT:
2116 RETVAL
2117
2118SV *
2119ready (SV *self)
2120 PROTOTYPE: $
2121 CODE:
2122 RETVAL = boolSV (api_ready (self));
2123 OUTPUT:
2124 RETVAL
2125
2126int
2127nready (...)
2128 PROTOTYPE:
2129 CODE:
2130 RETVAL = coro_nready;
2131 OUTPUT:
2132 RETVAL
2133
2134void
2135throw (Coro::State self, SV *throw = &PL_sv_undef)
2136 PROTOTYPE: $;$
2137 CODE:
2138 SvREFCNT_dec (self->throw);
2139 self->throw = SvOK (throw) ? newSVsv (throw) : 0;
2140
1971# for async_pool speedup 2141# for async_pool speedup
1972void 2142void
1973_pool_1 (SV *cb) 2143_pool_1 (SV *cb)
1974 CODE: 2144 CODE:
1975{ 2145{
1980 AV *invoke_av; 2150 AV *invoke_av;
1981 int i, len; 2151 int i, len;
1982 2152
1983 if (!invoke) 2153 if (!invoke)
1984 { 2154 {
1985 SvREFCNT_dec (PL_diehook); PL_diehook = 0; 2155 SV *old = PL_diehook;
2156 PL_diehook = 0;
2157 SvREFCNT_dec (old);
1986 croak ("\3async_pool terminate\2\n"); 2158 croak ("\3async_pool terminate\2\n");
1987 } 2159 }
1988 2160
1989 SvREFCNT_dec (coro->saved_deffh); 2161 SvREFCNT_dec (coro->saved_deffh);
1990 coro->saved_deffh = SvREFCNT_inc ((SV *)PL_defoutgv); 2162 coro->saved_deffh = SvREFCNT_inc_NN ((SV *)PL_defoutgv);
1991 2163
1992 hv_store (hv, "desc", sizeof ("desc") - 1, 2164 hv_store (hv, "desc", sizeof ("desc") - 1,
1993 newSVpvn ("[async_pool]", sizeof ("[async_pool]") - 1), 0); 2165 newSVpvn ("[async_pool]", sizeof ("[async_pool]") - 1), 0);
1994 2166
1995 invoke_av = (AV *)SvRV (invoke); 2167 invoke_av = (AV *)SvRV (invoke);
1999 2171
2000 if (len > 0) 2172 if (len > 0)
2001 { 2173 {
2002 av_fill (defav, len - 1); 2174 av_fill (defav, len - 1);
2003 for (i = 0; i < len; ++i) 2175 for (i = 0; i < len; ++i)
2004 av_store (defav, i, SvREFCNT_inc (AvARRAY (invoke_av)[i + 1])); 2176 av_store (defav, i, SvREFCNT_inc_NN (AvARRAY (invoke_av)[i + 1]));
2005 } 2177 }
2006 2178
2007 SvREFCNT_dec (invoke); 2179 SvREFCNT_dec (invoke);
2008} 2180}
2009 2181
2019 coro->saved_deffh = 0; 2191 coro->saved_deffh = 0;
2020 2192
2021 if (coro_rss (aTHX_ coro) > SvIV (sv_pool_rss) 2193 if (coro_rss (aTHX_ coro) > SvIV (sv_pool_rss)
2022 || av_len (av_async_pool) + 1 >= SvIV (sv_pool_size)) 2194 || av_len (av_async_pool) + 1 >= SvIV (sv_pool_size))
2023 { 2195 {
2024 SvREFCNT_dec (PL_diehook); PL_diehook = 0; 2196 SV *old = PL_diehook;
2197 PL_diehook = 0;
2198 SvREFCNT_dec (old);
2025 croak ("\3async_pool terminate\2\n"); 2199 croak ("\3async_pool terminate\2\n");
2026 } 2200 }
2027 2201
2028 av_clear (GvAV (PL_defgv)); 2202 av_clear (GvAV (PL_defgv));
2029 hv_store ((HV *)SvRV (coro_current), "desc", sizeof ("desc") - 1, 2203 hv_store ((HV *)SvRV (coro_current), "desc", sizeof ("desc") - 1,
2035 api_trace (coro_current, 0); 2209 api_trace (coro_current, 0);
2036 2210
2037 av_push (av_async_pool, newSVsv (coro_current)); 2211 av_push (av_async_pool, newSVsv (coro_current));
2038} 2212}
2039 2213
2214#if 0
2215
2216void
2217_generator_call (...)
2218 PROTOTYPE: @
2219 PPCODE:
2220 fprintf (stderr, "call %p\n", CvXSUBANY(cv).any_ptr);
2221 xxxx
2222 abort ();
2223
2224SV *
2225gensub (SV *sub, ...)
2226 PROTOTYPE: &;@
2227 CODE:
2228{
2229 struct coro *coro;
2230 MAGIC *mg;
2231 CV *xcv;
2232 CV *ncv = (CV *)newSV_type (SVt_PVCV);
2233 int i;
2234
2235 CvGV (ncv) = CvGV (cv);
2236 CvFILE (ncv) = CvFILE (cv);
2237
2238 Newz (0, coro, 1, struct coro);
2239 coro->args = newAV ();
2240 coro->flags = CF_NEW;
2241
2242 av_extend (coro->args, items - 1);
2243 for (i = 1; i < items; i++)
2244 av_push (coro->args, newSVsv (ST (i)));
2245
2246 CvISXSUB_on (ncv);
2247 CvXSUBANY (ncv).any_ptr = (void *)coro;
2248
2249 xcv = GvCV (gv_fetchpv ("Coro::_generator_call", 0, SVt_PVCV));
2250
2251 CvXSUB (ncv) = CvXSUB (xcv);
2252 CvANON_on (ncv);
2253
2254 mg = sv_magicext ((SV *)ncv, 0, CORO_MAGIC_type_state, &coro_gensub_vtbl, (char *)coro, 0);
2255 RETVAL = newRV_noinc ((SV *)ncv);
2256}
2257 OUTPUT:
2258 RETVAL
2259
2260#endif
2261
2040 2262
2041MODULE = Coro::State PACKAGE = Coro::AIO 2263MODULE = Coro::State PACKAGE = Coro::AIO
2042 2264
2043SV * 2265void
2044_get_state () 2266_get_state (SV *self)
2045 CODE: 2267 PPCODE:
2046{ 2268{
2047 struct io_state *data; 2269 AV *defav = GvAV (PL_defgv);
2048 2270 AV *av = newAV ();
2271 int i;
2049 RETVAL = newSV (sizeof (struct io_state)); 2272 SV *data_sv = newSV (sizeof (struct io_state));
2050 data = (struct io_state *)SvPVX (RETVAL); 2273 struct io_state *data = (struct io_state *)SvPVX (data_sv);
2051 SvCUR_set (RETVAL, sizeof (struct io_state)); 2274 SvCUR_set (data_sv, sizeof (struct io_state));
2052 SvPOK_only (RETVAL); 2275 SvPOK_only (data_sv);
2053 2276
2054 data->errorno = errno; 2277 data->errorno = errno;
2055 data->laststype = PL_laststype; 2278 data->laststype = PL_laststype;
2056 data->laststatval = PL_laststatval; 2279 data->laststatval = PL_laststatval;
2057 data->statcache = PL_statcache; 2280 data->statcache = PL_statcache;
2281
2282 av_extend (av, AvFILLp (defav) + 1 + 1);
2283
2284 for (i = 0; i <= AvFILLp (defav); ++i)
2285 av_push (av, SvREFCNT_inc_NN (AvARRAY (defav)[i]));
2286
2287 av_push (av, data_sv);
2288
2289 XPUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2290
2291 api_ready (self);
2058} 2292}
2059 OUTPUT:
2060 RETVAL
2061 2293
2062void 2294void
2063_set_state (char *data_) 2295_set_state (SV *state)
2064 PROTOTYPE: $ 2296 PROTOTYPE: $
2065 CODE: 2297 PPCODE:
2066{ 2298{
2067 struct io_state *data = (void *)data_; 2299 AV *av = (AV *)SvRV (state);
2300 struct io_state *data = (struct io_state *)SvPVX (AvARRAY (av)[AvFILLp (av)]);
2301 int i;
2068 2302
2069 errno = data->errorno; 2303 errno = data->errorno;
2070 PL_laststype = data->laststype; 2304 PL_laststype = data->laststype;
2071 PL_laststatval = data->laststatval; 2305 PL_laststatval = data->laststatval;
2072 PL_statcache = data->statcache; 2306 PL_statcache = data->statcache;
2307
2308 EXTEND (SP, AvFILLp (av));
2309 for (i = 0; i < AvFILLp (av); ++i)
2310 PUSHs (sv_2mortal (SvREFCNT_inc_NN (AvARRAY (av)[i])));
2073} 2311}
2074 2312
2075 2313
2076MODULE = Coro::State PACKAGE = Coro::AnyEvent 2314MODULE = Coro::State PACKAGE = Coro::AnyEvent
2077 2315
2078BOOT: 2316BOOT:
2079 sv_activity = coro_get_sv (aTHX_ "Coro::AnyEvent::ACTIVITY", TRUE); 2317 sv_activity = coro_get_sv (aTHX_ "Coro::AnyEvent::ACTIVITY", TRUE);
2080 2318
2081SV * 2319SV *
2082_schedule () 2320_schedule (...)
2083 PROTOTYPE: @ 2321 PROTOTYPE: @
2084 CODE: 2322 CODE:
2085{ 2323{
2086 static int incede; 2324 static int incede;
2087 2325
2101 } 2339 }
2102 2340
2103 --incede; 2341 --incede;
2104} 2342}
2105 2343
2344
2345MODULE = Coro::State PACKAGE = PerlIO::cede
2346
2347BOOT:
2348 PerlIO_define_layer (aTHX_ &PerlIO_cede);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines