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.211 by root, Wed Oct 10 03:37:58 2007 UTC vs.
Revision 1.217 by root, Wed Nov 14 11:32:56 2007 UTC

131#else 131#else
132# define LOCK (void)0 132# define LOCK (void)0
133# define UNLOCK (void)0 133# define UNLOCK (void)0
134#endif 134#endif
135 135
136#define strpair(const) const, sizeof (const) - 1
137
138/* helper storage struct for Coro::AIO */ 136/* helper storage struct for Coro::AIO */
139struct io_state 137struct io_state
140{ 138{
141 int errorno; 139 int errorno;
142 I32 laststype; 140 I32 laststype;
147static size_t coro_stacksize = CORO_STACKSIZE; 145static size_t coro_stacksize = CORO_STACKSIZE;
148static struct CoroAPI coroapi; 146static struct CoroAPI coroapi;
149static AV *main_mainstack; /* used to differentiate between $main and others */ 147static AV *main_mainstack; /* used to differentiate between $main and others */
150static JMPENV *main_top_env; 148static JMPENV *main_top_env;
151static HV *coro_state_stash, *coro_stash; 149static HV *coro_state_stash, *coro_stash;
152static SV *coro_mortal; /* will be freed after next transfer */ 150static volatile SV *coro_mortal; /* will be freed after next transfer */
153 151
154static GV *irsgv; /* $/ */ 152static GV *irsgv; /* $/ */
155static GV *stdoutgv; /* *STDOUT */ 153static GV *stdoutgv; /* *STDOUT */
156 154static SV *rv_diehook;
155static SV *rv_warnhook;
157static HV *hv_sig; /* %SIG */ 156static HV *hv_sig; /* %SIG */
158static SV *sv_diehook;
159static SV *sv_warnhook;
160 157
161/* async_pool helper stuff */ 158/* async_pool helper stuff */
162static SV *sv_pool_rss; 159static SV *sv_pool_rss;
163static SV *sv_pool_size; 160static SV *sv_pool_size;
164static AV *av_async_pool; 161static AV *av_async_pool;
262static struct coro *coro_first; 259static struct coro *coro_first;
263 260
264/** lowlevel stuff **********************************************************/ 261/** lowlevel stuff **********************************************************/
265 262
266static SV * 263static SV *
267coro_get_sv (const char *name, int create) 264coro_get_sv (pTHX_ const char *name, int create)
268{ 265{
269#if PERL_VERSION_ATLEAST (5,9,0) 266#if PERL_VERSION_ATLEAST (5,9,0)
270 /* silence stupid and wrong 5.10 warning that I am unable to switch off */ 267 /* silence stupid and wrong 5.10 warning that I am unable to switch off */
271 get_sv (name, create); 268 get_sv (name, create);
272#endif 269#endif
273 return get_sv (name, create); 270 return get_sv (name, create);
274} 271}
275 272
276static AV * 273static AV *
277coro_get_av (const char *name, int create) 274coro_get_av (pTHX_ const char *name, int create)
278{ 275{
279#if PERL_VERSION_ATLEAST (5,9,0) 276#if PERL_VERSION_ATLEAST (5,9,0)
280 /* silence stupid and wrong 5.10 warning that I am unable to switch off */ 277 /* silence stupid and wrong 5.10 warning that I am unable to switch off */
281 get_av (name, create); 278 get_av (name, create);
282#endif 279#endif
283 return get_av (name, create); 280 return get_av (name, create);
284} 281}
285 282
286static HV * 283static HV *
287coro_get_hv (const char *name, int create) 284coro_get_hv (pTHX_ const char *name, int create)
288{ 285{
289#if PERL_VERSION_ATLEAST (5,9,0) 286#if PERL_VERSION_ATLEAST (5,9,0)
290 /* silence stupid and wrong 5.10 warning that I am unable to switch off */ 287 /* silence stupid and wrong 5.10 warning that I am unable to switch off */
291 get_hv (name, create); 288 get_hv (name, create);
292#endif 289#endif
347 344
348 /* casting is fun. */ 345 /* casting is fun. */
349 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av))) 346 while (&PL_sv_undef != (SV *)(padlist = (AV *)av_pop (av)))
350 free_padlist (aTHX_ padlist); 347 free_padlist (aTHX_ padlist);
351 348
352 SvREFCNT_dec (av);
353
354 return 0; 349 return 0;
355} 350}
356 351
357#define PERL_MAGIC_coro PERL_MAGIC_ext 352#define CORO_MAGIC_type_cv PERL_MAGIC_ext
353#define CORO_MAGIC_type_state PERL_MAGIC_ext
358 354
359static MGVTBL vtbl_coro = {0, 0, 0, 0, coro_cv_free}; 355static MGVTBL coro_cv_vtbl = {
356 0, 0, 0, 0,
357 coro_cv_free
358};
360 359
361#define CORO_MAGIC(cv) \ 360#define CORO_MAGIC(sv,type) \
362 SvMAGIC (cv) \ 361 SvMAGIC (sv) \
363 ? SvMAGIC (cv)->mg_type == PERL_MAGIC_coro \ 362 ? SvMAGIC (sv)->mg_type == type \
364 ? SvMAGIC (cv) \ 363 ? SvMAGIC (sv) \
365 : mg_find ((SV *)cv, PERL_MAGIC_coro) \ 364 : mg_find (sv, type) \
366 : 0 365 : 0
366
367#define CORO_MAGIC_cv(cv) CORO_MAGIC (((SV *)(cv)), CORO_MAGIC_type_cv)
368#define CORO_MAGIC_state(sv) CORO_MAGIC (((SV *)(sv)), CORO_MAGIC_type_state)
367 369
368static struct coro * 370static struct coro *
369SvSTATE_ (pTHX_ SV *coro) 371SvSTATE_ (pTHX_ SV *coro)
370{ 372{
371 HV *stash; 373 HV *stash;
383 /* very slow, but rare, check */ 385 /* very slow, but rare, check */
384 if (!sv_derived_from (sv_2mortal (newRV_inc (coro)), "Coro::State")) 386 if (!sv_derived_from (sv_2mortal (newRV_inc (coro)), "Coro::State"))
385 croak ("Coro::State object required"); 387 croak ("Coro::State object required");
386 } 388 }
387 389
388 mg = CORO_MAGIC (coro); 390 mg = CORO_MAGIC_state (coro);
389 return (struct coro *)mg->mg_ptr; 391 return (struct coro *)mg->mg_ptr;
390} 392}
391 393
392#define SvSTATE(sv) SvSTATE_ (aTHX_ (sv)) 394#define SvSTATE(sv) SvSTATE_ (aTHX_ (sv))
393 395
394/* the next two functions merely cache the padlists */ 396/* the next two functions merely cache the padlists */
395static void 397static void
396get_padlist (pTHX_ CV *cv) 398get_padlist (pTHX_ CV *cv)
397{ 399{
398 MAGIC *mg = CORO_MAGIC (cv); 400 MAGIC *mg = CORO_MAGIC_cv (cv);
399 AV *av; 401 AV *av;
400 402
401 if (expect_true (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0)) 403 if (expect_true (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0))
402 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; 404 CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--];
403 else 405 else
415} 417}
416 418
417static void 419static void
418put_padlist (pTHX_ CV *cv) 420put_padlist (pTHX_ CV *cv)
419{ 421{
420 MAGIC *mg = CORO_MAGIC (cv); 422 MAGIC *mg = CORO_MAGIC_cv (cv);
421 AV *av; 423 AV *av;
422 424
423 if (expect_false (!mg)) 425 if (expect_false (!mg))
424 { 426 mg = sv_magicext ((SV *)cv, (SV *)newAV (), CORO_MAGIC_type_cv, &coro_cv_vtbl, 0, 0);
425 sv_magic ((SV *)cv, 0, PERL_MAGIC_coro, 0, 0);
426 mg = mg_find ((SV *)cv, PERL_MAGIC_coro);
427 mg->mg_virtual = &vtbl_coro;
428 mg->mg_obj = (SV *)newAV ();
429 }
430 427
431 av = (AV *)mg->mg_obj; 428 av = (AV *)mg->mg_obj;
432 429
433 if (expect_false (AvFILLp (av) >= AvMAX (av))) 430 if (expect_false (AvFILLp (av) >= AvMAX (av)))
434 av_extend (av, AvMAX (av) + 1); 431 av_extend (av, AvMAX (av) + 1);
452 GvSV (irsgv) = slot->irsgv; 449 GvSV (irsgv) = slot->irsgv;
453 450
454 #define VAR(name,type) PL_ ## name = slot->name; 451 #define VAR(name,type) PL_ ## name = slot->name;
455 # include "state.h" 452 # include "state.h"
456 #undef VAR 453 #undef VAR
457
458 /*hv_store (hv_sig, strpair ("__DIE__" ), SvREFCNT_inc (sv_diehook ), 0);*/
459 /*hv_store (hv_sig, strpair ("__WARN__"), SvREFCNT_inc (sv_warnhook), 0);*/
460 454
461 { 455 {
462 dSP; 456 dSP;
463 457
464 CV *cv; 458 CV *cv;
670 return rss; 664 return rss;
671} 665}
672 666
673/** coroutine stack handling ************************************************/ 667/** coroutine stack handling ************************************************/
674 668
669#if 0
670static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg);
671
672/*
673 * This overrides the default magic get method of %SIG elements.
674 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook
675 * and instead of tryign to save and restore the hash elements, we just provide
676 * readback here.
677 * We only do this when the hook is != 0, as they are often set to 0 temporarily,
678 * not expecting this to actually change the hook. This is a potential problem
679 * when a schedule happens then, but we ignore this.
680 */
681static int
682coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg)
683{
684 return orig_sigelem_get (aTHX_ sv, mg);
685 const char *s = MgPV_nolen_const (mg);
686
687 if (*s == '_')
688 {
689 if (strEQ (s, "__DIE__" ) && PL_diehook ) return sv_setsv (sv, PL_diehook ), 0;
690 if (strEQ (s, "__WARN__") && PL_warnhook) return sv_setsv (sv, PL_warnhook), 0;
691 }
692
693 return orig_sigelem_get (aTHX_ sv, mg);
694}
695#endif
696
675static void 697static void
676coro_setup (pTHX_ struct coro *coro) 698coro_setup (pTHX_ struct coro *coro)
677{ 699{
678 /* 700 /*
679 * emulate part of the perl startup here. 701 * emulate part of the perl startup here.
687 PL_curpm = 0; 709 PL_curpm = 0;
688 PL_curpad = 0; 710 PL_curpad = 0;
689 PL_localizing = 0; 711 PL_localizing = 0;
690 PL_dirty = 0; 712 PL_dirty = 0;
691 PL_restartop = 0; 713 PL_restartop = 0;
692 PL_diehook = 0; hv_store (hv_sig, strpair ("__DIE__" ), SvREFCNT_inc (sv_diehook ), 0); 714
693 PL_warnhook = 0; hv_store (hv_sig, strpair ("__WARN__"), SvREFCNT_inc (sv_warnhook), 0); 715 /* recreate the die/warn hooks */
716 PL_diehook = 0;
717 hv_store (hv_sig, "__DIE__", sizeof ("__DIE__") - 1, newSV (0), 0);
718 PL_diehook = SvREFCNT_inc (rv_diehook);
719
720 PL_warnhook = 0;
721 hv_store (hv_sig, "__WARN__", sizeof ("__WARN__") - 1, newSV (0), 0);
722 PL_warnhook = SvREFCNT_inc (rv_warnhook);
694 723
695 GvSV (PL_defgv) = newSV (0); 724 GvSV (PL_defgv) = newSV (0);
696 GvAV (PL_defgv) = coro->args; coro->args = 0; 725 GvAV (PL_defgv) = coro->args; coro->args = 0;
697 GvSV (PL_errgv) = newSV (0); 726 GvSV (PL_errgv) = newSV (0);
698 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 727 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
812 PUSHMARK (SP); 841 PUSHMARK (SP);
813 PUSHs (&PL_sv_no); 842 PUSHs (&PL_sv_no);
814 PUSHs (fullname); 843 PUSHs (fullname);
815 PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); 844 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
816 PUTBACK; 845 PUTBACK;
817 cb = hv_fetch ((HV *)SvRV (coro_current), strpair ("_trace_sub_cb"), 0); 846 cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0);
818 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 847 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
819 SPAGAIN; 848 SPAGAIN;
820 FREETMPS; 849 FREETMPS;
821 LEAVE; 850 LEAVE;
822 PL_runops = runops_trace; 851 PL_runops = runops_trace;
851 PUSHMARK (SP); 880 PUSHMARK (SP);
852 PUSHs (&PL_sv_yes); 881 PUSHs (&PL_sv_yes);
853 PUSHs (fullname); 882 PUSHs (fullname);
854 PUSHs (cx->blk_sub.hasargs ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); 883 PUSHs (cx->blk_sub.hasargs ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef);
855 PUTBACK; 884 PUTBACK;
856 cb = hv_fetch ((HV *)SvRV (coro_current), strpair ("_trace_sub_cb"), 0); 885 cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0);
857 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 886 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
858 SPAGAIN; 887 SPAGAIN;
859 FREETMPS; 888 FREETMPS;
860 LEAVE; 889 LEAVE;
861 PL_runops = runops_trace; 890 PL_runops = runops_trace;
875 PL_runops = RUNOPS_DEFAULT; 904 PL_runops = RUNOPS_DEFAULT;
876 PUSHMARK (SP); 905 PUSHMARK (SP);
877 PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); 906 PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0)));
878 PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); 907 PUSHs (sv_2mortal (newSViv (CopLINE (oldcop))));
879 PUTBACK; 908 PUTBACK;
880 cb = hv_fetch ((HV *)SvRV (coro_current), strpair ("_trace_line_cb"), 0); 909 cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0);
881 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 910 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
882 SPAGAIN; 911 SPAGAIN;
883 FREETMPS; 912 FREETMPS;
884 LEAVE; 913 LEAVE;
885 PL_runops = runops_trace; 914 PL_runops = runops_trace;
1091/* always use the TRANSFER macro */ 1120/* always use the TRANSFER macro */
1092static void NOINLINE 1121static void NOINLINE
1093transfer (pTHX_ struct coro *prev, struct coro *next) 1122transfer (pTHX_ struct coro *prev, struct coro *next)
1094{ 1123{
1095 dSTACKLEVEL; 1124 dSTACKLEVEL;
1125 static volatile int has_throw;
1096 1126
1097 /* sometimes transfer is only called to set idle_sp */ 1127 /* sometimes transfer is only called to set idle_sp */
1098 if (expect_false (!next)) 1128 if (expect_false (!next))
1099 { 1129 {
1100 ((coro_cctx *)prev)->idle_sp = STACKLEVEL; 1130 ((coro_cctx *)prev)->idle_sp = STACKLEVEL;
1115 prev->flags &= ~CF_RUNNING; 1145 prev->flags &= ~CF_RUNNING;
1116 next->flags |= CF_RUNNING; 1146 next->flags |= CF_RUNNING;
1117 1147
1118 LOCK; 1148 LOCK;
1119 1149
1150 /* first get rid of the old state */
1151 save_perl (aTHX_ prev);
1152
1120 if (expect_false (next->flags & CF_NEW)) 1153 if (expect_false (next->flags & CF_NEW))
1121 { 1154 {
1122 /* need to start coroutine */ 1155 /* need to start coroutine */
1123 next->flags &= ~CF_NEW; 1156 next->flags &= ~CF_NEW;
1124 /* first get rid of the old state */
1125 save_perl (aTHX_ prev);
1126 /* setup coroutine call */ 1157 /* setup coroutine call */
1127 coro_setup (aTHX_ next); 1158 coro_setup (aTHX_ next);
1128 } 1159 }
1129 else 1160 else
1130 {
1131 /* coroutine already started */
1132 save_perl (aTHX_ prev);
1133 load_perl (aTHX_ next); 1161 load_perl (aTHX_ next);
1134 }
1135 1162
1136 prev__cctx = prev->cctx; 1163 prev__cctx = prev->cctx;
1137 1164
1138 /* possibly "free" the cctx */ 1165 /* possibly "free" the cctx */
1139 if (expect_true (prev__cctx->idle_sp == STACKLEVEL && !(prev__cctx->flags & CC_TRACE))) 1166 if (expect_true (prev__cctx->idle_sp == STACKLEVEL && !(prev__cctx->flags & CC_TRACE)))
1154 1181
1155 ++next->usecount; 1182 ++next->usecount;
1156 1183
1157 if (expect_true (!next->cctx)) 1184 if (expect_true (!next->cctx))
1158 next->cctx = cctx_get (aTHX); 1185 next->cctx = cctx_get (aTHX);
1186
1187 has_throw = !!next->throw;
1159 1188
1160 if (expect_false (prev__cctx != next->cctx)) 1189 if (expect_false (prev__cctx != next->cctx))
1161 { 1190 {
1162 prev__cctx->top_env = PL_top_env; 1191 prev__cctx->top_env = PL_top_env;
1163 PL_top_env = next->cctx->top_env; 1192 PL_top_env = next->cctx->top_env;
1165 } 1194 }
1166 1195
1167 free_coro_mortal (aTHX); 1196 free_coro_mortal (aTHX);
1168 UNLOCK; 1197 UNLOCK;
1169 1198
1170 if (expect_false (prev->throw || next->throw)) 1199 if (expect_false (has_throw))
1171 { 1200 {
1172 struct coro *coro = SvSTATE (coro_current); 1201 struct coro *coro = SvSTATE (coro_current);
1173 1202
1174 if (coro->throw) 1203 if (coro->throw)
1175 { 1204 {
1507#endif 1536#endif
1508 BOOT_PAGESIZE; 1537 BOOT_PAGESIZE;
1509 1538
1510 irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); 1539 irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV);
1511 stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); 1540 stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO);
1512 1541#if 0
1542 orig_sigelem_get = PL_vtbl_sigelem.svt_get;
1543 PL_vtbl_sigelem.svt_get = coro_sigelem_get;
1544#endif
1513 hv_sig = coro_get_hv ("SIG", TRUE); 1545 hv_sig = coro_get_hv (aTHX_ "SIG", TRUE);
1514 sv_diehook = coro_get_sv ("Coro::State::DIEHOOK" , TRUE); 1546 rv_diehook = SvREFCNT_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV));
1515 sv_warnhook = coro_get_sv ("Coro::State::WARNHOOK", TRUE); 1547 rv_warnhook = SvREFCNT_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV));
1516
1517 if (!PL_diehook ) hv_store (hv_sig, strpair ("__DIE__" ), SvREFCNT_inc (sv_diehook ), 0);
1518 if (!PL_warnhook) hv_store (hv_sig, strpair ("__WARN__"), SvREFCNT_inc (sv_warnhook), 0);
1519 1548
1520 coro_state_stash = gv_stashpv ("Coro::State", TRUE); 1549 coro_state_stash = gv_stashpv ("Coro::State", TRUE);
1521 1550
1522 newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); 1551 newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE));
1523 newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); 1552 newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB));
1540SV * 1569SV *
1541new (char *klass, ...) 1570new (char *klass, ...)
1542 CODE: 1571 CODE:
1543{ 1572{
1544 struct coro *coro; 1573 struct coro *coro;
1574 MAGIC *mg;
1545 HV *hv; 1575 HV *hv;
1546 int i; 1576 int i;
1547 1577
1548 Newz (0, coro, 1, struct coro); 1578 Newz (0, coro, 1, struct coro);
1549 coro->args = newAV (); 1579 coro->args = newAV ();
1552 if (coro_first) coro_first->prev = coro; 1582 if (coro_first) coro_first->prev = coro;
1553 coro->next = coro_first; 1583 coro->next = coro_first;
1554 coro_first = coro; 1584 coro_first = coro;
1555 1585
1556 coro->hv = hv = newHV (); 1586 coro->hv = hv = newHV ();
1557 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP; 1587 mg = sv_magicext ((SV *)hv, 0, CORO_MAGIC_type_state, &coro_state_vtbl, (char *)coro, 0);
1588 mg->mg_flags |= MGf_DUP;
1558 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 1589 RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
1559 1590
1560 av_extend (coro->args, items - 1); 1591 av_extend (coro->args, items - 1);
1561 for (i = 1; i < items; i++) 1592 for (i = 1; i < items; i++)
1562 av_push (coro->args, newSVsv (ST (i))); 1593 av_push (coro->args, newSVsv (ST (i)));
1756 1787
1757BOOT: 1788BOOT:
1758{ 1789{
1759 int i; 1790 int i;
1760 1791
1761 sv_pool_rss = coro_get_sv ("Coro::POOL_RSS" , TRUE); 1792 sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE);
1762 sv_pool_size = coro_get_sv ("Coro::POOL_SIZE" , TRUE); 1793 sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE);
1763 av_async_pool = coro_get_av ("Coro::async_pool", TRUE); 1794 av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE);
1764 1795
1765 coro_current = coro_get_sv ("Coro::current", FALSE); 1796 coro_current = coro_get_sv (aTHX_ "Coro::current", FALSE);
1766 SvREADONLY_on (coro_current); 1797 SvREADONLY_on (coro_current);
1767 1798
1768 coro_stash = gv_stashpv ("Coro", TRUE); 1799 coro_stash = gv_stashpv ("Coro", TRUE);
1769 1800
1770 newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (PRIO_MAX)); 1801 newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (PRIO_MAX));
1853 CODE: 1884 CODE:
1854{ 1885{
1855 struct coro *coro = SvSTATE (coro_current); 1886 struct coro *coro = SvSTATE (coro_current);
1856 HV *hv = (HV *)SvRV (coro_current); 1887 HV *hv = (HV *)SvRV (coro_current);
1857 AV *defav = GvAV (PL_defgv); 1888 AV *defav = GvAV (PL_defgv);
1858 SV *invoke = hv_delete (hv, strpair ("_invoke"), 0); 1889 SV *invoke = hv_delete (hv, "_invoke", sizeof ("_invoke") - 1, 0);
1859 AV *invoke_av; 1890 AV *invoke_av;
1860 int i, len; 1891 int i, len;
1861 1892
1862 if (!invoke) 1893 if (!invoke)
1863 croak ("\3async_pool terminate\2\n"); 1894 croak ("\3async_pool terminate\2\n");
1864 1895
1865 SvREFCNT_dec (coro->saved_deffh); 1896 SvREFCNT_dec (coro->saved_deffh);
1866 coro->saved_deffh = SvREFCNT_inc ((SV *)PL_defoutgv); 1897 coro->saved_deffh = SvREFCNT_inc ((SV *)PL_defoutgv);
1867 1898
1868 hv_store (hv, "desc", sizeof ("desc") - 1, 1899 hv_store (hv, "desc", sizeof ("desc") - 1,
1869 newSVpvn (strpair ("[async_pool]")), 0); 1900 newSVpvn ("[async_pool]", sizeof ("[async_pool]") - 1), 0);
1870 1901
1871 invoke_av = (AV *)SvRV (invoke); 1902 invoke_av = (AV *)SvRV (invoke);
1872 len = av_len (invoke_av); 1903 len = av_len (invoke_av);
1873 1904
1874 sv_setsv (cb, AvARRAY (invoke_av)[0]); 1905 sv_setsv (cb, AvARRAY (invoke_av)[0]);
1897 if (coro_rss (aTHX_ coro) > SvIV (sv_pool_rss) 1928 if (coro_rss (aTHX_ coro) > SvIV (sv_pool_rss)
1898 || av_len (av_async_pool) + 1 >= SvIV (sv_pool_size)) 1929 || av_len (av_async_pool) + 1 >= SvIV (sv_pool_size))
1899 croak ("\3async_pool terminate\2\n"); 1930 croak ("\3async_pool terminate\2\n");
1900 1931
1901 av_clear (GvAV (PL_defgv)); 1932 av_clear (GvAV (PL_defgv));
1902 hv_store ((HV *)SvRV (coro_current), strpair ("desc"), 1933 hv_store ((HV *)SvRV (coro_current), "desc", sizeof ("desc") - 1,
1903 newSVpvn (strpair ("[async_pool idle]")), 0); 1934 newSVpvn ("[async_pool idle]", sizeof ("[async_pool idle]") - 1), 0);
1904 1935
1905 coro->prio = 0; 1936 coro->prio = 0;
1906 1937
1907 if (coro->cctx && (coro->cctx->flags & CC_TRACE)) 1938 if (coro->cctx && (coro->cctx->flags & CC_TRACE))
1908 api_trace (coro_current, 0); 1939 api_trace (coro_current, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines