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.197 by root, Sat Oct 6 19:25:00 2007 UTC vs.
Revision 1.200 by root, Sun Oct 7 15:08:23 2007 UTC

1#include "libcoro/coro.c" 1#include "libcoro/coro.c"
2 2
3#define PERL_NO_GET_CONTEXT 3#define PERL_NO_GET_CONTEXT
4#define PERL_EXT
4 5
5#include "EXTERN.h" 6#include "EXTERN.h"
6#include "perl.h" 7#include "perl.h"
7#include "XSUB.h" 8#include "XSUB.h"
8 9
129#else 130#else
130# define LOCK (void)0 131# define LOCK (void)0
131# define UNLOCK (void)0 132# define UNLOCK (void)0
132#endif 133#endif
133 134
135#define strpair(const) const, sizeof (const) - 1
136
134/* helper storage struct for Coro::AIO */ 137/* helper storage struct for Coro::AIO */
135struct io_state 138struct io_state
136{ 139{
137 int errorno; 140 int errorno;
138 I32 laststype; 141 I32 laststype;
147static HV *coro_state_stash, *coro_stash; 150static HV *coro_state_stash, *coro_stash;
148static SV *coro_mortal; /* will be freed after next transfer */ 151static SV *coro_mortal; /* will be freed after next transfer */
149 152
150static GV *irsgv; /* $/ */ 153static GV *irsgv; /* $/ */
151static GV *stdoutgv; /* *STDOUT */ 154static GV *stdoutgv; /* *STDOUT */
155
156static HV *hv_sig; /* %SIG */
157static SV *sv_diehook;
158static SV *sv_warnhook;
152 159
153/* async_pool helper stuff */ 160/* async_pool helper stuff */
154static SV *sv_pool_rss; 161static SV *sv_pool_rss;
155static SV *sv_pool_size; 162static SV *sv_pool_size;
156static AV *av_async_pool; 163static AV *av_async_pool;
192 CF_READY = 0x0002, /* coroutine is ready */ 199 CF_READY = 0x0002, /* coroutine is ready */
193 CF_NEW = 0x0004, /* has never been switched to */ 200 CF_NEW = 0x0004, /* has never been switched to */
194 CF_DESTROYED = 0x0008, /* coroutine data has been freed */ 201 CF_DESTROYED = 0x0008, /* coroutine data has been freed */
195}; 202};
196 203
204/* the structure where most of the perl state is stored, overlaid on the cxstack */
205typedef struct {
206 SV *defsv;
207 AV *defav;
208 SV *errsv;
209 SV *irsgv;
210#define VAR(name,type) type name;
211# include "state.h"
212#undef VAR
213} perl_slots;
214
215#define SLOT_COUNT ((sizeof (perl_slots) + sizeof (PERL_CONTEXT) - 1) / sizeof (PERL_CONTEXT))
216
197/* this is a structure representing a perl-level coroutine */ 217/* this is a structure representing a perl-level coroutine */
198struct coro { 218struct coro {
199 /* the c coroutine allocated to this perl coroutine, if any */ 219 /* the c coroutine allocated to this perl coroutine, if any */
200 coro_cctx *cctx; 220 coro_cctx *cctx;
201 221
222 /* process data */
223 AV *mainstack;
224 perl_slots *slot; /* basically the saved sp */
225
202 /* data associated with this coroutine (initial args) */ 226 /* data associated with this coroutine (initial args) */
203 AV *args; 227 AV *args;
204 int refcnt; 228 int refcnt;
205 int flags; /* CF_ flags */ 229 int flags; /* CF_ flags */
206
207 /* optionally saved, might be zero */
208 AV *defav; /* @_ */
209 SV *defsv; /* $_ */
210 SV *errsv; /* $@ */
211 SV *deffh; /* default filehandle */
212 SV *irssv; /* $/ */
213 SV *irssv_sv; /* real $/ cache */
214
215#define VAR(name,type) type name;
216# include "state.h"
217#undef VAR
218 230
219 /* statistics */ 231 /* statistics */
220 int usecount; /* number of transfers to this coro */ 232 int usecount; /* number of transfers to this coro */
221 233
222 /* coro process data */ 234 /* coro process data */
248static AV *coro_ready [PRIO_MAX-PRIO_MIN+1]; 260static AV *coro_ready [PRIO_MAX-PRIO_MIN+1];
249static int coro_nready; 261static int coro_nready;
250static struct coro *coro_first; 262static struct coro *coro_first;
251 263
252/** lowlevel stuff **********************************************************/ 264/** lowlevel stuff **********************************************************/
265
266static SV *
267coro_get_sv (const char *name, int create)
268{
269#if PERL_VERSION_ATLEAST (5,9,0)
270 /* silence stupid and wrong 5.10 warning that I am unable to switch off */
271 get_sv (name, create);
272#endif
273 return get_sv (name, create);
274}
275
276static AV *
277coro_get_av (const char *name, int create)
278{
279#if PERL_VERSION_ATLEAST (5,9,0)
280 /* silence stupid and wrong 5.10 warning that I am unable to switch off */
281 get_av (name, create);
282#endif
283 return get_av (name, create);
284}
285
286static HV *
287coro_get_hv (const char *name, int create)
288{
289#if PERL_VERSION_ATLEAST (5,9,0)
290 /* silence stupid and wrong 5.10 warning that I am unable to switch off */
291 get_hv (name, create);
292#endif
293 return get_hv (name, create);
294}
253 295
254static AV * 296static AV *
255coro_clone_padlist (pTHX_ CV *cv) 297coro_clone_padlist (pTHX_ CV *cv)
256{ 298{
257 AV *padlist = CvPADLIST (cv); 299 AV *padlist = CvPADLIST (cv);
397/** load & save, init *******************************************************/ 439/** load & save, init *******************************************************/
398 440
399static void 441static void
400load_perl (pTHX_ Coro__State c) 442load_perl (pTHX_ Coro__State c)
401{ 443{
444 perl_slots *slot = c->slot;
445 c->slot = 0;
446
447 PL_mainstack = c->mainstack;
448
449 GvSV (PL_defgv) = slot->defsv;
450 GvAV (PL_defgv) = slot->defav;
451 GvSV (PL_errgv) = slot->errsv;
452 GvSV (irsgv) = slot->irsgv;
453
402#define VAR(name,type) PL_ ## name = c->name; 454 #define VAR(name,type) PL_ ## name = slot->name;
403# include "state.h" 455 # include "state.h"
404#undef VAR 456 #undef VAR
405
406 GvSV (PL_defgv) = c->defsv;
407 GvAV (PL_defgv) = c->defav;
408 GvSV (PL_errgv) = c->errsv;
409 GvSV (irsgv) = c->irssv_sv;
410 457
411 { 458 {
412 dSP; 459 dSP;
460
413 CV *cv; 461 CV *cv;
414 462
415 /* now do the ugly restore mess */ 463 /* now do the ugly restore mess */
416 while (expect_true (cv = (CV *)POPs)) 464 while (expect_true (cv = (CV *)POPs))
417 { 465 {
472 } 520 }
473 521
474 PUTBACK; 522 PUTBACK;
475 } 523 }
476 524
525 /* allocate some space on the context stack for our purposes */
526 {
527 /* we manually unroll here, as usually 2 slots is enough */
528 int i;
529 if (SLOT_COUNT >= 1) CXINC;
530 if (SLOT_COUNT >= 2) CXINC;
531 if (SLOT_COUNT >= 3) CXINC;
532 for (i = 3; i < SLOT_COUNT; ++i)
533 CXINC;
534
535 cxstack_ix -= SLOT_COUNT; /* undo allocation */
536 }
537
538 c->mainstack = PL_mainstack;
539
540 {
541 perl_slots *slot = c->slot = (perl_slots *)(cxstack + cxstack_ix + 1);
542
477 c->defav = GvAV (PL_defgv); 543 slot->defav = GvAV (PL_defgv);
478 c->defsv = DEFSV; 544 slot->defsv = DEFSV;
479 c->errsv = ERRSV; 545 slot->errsv = ERRSV;
480 c->irssv_sv = GvSV (irsgv); 546 slot->irsgv = GvSV (irsgv);
481 547
482#define VAR(name,type)c->name = PL_ ## name; 548 #define VAR(name,type) slot->name = PL_ ## name;
483# include "state.h" 549 # include "state.h"
484#undef VAR 550 #undef VAR
551 }
485} 552}
486 553
487/* 554/*
488 * allocate various perl stacks. This is an exact copy 555 * allocate various perl stacks. This is an exact copy
489 * of perl.c:init_stacks, except that it uses less memory 556 * of perl.c:init_stacks, except that it uses less memory
494# define coro_init_stacks init_stacks 561# define coro_init_stacks init_stacks
495#else 562#else
496static void 563static void
497coro_init_stacks (pTHX) 564coro_init_stacks (pTHX)
498{ 565{
499 PL_curstackinfo = new_stackinfo(64, 6); 566 PL_curstackinfo = new_stackinfo(32, 8);
500 PL_curstackinfo->si_type = PERLSI_MAIN; 567 PL_curstackinfo->si_type = PERLSI_MAIN;
501 PL_curstack = PL_curstackinfo->si_stack; 568 PL_curstack = PL_curstackinfo->si_stack;
502 PL_mainstack = PL_curstack; /* remember in case we switch stacks */ 569 PL_mainstack = PL_curstack; /* remember in case we switch stacks */
503 570
504 PL_stack_base = AvARRAY(PL_curstack); 571 PL_stack_base = AvARRAY(PL_curstack);
505 PL_stack_sp = PL_stack_base; 572 PL_stack_sp = PL_stack_base;
506 PL_stack_max = PL_stack_base + AvMAX(PL_curstack); 573 PL_stack_max = PL_stack_base + AvMAX(PL_curstack);
507 574
508 New(50,PL_tmps_stack,64,SV*); 575 New(50,PL_tmps_stack,32,SV*);
509 PL_tmps_floor = -1; 576 PL_tmps_floor = -1;
510 PL_tmps_ix = -1; 577 PL_tmps_ix = -1;
511 PL_tmps_max = 64; 578 PL_tmps_max = 32;
512 579
513 New(54,PL_markstack,16,I32); 580 New(54,PL_markstack,16,I32);
514 PL_markstack_ptr = PL_markstack; 581 PL_markstack_ptr = PL_markstack;
515 PL_markstack_max = PL_markstack + 16; 582 PL_markstack_max = PL_markstack + 16;
516 583
517#ifdef SET_MARK_OFFSET 584#ifdef SET_MARK_OFFSET
518 SET_MARK_OFFSET; 585 SET_MARK_OFFSET;
519#endif 586#endif
520 587
521 New(54,PL_scopestack,16,I32); 588 New(54,PL_scopestack,8,I32);
522 PL_scopestack_ix = 0; 589 PL_scopestack_ix = 0;
523 PL_scopestack_max = 16; 590 PL_scopestack_max = 8;
524 591
525 New(54,PL_savestack,64,ANY); 592 New(54,PL_savestack,24,ANY);
526 PL_savestack_ix = 0; 593 PL_savestack_ix = 0;
527 PL_savestack_max = 64; 594 PL_savestack_max = 24;
528 595
529#if !PERL_VERSION_ATLEAST (5,9,0) 596#if !PERL_VERSION_ATLEAST (5,9,0)
530 New(54,PL_retstack,4,OP*); 597 New(54,PL_retstack,4,OP*);
531 PL_retstack_ix = 0; 598 PL_retstack_ix = 0;
532 PL_retstack_max = 4; 599 PL_retstack_max = 4;
569{ 636{
570 size_t rss = sizeof (*coro); 637 size_t rss = sizeof (*coro);
571 638
572 if (coro->mainstack) 639 if (coro->mainstack)
573 { 640 {
641 perl_slots tmp_slot;
642 perl_slots *slot;
643
574 if (coro->flags & CF_RUNNING) 644 if (coro->flags & CF_RUNNING)
575 { 645 {
646 slot = &tmp_slot;
647
576 #define VAR(name,type)coro->name = PL_ ## name; 648 #define VAR(name,type) slot->name = PL_ ## name;
577 # include "state.h" 649 # include "state.h"
578 #undef VAR 650 #undef VAR
579 } 651 }
652 else
653 slot = coro->slot;
580 654
581 rss += sizeof (coro->curstackinfo); 655 rss += sizeof (slot->curstackinfo);
582 rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvFILL (coro->curstackinfo->si_stack)) * sizeof (SV *);
583 rss += (coro->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT); 656 rss += (slot->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT);
584 rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvFILL (coro->curstack)) * sizeof (SV *); 657 rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvMAX (slot->curstack)) * sizeof (SV *);
585 rss += coro->tmps_max * sizeof (SV *); 658 rss += slot->tmps_max * sizeof (SV *);
586 rss += (coro->markstack_max - coro->markstack_ptr) * sizeof (I32); 659 rss += (slot->markstack_max - slot->markstack_ptr) * sizeof (I32);
587 rss += coro->scopestack_max * sizeof (I32); 660 rss += slot->scopestack_max * sizeof (I32);
588 rss += coro->savestack_max * sizeof (ANY); 661 rss += slot->savestack_max * sizeof (ANY);
589 662
590#if !PERL_VERSION_ATLEAST (5,9,0) 663#if !PERL_VERSION_ATLEAST (5,9,0)
591 rss += coro->retstack_max * sizeof (OP *); 664 rss += slot->retstack_max * sizeof (OP *);
592#endif 665#endif
593 } 666 }
594 667
595 return rss; 668 return rss;
596} 669}
612 PL_curpm = 0; 685 PL_curpm = 0;
613 PL_curpad = 0; 686 PL_curpad = 0;
614 PL_localizing = 0; 687 PL_localizing = 0;
615 PL_dirty = 0; 688 PL_dirty = 0;
616 PL_restartop = 0; 689 PL_restartop = 0;
690 SvREFCNT_inc (PL_diehook ); hv_store (hv_sig, strpair ("__DIE__" ), SvREFCNT_inc (sv_diehook ), 0);
691 SvREFCNT_inc (PL_warnhook); hv_store (hv_sig, strpair ("__WARN__"), SvREFCNT_inc (sv_warnhook), 0);
617 692
618 GvSV (PL_defgv) = newSV (0); 693 GvSV (PL_defgv) = newSV (0);
619 GvAV (PL_defgv) = coro->args; coro->args = 0; 694 GvAV (PL_defgv) = coro->args; coro->args = 0;
620 GvSV (PL_errgv) = newSV (0); 695 GvSV (PL_errgv) = newSV (0);
621 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); 696 GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0);
666 SvREFCNT_dec (GvSV (PL_errgv)); 741 SvREFCNT_dec (GvSV (PL_errgv));
667 SvREFCNT_dec (PL_defoutgv); 742 SvREFCNT_dec (PL_defoutgv);
668 SvREFCNT_dec (PL_rs); 743 SvREFCNT_dec (PL_rs);
669 SvREFCNT_dec (GvSV (irsgv)); 744 SvREFCNT_dec (GvSV (irsgv));
670 745
746 SvREFCNT_dec (PL_diehook);
747 SvREFCNT_dec (PL_warnhook);
748
671 SvREFCNT_dec (coro->saved_deffh); 749 SvREFCNT_dec (coro->saved_deffh);
672 SvREFCNT_dec (coro->throw); 750 SvREFCNT_dec (coro->throw);
673 751
674 coro_destroy_stacks (aTHX); 752 coro_destroy_stacks (aTHX);
675} 753}
727 PUSHMARK (SP); 805 PUSHMARK (SP);
728 PUSHs (&PL_sv_no); 806 PUSHs (&PL_sv_no);
729 PUSHs (fullname); 807 PUSHs (fullname);
730 PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); 808 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
731 PUTBACK; 809 PUTBACK;
732 cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); 810 cb = hv_fetch ((HV *)SvRV (coro_current), strpair ("_trace_sub_cb"), 0);
733 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 811 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
734 SPAGAIN; 812 SPAGAIN;
735 FREETMPS; 813 FREETMPS;
736 LEAVE; 814 LEAVE;
737 PL_runops = runops_trace; 815 PL_runops = runops_trace;
766 PUSHMARK (SP); 844 PUSHMARK (SP);
767 PUSHs (&PL_sv_yes); 845 PUSHs (&PL_sv_yes);
768 PUSHs (fullname); 846 PUSHs (fullname);
769 PUSHs (cx->blk_sub.hasargs ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); 847 PUSHs (cx->blk_sub.hasargs ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef);
770 PUTBACK; 848 PUTBACK;
771 cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); 849 cb = hv_fetch ((HV *)SvRV (coro_current), strpair ("_trace_sub_cb"), 0);
772 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 850 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
773 SPAGAIN; 851 SPAGAIN;
774 FREETMPS; 852 FREETMPS;
775 LEAVE; 853 LEAVE;
776 PL_runops = runops_trace; 854 PL_runops = runops_trace;
790 PL_runops = RUNOPS_DEFAULT; 868 PL_runops = RUNOPS_DEFAULT;
791 PUSHMARK (SP); 869 PUSHMARK (SP);
792 PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); 870 PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0)));
793 PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); 871 PUSHs (sv_2mortal (newSViv (CopLINE (oldcop))));
794 PUTBACK; 872 PUTBACK;
795 cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); 873 cb = hv_fetch ((HV *)SvRV (coro_current), strpair ("_trace_line_cb"), 0);
796 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 874 if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
797 SPAGAIN; 875 SPAGAIN;
798 FREETMPS; 876 FREETMPS;
799 LEAVE; 877 LEAVE;
800 PL_runops = runops_trace; 878 PL_runops = runops_trace;
991 croak ("Coro::State::transfer called with running next Coro::State, but can only transfer to inactive states"); 1069 croak ("Coro::State::transfer called with running next Coro::State, but can only transfer to inactive states");
992 1070
993 if (expect_false (next->flags & CF_DESTROYED)) 1071 if (expect_false (next->flags & CF_DESTROYED))
994 croak ("Coro::State::transfer called with destroyed next Coro::State, but can only transfer to inactive states"); 1072 croak ("Coro::State::transfer called with destroyed next Coro::State, but can only transfer to inactive states");
995 1073
1074 if (
1075#if PERL_VERSION_ATLEAST (5,9,0)
1076 expect_false (PL_parser)
1077#else
996 if (expect_false (PL_lex_state != LEX_NOTPARSING)) 1078 expect_false (PL_lex_state != LEX_NOTPARSING)
1079#endif
1080 )
997 croak ("Coro::State::transfer called while parsing, but this is not supported"); 1081 croak ("Coro::State::transfer called while parsing, but this is not supported");
998 } 1082 }
999} 1083}
1000 1084
1001/* always use the TRANSFER macro */ 1085/* always use the TRANSFER macro */
1130 save_perl (aTHX_ &temp); 1214 save_perl (aTHX_ &temp);
1131 load_perl (aTHX_ coro); 1215 load_perl (aTHX_ coro);
1132 1216
1133 coro_destroy (aTHX_ coro); 1217 coro_destroy (aTHX_ coro);
1134 1218
1135 load_perl (aTHX_ &temp); /* this will get rid of defsv etc.. */ 1219 load_perl (aTHX_ &temp);
1136 1220
1137 coro->mainstack = 0; 1221 coro->slot = 0;
1138 } 1222 }
1139 1223
1140 cctx_destroy (coro->cctx); 1224 cctx_destroy (coro->cctx);
1141 SvREFCNT_dec (coro->args); 1225 SvREFCNT_dec (coro->args);
1142 1226
1399 coro->cctx->flags &= ~(CC_TRACE | CC_TRACE_ALL); 1483 coro->cctx->flags &= ~(CC_TRACE | CC_TRACE_ALL);
1400 1484
1401 if (coro->flags & CF_RUNNING) 1485 if (coro->flags & CF_RUNNING)
1402 PL_runops = RUNOPS_DEFAULT; 1486 PL_runops = RUNOPS_DEFAULT;
1403 else 1487 else
1404 coro->runops = RUNOPS_DEFAULT; 1488 coro->slot->runops = RUNOPS_DEFAULT;
1405 } 1489 }
1406} 1490}
1407 1491
1408MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ 1492MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_
1409 1493
1416#endif 1500#endif
1417 BOOT_PAGESIZE; 1501 BOOT_PAGESIZE;
1418 1502
1419 irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); 1503 irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV);
1420 stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); 1504 stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO);
1505
1506 hv_sig = coro_get_hv ("SIG", TRUE);
1507 sv_diehook = coro_get_sv ("Coro::State::DIEHOOK" , TRUE);
1508 sv_warnhook = coro_get_sv ("Coro::State::WARNHOOK", TRUE);
1509
1510 if (!PL_diehook ) hv_store (hv_sig, strpair ("__DIE__" ), SvREFCNT_inc (sv_diehook ), 0);
1511 if (!PL_warnhook) hv_store (hv_sig, strpair ("__WARN__"), SvREFCNT_inc (sv_warnhook), 0);
1421 1512
1422 coro_state_stash = gv_stashpv ("Coro::State", TRUE); 1513 coro_state_stash = gv_stashpv ("Coro::State", TRUE);
1423 1514
1424 newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); 1515 newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE));
1425 newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); 1516 newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB));
1569 CODE: 1660 CODE:
1570{ 1661{
1571 if (coro->mainstack) 1662 if (coro->mainstack)
1572 { 1663 {
1573 struct coro temp; 1664 struct coro temp;
1574 Zero (&temp, 1, struct coro);
1575 1665
1576 if (!(coro->flags & CF_RUNNING)) 1666 if (!(coro->flags & CF_RUNNING))
1577 { 1667 {
1578 save_perl (aTHX_ &temp); 1668 save_perl (aTHX_ &temp);
1579 load_perl (aTHX_ coro); 1669 load_perl (aTHX_ coro);
1583 dSP; 1673 dSP;
1584 ENTER; 1674 ENTER;
1585 SAVETMPS; 1675 SAVETMPS;
1586 PUSHMARK (SP); 1676 PUSHMARK (SP);
1587 PUTBACK; 1677 PUTBACK;
1678
1588 if (ix) 1679 if (ix)
1589 eval_sv (coderef, 0); 1680 eval_sv (coderef, 0);
1590 else 1681 else
1591 call_sv (coderef, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); 1682 call_sv (coderef, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
1683
1592 SPAGAIN; 1684 SPAGAIN;
1593 FREETMPS; 1685 FREETMPS;
1594 LEAVE; 1686 LEAVE;
1595 PUTBACK; 1687 PUTBACK;
1596 } 1688 }
1654 1746
1655BOOT: 1747BOOT:
1656{ 1748{
1657 int i; 1749 int i;
1658 1750
1659 sv_pool_rss = get_sv ("Coro::POOL_RSS" , TRUE); 1751 sv_pool_rss = coro_get_sv ("Coro::POOL_RSS" , TRUE);
1660 sv_pool_size = get_sv ("Coro::POOL_SIZE" , TRUE); 1752 sv_pool_size = coro_get_sv ("Coro::POOL_SIZE" , TRUE);
1661 av_async_pool = get_av ("Coro::async_pool", TRUE); 1753 av_async_pool = coro_get_av ("Coro::async_pool", TRUE);
1662 1754
1663 coro_current = get_sv ("Coro::current", FALSE); 1755 coro_current = coro_get_sv ("Coro::current", FALSE);
1664 SvREADONLY_on (coro_current); 1756 SvREADONLY_on (coro_current);
1665 1757
1666 coro_stash = gv_stashpv ("Coro", TRUE); 1758 coro_stash = gv_stashpv ("Coro", TRUE);
1667 1759
1668 newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (PRIO_MAX)); 1760 newCONSTSUB (coro_stash, "PRIO_MAX", newSViv (PRIO_MAX));
1669 newCONSTSUB (coro_stash, "PRIO_HIGH", newSViv (PRIO_HIGH)); 1761 newCONSTSUB (coro_stash, "PRIO_HIGH", newSViv (PRIO_HIGH));
1670 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL)); 1762 newCONSTSUB (coro_stash, "PRIO_NORMAL", newSViv (PRIO_NORMAL));
1671 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW)); 1763 newCONSTSUB (coro_stash, "PRIO_LOW", newSViv (PRIO_LOW));
1674 1766
1675 for (i = PRIO_MAX - PRIO_MIN + 1; i--; ) 1767 for (i = PRIO_MAX - PRIO_MIN + 1; i--; )
1676 coro_ready[i] = newAV (); 1768 coro_ready[i] = newAV ();
1677 1769
1678 { 1770 {
1679 SV *sv = perl_get_sv("Coro::API", 1); 1771 SV *sv = perl_get_sv ("Coro::API", TRUE);
1772 perl_get_sv ("Coro::API", TRUE); /* silence 5.10 warning */
1680 1773
1681 coroapi.schedule = api_schedule; 1774 coroapi.schedule = api_schedule;
1682 coroapi.cede = api_cede; 1775 coroapi.cede = api_cede;
1683 coroapi.cede_notself = api_cede_notself; 1776 coroapi.cede_notself = api_cede_notself;
1684 coroapi.ready = api_ready; 1777 coroapi.ready = api_ready;
1750 CODE: 1843 CODE:
1751{ 1844{
1752 struct coro *coro = SvSTATE (coro_current); 1845 struct coro *coro = SvSTATE (coro_current);
1753 HV *hv = (HV *)SvRV (coro_current); 1846 HV *hv = (HV *)SvRV (coro_current);
1754 AV *defav = GvAV (PL_defgv); 1847 AV *defav = GvAV (PL_defgv);
1755 SV *invoke = hv_delete (hv, "_invoke", sizeof ("_invoke") - 1, 0); 1848 SV *invoke = hv_delete (hv, strpair ("_invoke"), 0);
1756 AV *invoke_av; 1849 AV *invoke_av;
1757 int i, len; 1850 int i, len;
1758 1851
1759 if (!invoke) 1852 if (!invoke)
1760 croak ("\3async_pool terminate\2\n"); 1853 croak ("\3async_pool terminate\2\n");
1761 1854
1762 SvREFCNT_dec (coro->saved_deffh); 1855 SvREFCNT_dec (coro->saved_deffh);
1763 coro->saved_deffh = SvREFCNT_inc ((SV *)PL_defoutgv); 1856 coro->saved_deffh = SvREFCNT_inc ((SV *)PL_defoutgv);
1764 1857
1765 hv_store (hv, "desc", sizeof ("desc") - 1, 1858 hv_store (hv, "desc", sizeof ("desc") - 1,
1766 newSVpvn ("[async_pool]", sizeof ("[async_pool]") - 1), 0); 1859 newSVpvn (strpair ("[async_pool]")), 0);
1767 1860
1768 invoke_av = (AV *)SvRV (invoke); 1861 invoke_av = (AV *)SvRV (invoke);
1769 len = av_len (invoke_av); 1862 len = av_len (invoke_av);
1770 1863
1771 sv_setsv (cb, AvARRAY (invoke_av)[0]); 1864 sv_setsv (cb, AvARRAY (invoke_av)[0]);
1794 if (coro_rss (aTHX_ coro) > SvIV (sv_pool_rss) 1887 if (coro_rss (aTHX_ coro) > SvIV (sv_pool_rss)
1795 || av_len (av_async_pool) + 1 >= SvIV (sv_pool_size)) 1888 || av_len (av_async_pool) + 1 >= SvIV (sv_pool_size))
1796 croak ("\3async_pool terminate\2\n"); 1889 croak ("\3async_pool terminate\2\n");
1797 1890
1798 av_clear (GvAV (PL_defgv)); 1891 av_clear (GvAV (PL_defgv));
1799 hv_store ((HV *)SvRV (coro_current), "desc", sizeof ("desc") - 1, 1892 hv_store ((HV *)SvRV (coro_current), strpair ("desc"),
1800 newSVpvn ("[async_pool idle]", sizeof ("[async_pool idle]") - 1), 0); 1893 newSVpvn (strpair ("[async_pool idle]")), 0);
1801 1894
1802 coro->prio = 0; 1895 coro->prio = 0;
1803 1896
1804 if (coro->cctx && (coro->cctx->flags & CC_TRACE)) 1897 if (coro->cctx && (coro->cctx->flags & CC_TRACE))
1805 api_trace (coro_current, 0); 1898 api_trace (coro_current, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines