… | |
… | |
75 | /* 5.8.7 */ |
75 | /* 5.8.7 */ |
76 | #ifndef SvRV_set |
76 | #ifndef SvRV_set |
77 | # define SvRV_set(s,v) SvRV(s) = (v) |
77 | # define SvRV_set(s,v) SvRV(s) = (v) |
78 | #endif |
78 | #endif |
79 | |
79 | |
|
|
80 | /* 5.8.8 */ |
|
|
81 | #ifndef GV_NOTQUAL |
|
|
82 | # define GV_NOTQUAL 0 |
|
|
83 | #endif |
|
|
84 | #ifndef newSV |
|
|
85 | # define newSV(l) NEWSV(0,l) |
|
|
86 | #endif |
|
|
87 | |
80 | #if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 |
88 | #if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 |
81 | # undef CORO_STACKGUARD |
89 | # undef CORO_STACKGUARD |
82 | #endif |
90 | #endif |
83 | |
91 | |
84 | #ifndef CORO_STACKGUARD |
92 | #ifndef CORO_STACKGUARD |
… | |
… | |
132 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
140 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
133 | static JMPENV *main_top_env; |
141 | static JMPENV *main_top_env; |
134 | static HV *coro_state_stash, *coro_stash; |
142 | static HV *coro_state_stash, *coro_stash; |
135 | static SV *coro_mortal; /* will be freed after next transfer */ |
143 | static SV *coro_mortal; /* will be freed after next transfer */ |
136 | |
144 | |
137 | static GV *irsgv; /* $/ */ |
145 | static GV *irsgv; /* $/ */ |
|
|
146 | static GV *stdoutgv; /* *STDOUT */ |
138 | |
147 | |
139 | /* async_pool helper stuff */ |
148 | /* async_pool helper stuff */ |
140 | static SV *sv_pool_rss; |
149 | static SV *sv_pool_rss; |
141 | static SV *sv_pool_size; |
150 | static SV *sv_pool_size; |
142 | static AV *av_async_pool; |
151 | static AV *av_async_pool; |
… | |
… | |
563 | # include "state.h" |
572 | # include "state.h" |
564 | #undef VAR |
573 | #undef VAR |
565 | } |
574 | } |
566 | |
575 | |
567 | rss += sizeof (coro->curstackinfo); |
576 | rss += sizeof (coro->curstackinfo); |
568 | rss += sizeof (struct xpvav) + (1 + AvFILL (coro->curstackinfo->si_stack)) * sizeof (SV *); |
577 | rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvFILL (coro->curstackinfo->si_stack)) * sizeof (SV *); |
569 | rss += (coro->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT); |
578 | rss += (coro->curstackinfo->si_cxmax + 1) * sizeof (PERL_CONTEXT); |
570 | rss += sizeof (struct xpvav) + (1 + AvFILL (coro->curstack)) * sizeof (SV *); |
579 | rss += sizeof (SV) + sizeof (struct xpvav) + (1 + AvFILL (coro->curstack)) * sizeof (SV *); |
571 | rss += coro->tmps_max * sizeof (SV *); |
580 | rss += coro->tmps_max * sizeof (SV *); |
572 | rss += (coro->markstack_max - coro->markstack_ptr) * sizeof (I32); |
581 | rss += (coro->markstack_max - coro->markstack_ptr) * sizeof (I32); |
573 | rss += coro->scopestack_max * sizeof (I32); |
582 | rss += coro->scopestack_max * sizeof (I32); |
574 | rss += coro->savestack_max * sizeof (ANY); |
583 | rss += coro->savestack_max * sizeof (ANY); |
575 | |
584 | |
… | |
… | |
598 | PL_curpm = 0; |
607 | PL_curpm = 0; |
599 | PL_localizing = 0; |
608 | PL_localizing = 0; |
600 | PL_dirty = 0; |
609 | PL_dirty = 0; |
601 | PL_restartop = 0; |
610 | PL_restartop = 0; |
602 | |
611 | |
603 | GvSV (PL_defgv) = NEWSV (0, 0); |
612 | GvSV (PL_defgv) = newSV (0); |
604 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
613 | GvAV (PL_defgv) = coro->args; coro->args = 0; |
605 | GvSV (PL_errgv) = NEWSV (0, 0); |
614 | GvSV (PL_errgv) = newSV (0); |
606 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
615 | GvSV (irsgv) = newSVpvn ("\n", 1); sv_magic (GvSV (irsgv), (SV *)irsgv, PERL_MAGIC_sv, "/", 0); |
607 | PL_rs = newSVsv (GvSV (irsgv)); |
616 | PL_rs = newSVsv (GvSV (irsgv)); |
|
|
617 | PL_defoutgv = SvREFCNT_inc (stdoutgv); |
608 | |
618 | |
609 | { |
619 | ENTER; /* necessary e.g. for dounwind */ |
610 | IO *io = newIO (); |
|
|
611 | PL_defoutgv = newGVgen ("Coro"); |
|
|
612 | GvIOp(PL_defoutgv) = io; |
|
|
613 | IoTYPE (io) = IoTYPE_WRONLY; |
|
|
614 | IoOFP (io) = IoIFP (io) = PerlIO_stdout (); |
|
|
615 | IoFLAGS (io) |= IOf_FLUSH; |
|
|
616 | } |
|
|
617 | |
620 | |
618 | { |
621 | { |
619 | dSP; |
622 | dSP; |
620 | LOGOP myop; |
623 | LOGOP myop; |
621 | |
624 | |
622 | Zero (&myop, 1, LOGOP); |
625 | Zero (&myop, 1, LOGOP); |
623 | myop.op_next = Nullop; |
626 | myop.op_next = Nullop; |
624 | myop.op_flags = OPf_WANT_VOID; |
627 | myop.op_flags = OPf_WANT_VOID; |
625 | |
628 | |
626 | PUSHMARK (SP); |
629 | PUSHMARK (SP); |
627 | XPUSHs (av_shift (GvAV (PL_defgv))); |
630 | XPUSHs (sv_2mortal (av_shift (GvAV (PL_defgv)))); |
628 | PUTBACK; |
631 | PUTBACK; |
629 | PL_op = (OP *)&myop; |
632 | PL_op = (OP *)&myop; |
630 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
633 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
631 | SPAGAIN; |
634 | SPAGAIN; |
632 | } |
635 | } |
633 | |
|
|
634 | ENTER; /* necessary e.g. for dounwind */ |
|
|
635 | } |
636 | } |
636 | |
637 | |
637 | static void |
638 | static void |
638 | coro_destroy (pTHX_ struct coro *coro) |
639 | coro_destroy (pTHX_ struct coro *coro) |
639 | { |
640 | { |
… | |
… | |
707 | bot = PL_stack_base + cx->blk_oldsp + 1; |
708 | bot = PL_stack_base + cx->blk_oldsp + 1; |
708 | top = cx->blk_gimme == G_ARRAY ? SP + 1 |
709 | top = cx->blk_gimme == G_ARRAY ? SP + 1 |
709 | : cx->blk_gimme == G_SCALAR ? bot + 1 |
710 | : cx->blk_gimme == G_SCALAR ? bot + 1 |
710 | : bot; |
711 | : bot; |
711 | |
712 | |
|
|
713 | av_extend (av, top - bot); |
712 | while (bot < top) |
714 | while (bot < top) |
713 | av_push (av, SvREFCNT_inc (*bot++)); |
715 | av_push (av, SvREFCNT_inc (*bot++)); |
714 | |
716 | |
715 | PL_runops = RUNOPS_DEFAULT; |
717 | PL_runops = RUNOPS_DEFAULT; |
716 | ENTER; |
718 | ENTER; |
… | |
… | |
928 | Safefree (cctx->sptr); |
930 | Safefree (cctx->sptr); |
929 | |
931 | |
930 | Safefree (cctx); |
932 | Safefree (cctx); |
931 | } |
933 | } |
932 | |
934 | |
|
|
935 | /* wether this cctx should be destructed */ |
|
|
936 | #define CCTX_EXPIRED(cctx) ((cctx)->ssize < coro_stacksize || ((cctx)->flags & CC_NOREUSE)) |
|
|
937 | |
933 | static coro_cctx * |
938 | static coro_cctx * |
934 | cctx_get (pTHX) |
939 | cctx_get (pTHX) |
935 | { |
940 | { |
936 | while (cctx_first) |
941 | while (cctx_first) |
937 | { |
942 | { |
938 | coro_cctx *cctx = cctx_first; |
943 | coro_cctx *cctx = cctx_first; |
939 | cctx_first = cctx->next; |
944 | cctx_first = cctx->next; |
940 | --cctx_idle; |
945 | --cctx_idle; |
941 | |
946 | |
942 | if (cctx->ssize >= coro_stacksize && !(cctx->flags & CC_NOREUSE)) |
947 | if (!CCTX_EXPIRED (cctx)) |
943 | return cctx; |
948 | return cctx; |
944 | |
949 | |
945 | cctx_destroy (cctx); |
950 | cctx_destroy (cctx); |
946 | } |
951 | } |
947 | |
952 | |
… | |
… | |
1040 | /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */ |
1045 | /* I assume that STACKLEVEL is a stronger indicator than PL_top_env changes */ |
1041 | assert (("ERROR: current top_env must equal previous top_env", PL_top_env == prev__cctx->idle_te)); |
1046 | assert (("ERROR: current top_env must equal previous top_env", PL_top_env == prev__cctx->idle_te)); |
1042 | |
1047 | |
1043 | prev->cctx = 0; |
1048 | prev->cctx = 0; |
1044 | |
1049 | |
|
|
1050 | /* if the cctx is about to be destroyed we need to make sure we won't see it in cctx_get */ |
|
|
1051 | if (CCTX_EXPIRED (prev__cctx)) |
|
|
1052 | next->cctx = cctx_get (aTHX); |
|
|
1053 | |
1045 | cctx_put (prev__cctx); |
1054 | cctx_put (prev__cctx); |
1046 | } |
1055 | } |
1047 | |
1056 | |
1048 | ++next->usecount; |
1057 | ++next->usecount; |
1049 | |
1058 | |
… | |
… | |
1385 | #ifdef USE_ITHREADS |
1394 | #ifdef USE_ITHREADS |
1386 | MUTEX_INIT (&coro_mutex); |
1395 | MUTEX_INIT (&coro_mutex); |
1387 | #endif |
1396 | #endif |
1388 | BOOT_PAGESIZE; |
1397 | BOOT_PAGESIZE; |
1389 | |
1398 | |
1390 | irsgv = gv_fetchpv ("/", 1, SVt_PV); |
1399 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
|
|
1400 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
1391 | |
1401 | |
1392 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
1402 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
1393 | |
1403 | |
1394 | newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); |
1404 | newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE)); |
1395 | newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); |
1405 | newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB)); |
… | |
… | |
1426 | |
1436 | |
1427 | coro->hv = hv = newHV (); |
1437 | coro->hv = hv = newHV (); |
1428 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP; |
1438 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, &coro_state_vtbl, (char *)coro, 0)->mg_flags |= MGf_DUP; |
1429 | RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
1439 | RETVAL = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); |
1430 | |
1440 | |
|
|
1441 | av_extend (coro->args, items - 1); |
1431 | for (i = 1; i < items; i++) |
1442 | for (i = 1; i < items; i++) |
1432 | av_push (coro->args, newSVsv (ST (i))); |
1443 | av_push (coro->args, newSVsv (ST (i))); |
1433 | } |
1444 | } |
1434 | OUTPUT: |
1445 | OUTPUT: |
1435 | RETVAL |
1446 | RETVAL |