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.316 by root, Thu Nov 20 06:01:40 2008 UTC vs.
Revision 1.317 by root, Thu Nov 20 06:28:52 2008 UTC

1614 return !!(SvSTATE (coro_sv)->flags & CF_READY); 1614 return !!(SvSTATE (coro_sv)->flags & CF_READY);
1615} 1615}
1616 1616
1617/* expects to own a reference to next->hv */ 1617/* expects to own a reference to next->hv */
1618INLINE void 1618INLINE void
1619prepare_cede_to (pTHX_ struct coro_transfer_args *ta, struct coro *next) 1619prepare_schedule_to (pTHX_ struct coro_transfer_args *ta, struct coro *next)
1620{ 1620{
1621 SV *prev_sv = SvRV (coro_current); 1621 SV *prev_sv = SvRV (coro_current);
1622 1622
1623 ta->prev = SvSTATE_hv (prev_sv); 1623 ta->prev = SvSTATE_hv (prev_sv);
1624 ta->next = next; 1624 ta->next = next;
1625 1625
1626 TRANSFER_CHECK (*ta); 1626 TRANSFER_CHECK (*ta);
1627 1627
1628 SvRV_set (coro_current, next->hv); 1628 SvRV_set (coro_current, (SV *)next->hv);
1629 1629
1630 free_coro_mortal (aTHX); 1630 free_coro_mortal (aTHX);
1631 coro_mortal = prev_sv; 1631 coro_mortal = prev_sv;
1632} 1632}
1633 1633
1636{ 1636{
1637 for (;;) 1637 for (;;)
1638 { 1638 {
1639 SV *next_sv = coro_deq (aTHX); 1639 SV *next_sv = coro_deq (aTHX);
1640 1640
1641 if (expect_false (!next_sv)) 1641 if (expect_true (next_sv))
1642 {
1643 /* nothing to schedule: call the idle handler */
1644 dSP;
1645
1646 ENTER;
1647 SAVETMPS;
1648
1649 PUSHMARK (SP);
1650 PUTBACK;
1651 call_sv (get_sv ("Coro::idle", FALSE), G_VOID | G_DISCARD);
1652
1653 FREETMPS;
1654 LEAVE;
1655 }
1656 else
1657 { 1642 {
1658 struct coro *next = SvSTATE_hv (next_sv); 1643 struct coro *next = SvSTATE_hv (next_sv);
1659 1644
1660 /* cannot transfer to destroyed coros, skip and look for next */ 1645 /* cannot transfer to destroyed coros, skip and look for next */
1661 if (expect_false (next->flags & CF_DESTROYED)) 1646 if (expect_false (next->flags & CF_DESTROYED))
1663 else 1648 else
1664 { 1649 {
1665 next->flags &= ~CF_READY; 1650 next->flags &= ~CF_READY;
1666 --coro_nready; 1651 --coro_nready;
1667 1652
1668 return prepare_cede_to (aTHX_ ta, next); 1653 return prepare_schedule_to (aTHX_ ta, next);
1669 } 1654 }
1670 } 1655 }
1656 else
1657 {
1658 /* nothing to schedule: call the idle handler */
1659 dSP;
1660
1661 ENTER;
1662 SAVETMPS;
1663
1664 PUSHMARK (SP);
1665 PUTBACK;
1666 call_sv (get_sv ("Coro::idle", FALSE), G_VOID | G_DISCARD);
1667
1668 FREETMPS;
1669 LEAVE;
1670 }
1671 } 1671 }
1672} 1672}
1673 1673
1674INLINE void 1674INLINE void
1675prepare_cede (pTHX_ struct coro_transfer_args *ta) 1675prepare_cede (pTHX_ struct coro_transfer_args *ta)
1697{ 1697{
1698 struct coro_transfer_args ta; 1698 struct coro_transfer_args ta;
1699 1699
1700 prepare_schedule (aTHX_ &ta); 1700 prepare_schedule (aTHX_ &ta);
1701 TRANSFER (ta, 1); 1701 TRANSFER (ta, 1);
1702}
1703
1704static void
1705api_schedule_to (pTHX_ SV *coro_sv)
1706{
1707 struct coro_transfer_args ta;
1708 struct coro *next = SvSTATE (coro_sv);
1709
1710 SvREFCNT_inc_NN (coro_sv);
1711 prepare_schedule_to (aTHX_ &ta, next);
1702} 1712}
1703 1713
1704static int 1714static int
1705api_cede (pTHX) 1715api_cede (pTHX)
1706{ 1716{
1995static void 2005static void
1996slf_init_schedule (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items) 2006slf_init_schedule (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items)
1997{ 2007{
1998 frame->prepare = prepare_schedule; 2008 frame->prepare = prepare_schedule;
1999 frame->check = slf_check_nop; 2009 frame->check = slf_check_nop;
2010}
2011
2012static void
2013slf_prepare_schedule_to (pTHX_ struct coro_transfer_args *ta)
2014{
2015 struct coro *next = (struct coro *)slf_frame.data;
2016
2017 SvREFCNT_inc_NN (next->hv);
2018 prepare_schedule_to (aTHX_ ta, next);
2019}
2020
2021static void
2022slf_init_schedule_to (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items)
2023{
2024 if (!items)
2025 croak ("Coro::schedule_to expects a coroutine argument, caught");
2026
2027 frame->data = (void *)SvSTATE (arg [0]);
2028 frame->prepare = slf_prepare_schedule_to;
2029 frame->check = slf_check_nop;
2030}
2031
2032static void
2033slf_init_cede_to (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items)
2034{
2035 api_ready (aTHX_ SvRV (coro_current));
2036
2037 slf_init_schedule_to (aTHX_ frame, cv, arg, items);
2000} 2038}
2001 2039
2002static void 2040static void
2003slf_init_cede (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items) 2041slf_init_cede (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items)
2004{ 2042{
2986 3024
2987 { 3025 {
2988 SV *sv = coro_get_sv (aTHX_ "Coro::API", TRUE); 3026 SV *sv = coro_get_sv (aTHX_ "Coro::API", TRUE);
2989 3027
2990 coroapi.schedule = api_schedule; 3028 coroapi.schedule = api_schedule;
3029 coroapi.schedule_to = api_schedule_to;
2991 coroapi.cede = api_cede; 3030 coroapi.cede = api_cede;
2992 coroapi.cede_notself = api_cede_notself; 3031 coroapi.cede_notself = api_cede_notself;
2993 coroapi.ready = api_ready; 3032 coroapi.ready = api_ready;
2994 coroapi.is_ready = api_is_ready; 3033 coroapi.is_ready = api_is_ready;
2995 coroapi.nready = coro_nready; 3034 coroapi.nready = coro_nready;
3003 3042
3004void 3043void
3005schedule (...) 3044schedule (...)
3006 CODE: 3045 CODE:
3007 CORO_EXECUTE_SLF_XS (slf_init_schedule); 3046 CORO_EXECUTE_SLF_XS (slf_init_schedule);
3047
3048void
3049schedule_to (...)
3050 CODE:
3051 CORO_EXECUTE_SLF_XS (slf_init_schedule_to);
3052
3053void
3054cede_to (...)
3055 CODE:
3056 CORO_EXECUTE_SLF_XS (slf_init_cede_to);
3008 3057
3009void 3058void
3010cede (...) 3059cede (...)
3011 CODE: 3060 CODE:
3012 CORO_EXECUTE_SLF_XS (slf_init_cede); 3061 CORO_EXECUTE_SLF_XS (slf_init_cede);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines