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.233 by root, Fri May 9 22:04:37 2008 UTC vs.
Revision 1.238 by root, Sat May 31 12:10:55 2008 UTC

684/** coroutine stack handling ************************************************/ 684/** coroutine stack handling ************************************************/
685 685
686static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg); 686static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg);
687static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg); 687static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg);
688 688
689/* apparently < 5.8.8 */
690#undef MgPV_nolen_const
691#ifndef MgPV_nolen_const
692#define MgPV_nolen_const(mg) (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \
693 SvPV_nolen_const((SV*)((mg)->mg_ptr)) : \
694 (const char*)(mg)->mg_ptr)
695#endif
696
689/* 697/*
690 * This overrides the default magic get method of %SIG elements. 698 * This overrides the default magic get method of %SIG elements.
691 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook 699 * The original one doesn't provide for reading back of PL_diehook/PL_warnhook
692 * and instead of tryign to save and restore the hash elements, we just provide 700 * and instead of tryign to save and restore the hash elements, we just provide
693 * readback here. 701 * readback here.
1383static int 1391static int
1384api_ready (SV *coro_sv) 1392api_ready (SV *coro_sv)
1385{ 1393{
1386 dTHX; 1394 dTHX;
1387 struct coro *coro; 1395 struct coro *coro;
1388 SV *hook; 1396 SV *sv_hook;
1397 void (*xs_hook)(void);
1389 1398
1390 if (SvROK (coro_sv)) 1399 if (SvROK (coro_sv))
1391 coro_sv = SvRV (coro_sv); 1400 coro_sv = SvRV (coro_sv);
1392 1401
1393 coro = SvSTATE (coro_sv); 1402 coro = SvSTATE (coro_sv);
1397 1406
1398 coro->flags |= CF_READY; 1407 coro->flags |= CF_READY;
1399 1408
1400 LOCK; 1409 LOCK;
1401 1410
1402 hook = coro_nready ? 0 : coro_readyhook; 1411 sv_hook = coro_nready ? 0 : coro_readyhook;
1412 xs_hook = coro_nready ? 0 : coroapi.readyhook;
1403 1413
1404 coro_enq (aTHX_ SvREFCNT_inc (coro_sv)); 1414 coro_enq (aTHX_ SvREFCNT_inc (coro_sv));
1405 ++coro_nready; 1415 ++coro_nready;
1406 1416
1407 UNLOCK; 1417 UNLOCK;
1408 1418
1409 if (hook) 1419 if (sv_hook)
1410 { 1420 {
1411 dSP; 1421 dSP;
1412 1422
1413 ENTER; 1423 ENTER;
1414 SAVETMPS; 1424 SAVETMPS;
1415 1425
1416 PUSHMARK (SP); 1426 PUSHMARK (SP);
1417 PUTBACK; 1427 PUTBACK;
1418 call_sv (hook, G_DISCARD); 1428 call_sv (sv_hook, G_DISCARD);
1419 SPAGAIN; 1429 SPAGAIN;
1420 1430
1421 FREETMPS; 1431 FREETMPS;
1422 LEAVE; 1432 LEAVE;
1423 } 1433 }
1434
1435 if (xs_hook)
1436 xs_hook ();
1424 1437
1425 return 1; 1438 return 1;
1426} 1439}
1427 1440
1428static int 1441static int
1614 main_top_env = PL_top_env; 1627 main_top_env = PL_top_env;
1615 1628
1616 while (main_top_env->je_prev) 1629 while (main_top_env->je_prev)
1617 main_top_env = main_top_env->je_prev; 1630 main_top_env = main_top_env->je_prev;
1618 1631
1619 coroapi.ver = CORO_API_VERSION; 1632 coroapi.ver = CORO_API_VERSION;
1620 coroapi.rev = CORO_API_REVISION; 1633 coroapi.rev = CORO_API_REVISION;
1621 coroapi.transfer = api_transfer; 1634 coroapi.transfer = api_transfer;
1622 1635
1623 assert (("PRIO_NORMAL must be 0", !PRIO_NORMAL)); 1636 assert (("PRIO_NORMAL must be 0", !PRIO_NORMAL));
1624} 1637}
1625 1638
1626SV * 1639SV *
1811 1824
1812void 1825void
1813api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB) 1826api_trace (SV *coro, int flags = CC_TRACE | CC_TRACE_SUB)
1814 1827
1815SV * 1828SV *
1816has_stack (Coro::State coro) 1829has_cctx (Coro::State coro)
1817 PROTOTYPE: $ 1830 PROTOTYPE: $
1818 CODE: 1831 CODE:
1819 RETVAL = boolSV (!!coro->cctx); 1832 RETVAL = boolSV (!!coro->cctx);
1820 OUTPUT: 1833 OUTPUT:
1821 RETVAL 1834 RETVAL
1901void 1914void
1902_set_readyhook (SV *hook) 1915_set_readyhook (SV *hook)
1903 PROTOTYPE: $ 1916 PROTOTYPE: $
1904 CODE: 1917 CODE:
1905 LOCK; 1918 LOCK;
1906 if (coro_readyhook)
1907 SvREFCNT_dec (coro_readyhook); 1919 SvREFCNT_dec (coro_readyhook);
1908 coro_readyhook = SvOK (hook) ? newSVsv (hook) : 0; 1920 coro_readyhook = SvOK (hook) ? newSVsv (hook) : 0;
1909 UNLOCK; 1921 UNLOCK;
1910 1922
1911int 1923int
1912prio (Coro::State coro, int newprio = 0) 1924prio (Coro::State coro, int newprio = 0)
2078 2090
2079BOOT: 2091BOOT:
2080 sv_activity = coro_get_sv (aTHX_ "Coro::AnyEvent::ACTIVITY", TRUE); 2092 sv_activity = coro_get_sv (aTHX_ "Coro::AnyEvent::ACTIVITY", TRUE);
2081 2093
2082SV * 2094SV *
2083_schedule () 2095_schedule (...)
2084 PROTOTYPE: @ 2096 PROTOTYPE: @
2085 CODE: 2097 CODE:
2086{ 2098{
2087 static int incede; 2099 static int incede;
2088 fprintf (stderr, "_schedule\n");//D
2089 2100
2090 api_cede_notself (); 2101 api_cede_notself ();
2091 2102
2092 ++incede; 2103 ++incede;
2093 while (coro_nready >= incede && api_cede ()) 2104 while (coro_nready >= incede && api_cede ())
2096 sv_setsv (sv_activity, &PL_sv_undef); 2107 sv_setsv (sv_activity, &PL_sv_undef);
2097 if (coro_nready >= incede) 2108 if (coro_nready >= incede)
2098 { 2109 {
2099 PUSHMARK (SP); 2110 PUSHMARK (SP);
2100 PUTBACK; 2111 PUTBACK;
2101 fprintf (stderr, "call act %d >= %d\n", coro_nready, incede);//D
2102 call_pv ("Coro::AnyEvent::_activity", G_DISCARD | G_EVAL); 2112 call_pv ("Coro::AnyEvent::_activity", G_DISCARD | G_EVAL);
2103 SPAGAIN; 2113 SPAGAIN;
2104 } 2114 }
2105 2115
2106 --incede; 2116 --incede;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines