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.166 by root, Wed Sep 26 21:11:28 2007 UTC vs.
Revision 1.167 by root, Thu Sep 27 15:52:31 2007 UTC

141 141
142static struct coro_cctx *cctx_first; 142static struct coro_cctx *cctx_first;
143static int cctx_count, cctx_idle; 143static int cctx_count, cctx_idle;
144 144
145enum { 145enum {
146 CC_MAPPED = 0x01, 146 CC_MAPPED = 0x01,
147 CC_TRACE = 0x02,
148 CC_NOREUSE = 0x04, /* throw this away after tracing */ 147 CC_NOREUSE = 0x02, /* throw this away after tracing */
148 CC_TRACE = 0x04,
149 CC_TRACE_SUB = 0x08, /* trace sub calls */
150 CC_TRACE_LINE = 0x10, /* trace each statement */
151 CC_TRACE_ALL = CC_TRACE_SUB | CC_TRACE_LINE,
149}; 152};
150 153
151/* this is a structure representing a c-level coroutine */ 154/* this is a structure representing a c-level coroutine */
152typedef struct coro_cctx { 155typedef struct coro_cctx {
153 struct coro_cctx *next; 156 struct coro_cctx *next;
630 SvREFCNT_dec (coro_mortal); 633 SvREFCNT_dec (coro_mortal);
631 coro_mortal = 0; 634 coro_mortal = 0;
632 } 635 }
633} 636}
634 637
635static void
636do_trace (pTHX)
637{
638 if (PL_curcop != &PL_compiling)
639 {
640 runops_proc_t old_runops = PL_runops;
641 dSP;
642 ENTER;
643 SAVETMPS;
644 PUSHMARK (SP);
645 PUTBACK;
646 PL_runops = RUNOPS_DEFAULT;
647 call_pv ("Coro::_do_trace", G_KEEPERR | G_EVAL | G_VOID | G_DISCARD | G_NOARGS);
648 PL_runops = old_runops;
649 SPAGAIN;
650 FREETMPS;
651 LEAVE;
652 PUTBACK;
653 }
654}
655
656static int 638static int
657runops_coro (pTHX) 639runops_coro (pTHX)
658{ 640{
659 COP *oldcop = 0; 641 COP *oldcop = 0;
642 int oldcxix = -2;
660 643
661 while ((PL_op = CALL_FPTR (PL_op->op_ppaddr) (aTHX))) 644 while ((PL_op = CALL_FPTR (PL_op->op_ppaddr) (aTHX)))
662 { 645 {
663 PERL_ASYNC_CHECK (); 646 PERL_ASYNC_CHECK ();
647
648 if (PL_op->op_type == OP_LEAVESUB)
649 {
650 PERL_CONTEXT *cx = &cxstack[cxstack_ix];
651 SV **bot, **top;
652 AV *av = newAV (); /* return values */
653 runops_proc_t old_runops = PL_runops;
654 dSP;
655 ENTER;
656 SAVETMPS;
657 EXTEND (SP, 3);
658 PL_runops = RUNOPS_DEFAULT;
659
660 GV *gv = CvGV (cx->blk_sub.cv);
661 SV *fullname = sv_2mortal (newSV (0));
662 if (isGV (gv))
663 gv_efullname3 (fullname, gv, 0);
664
665 bot = PL_stack_base + cx->blk_oldsp + 1;
666 top = cx->blk_gimme == G_ARRAY ? SP + 1
667 : cx->blk_gimme == G_SCALAR ? bot + 1
668 : bot;
669
670 while (bot < top)
671 av_push (av, SvREFCNT_inc (*bot++));
672
673 PUSHMARK (SP);
674 PUSHs (&PL_sv_no);
675 PUSHs (fullname);
676 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
677 PUTBACK;
678 call_pv ("Coro::_do_trace_sub", G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
679 SPAGAIN;
680
681 FREETMPS;
682 LEAVE;
683 PL_runops = old_runops;
684 }
664 685
665 if (oldcop != PL_curcop) 686 if (oldcop != PL_curcop)
666 { 687 {
667 oldcop = PL_curcop; 688 oldcop = PL_curcop;
668 do_trace (aTHX); 689
690 if (PL_curcop != &PL_compiling)
691 {
692 runops_proc_t old_runops = PL_runops;
693 dSP;
694 ENTER;
695 SAVETMPS;
696 EXTEND (SP, 3);
697 PL_runops = RUNOPS_DEFAULT;
698
699 if (oldcxix != cxstack_ix)
700 {
701 PERL_CONTEXT *cx = &cxstack[cxstack_ix];
702
703 if (CxTYPE (cx) == CXt_SUB && oldcxix < cxstack_ix)
704 {
705 GV *gv = CvGV (cx->blk_sub.cv);
706 SV *fullname = sv_2mortal (newSV (0));
707 if (isGV (gv))
708 gv_efullname3 (fullname, gv, 0);
709
710 PUSHMARK (SP);
711 PUSHs (&PL_sv_yes);
712 PUSHs (fullname);
713 PUSHs (cx->blk_sub.hasargs ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef);
714 PUTBACK;
715 call_pv ("Coro::_do_trace_sub", G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
716 SPAGAIN;
717 }
718
719 oldcxix = cxstack_ix;
720 }
721
722 if (0) {
723 PUSHMARK (SP);
724 PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0)));
725 PUSHs (sv_2mortal (newSViv (CopLINE (oldcop))));
726 PUTBACK;
727 call_pv ("Coro::_do_trace_line", G_KEEPERR | G_EVAL | G_VOID | G_DISCARD);
728 SPAGAIN;
729 }
730
731 FREETMPS;
732 LEAVE;
733 PL_runops = old_runops;
734 }
669 } 735 }
670 } 736 }
671 737
672 TAINT_NOT; 738 TAINT_NOT;
673 return 0; 739 return 0;
1262#endif 1328#endif
1263 BOOT_PAGESIZE; 1329 BOOT_PAGESIZE;
1264 1330
1265 coro_state_stash = gv_stashpv ("Coro::State", TRUE); 1331 coro_state_stash = gv_stashpv ("Coro::State", TRUE);
1266 1332
1333 newCONSTSUB (coro_state_stash, "CC_TRACE" , newSViv (CC_TRACE));
1334 newCONSTSUB (coro_state_stash, "CC_TRACE_SUB" , newSViv (CC_TRACE_SUB));
1335 newCONSTSUB (coro_state_stash, "CC_TRACE_LINE", newSViv (CC_TRACE_LINE));
1336 newCONSTSUB (coro_state_stash, "CC_TRACE_ALL" , newSViv (CC_TRACE_ALL));
1337
1267 newCONSTSUB (coro_state_stash, "SAVE_DEFAV", newSViv (CORO_SAVE_DEFAV)); 1338 newCONSTSUB (coro_state_stash, "SAVE_DEFAV", newSViv (CORO_SAVE_DEFAV));
1268 newCONSTSUB (coro_state_stash, "SAVE_DEFSV", newSViv (CORO_SAVE_DEFSV)); 1339 newCONSTSUB (coro_state_stash, "SAVE_DEFSV", newSViv (CORO_SAVE_DEFSV));
1269 newCONSTSUB (coro_state_stash, "SAVE_ERRSV", newSViv (CORO_SAVE_ERRSV)); 1340 newCONSTSUB (coro_state_stash, "SAVE_ERRSV", newSViv (CORO_SAVE_ERRSV));
1270 newCONSTSUB (coro_state_stash, "SAVE_IRSSV", newSViv (CORO_SAVE_IRSSV)); 1341 newCONSTSUB (coro_state_stash, "SAVE_IRSSV", newSViv (CORO_SAVE_IRSSV));
1271 newCONSTSUB (coro_state_stash, "SAVE_DEFFH", newSViv (CORO_SAVE_DEFFH)); 1342 newCONSTSUB (coro_state_stash, "SAVE_DEFFH", newSViv (CORO_SAVE_DEFFH));
1477 RETVAL = boolSV (coro->flags & ix); 1548 RETVAL = boolSV (coro->flags & ix);
1478 OUTPUT: 1549 OUTPUT:
1479 RETVAL 1550 RETVAL
1480 1551
1481void 1552void
1482trace (Coro::State coro, int enable = 0) 1553trace (Coro::State coro, int flags = CC_TRACE | CC_TRACE_SUB)
1483 CODE: 1554 CODE:
1484 if (enable) 1555 if (flags & CC_TRACE)
1485 { 1556 {
1486 if (coro->cctx && coro->cctx->flags & CC_TRACE)
1487 XSRETURN_EMPTY;
1488
1489 if (coro->flags & CF_RUNNING)
1490 croak ("cannot enable tracing on running coroutine");
1491
1492 if (coro->cctx) 1557 if (!coro->cctx)
1558 coro->cctx = cctx_new ();
1559 else if (!(coro->cctx->flags & CC_TRACE))
1493 croak ("cannot enable tracing on coroutine with custom stack"); 1560 croak ("cannot enable tracing on coroutine with custom stack");
1494 1561
1495 coro->cctx = cctx_new ();
1496 coro->cctx->flags |= CC_TRACE; 1562 coro->cctx->flags |= flags & (CC_TRACE | CC_TRACE_ALL);
1497 } 1563 }
1498 else 1564 else
1499 if (coro->cctx && coro->cctx->flags & CC_TRACE) 1565 if (coro->cctx && coro->cctx->flags & CC_TRACE)
1500 { 1566 {
1501 coro->cctx->flags &= ~CC_TRACE; 1567 coro->cctx->flags &= ~(CC_TRACE | CC_TRACE_ALL);
1502 coro->cctx->flags |= CC_NOREUSE; 1568 coro->cctx->flags |= CC_NOREUSE;
1503 } 1569 }
1504 1570
1505SV * 1571SV *
1506has_stack (Coro::State coro) 1572has_stack (Coro::State coro)
1507 PROTOTYPE: $ 1573 PROTOTYPE: $
1508 CODE: 1574 CODE:
1509 RETVAL = boolSV (!!coro->cctx); 1575 RETVAL = boolSV (!!coro->cctx);
1576 OUTPUT:
1577 RETVAL
1578
1579int
1580is_traced (Coro::State coro)
1581 PROTOTYPE: $
1582 CODE:
1583 RETVAL = (coro->cctx ? coro->cctx->flags : 0) & CC_TRACE_ALL;
1510 OUTPUT: 1584 OUTPUT:
1511 RETVAL 1585 RETVAL
1512 1586
1513IV 1587IV
1514rss (Coro::State coro) 1588rss (Coro::State coro)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines