… | |
… | |
171 | /* async_pool helper stuff */ |
171 | /* async_pool helper stuff */ |
172 | static SV *sv_pool_rss; |
172 | static SV *sv_pool_rss; |
173 | static SV *sv_pool_size; |
173 | static SV *sv_pool_size; |
174 | static AV *av_async_pool; |
174 | static AV *av_async_pool; |
175 | |
175 | |
|
|
176 | /* Coro::AnyEvent */ |
|
|
177 | static SV *sv_activity; |
|
|
178 | |
176 | static struct coro_cctx *cctx_first; |
179 | static struct coro_cctx *cctx_first; |
177 | static int cctx_count, cctx_idle; |
180 | static int cctx_count, cctx_idle; |
178 | |
181 | |
179 | enum { |
182 | enum { |
180 | CC_MAPPED = 0x01, |
183 | CC_MAPPED = 0x01, |
… | |
… | |
265 | #define PRIO_IDLE -3 |
268 | #define PRIO_IDLE -3 |
266 | #define PRIO_MIN -4 |
269 | #define PRIO_MIN -4 |
267 | |
270 | |
268 | /* for Coro.pm */ |
271 | /* for Coro.pm */ |
269 | static SV *coro_current; |
272 | static SV *coro_current; |
|
|
273 | static SV *coro_readyhook; |
270 | static AV *coro_ready [PRIO_MAX-PRIO_MIN+1]; |
274 | static AV *coro_ready [PRIO_MAX-PRIO_MIN+1]; |
271 | static int coro_nready; |
275 | static int coro_nready; |
272 | static struct coro *coro_first; |
276 | static struct coro *coro_first; |
273 | |
277 | |
274 | /** lowlevel stuff **********************************************************/ |
278 | /** lowlevel stuff **********************************************************/ |
… | |
… | |
510 | |
514 | |
511 | if (expect_true (CvDEPTH (cv))) |
515 | if (expect_true (CvDEPTH (cv))) |
512 | { |
516 | { |
513 | EXTEND (SP, 3); |
517 | EXTEND (SP, 3); |
514 | PUSHs ((SV *)CvPADLIST (cv)); |
518 | PUSHs ((SV *)CvPADLIST (cv)); |
515 | PUSHs (INT2PTR (SV *, CvDEPTH (cv))); |
519 | PUSHs (INT2PTR (SV *, (IV)CvDEPTH (cv))); |
516 | PUSHs ((SV *)cv); |
520 | PUSHs ((SV *)cv); |
517 | |
521 | |
518 | CvDEPTH (cv) = 0; |
522 | CvDEPTH (cv) = 0; |
519 | get_padlist (aTHX_ cv); |
523 | get_padlist (aTHX_ cv); |
520 | } |
524 | } |
… | |
… | |
1379 | static int |
1383 | static int |
1380 | api_ready (SV *coro_sv) |
1384 | api_ready (SV *coro_sv) |
1381 | { |
1385 | { |
1382 | dTHX; |
1386 | dTHX; |
1383 | struct coro *coro; |
1387 | struct coro *coro; |
|
|
1388 | SV *hook; |
1384 | |
1389 | |
1385 | if (SvROK (coro_sv)) |
1390 | if (SvROK (coro_sv)) |
1386 | coro_sv = SvRV (coro_sv); |
1391 | coro_sv = SvRV (coro_sv); |
1387 | |
1392 | |
1388 | coro = SvSTATE (coro_sv); |
1393 | coro = SvSTATE (coro_sv); |
… | |
… | |
1391 | return 0; |
1396 | return 0; |
1392 | |
1397 | |
1393 | coro->flags |= CF_READY; |
1398 | coro->flags |= CF_READY; |
1394 | |
1399 | |
1395 | LOCK; |
1400 | LOCK; |
|
|
1401 | |
|
|
1402 | hook = coro_nready ? 0 : coro_readyhook; |
|
|
1403 | |
1396 | coro_enq (aTHX_ SvREFCNT_inc (coro_sv)); |
1404 | coro_enq (aTHX_ SvREFCNT_inc (coro_sv)); |
1397 | ++coro_nready; |
1405 | ++coro_nready; |
|
|
1406 | |
1398 | UNLOCK; |
1407 | UNLOCK; |
|
|
1408 | |
|
|
1409 | if (hook) |
|
|
1410 | { |
|
|
1411 | dSP; |
|
|
1412 | |
|
|
1413 | ENTER; |
|
|
1414 | SAVETMPS; |
|
|
1415 | |
|
|
1416 | PUSHMARK (SP); |
|
|
1417 | PUTBACK; |
|
|
1418 | call_sv (hook, G_DISCARD); |
|
|
1419 | SPAGAIN; |
|
|
1420 | |
|
|
1421 | FREETMPS; |
|
|
1422 | LEAVE; |
|
|
1423 | } |
1399 | |
1424 | |
1400 | return 1; |
1425 | return 1; |
1401 | } |
1426 | } |
1402 | |
1427 | |
1403 | static int |
1428 | static int |
… | |
… | |
1685 | RETVAL = coro_state_destroy (aTHX_ SvSTATE (coro_sv)); |
1710 | RETVAL = coro_state_destroy (aTHX_ SvSTATE (coro_sv)); |
1686 | OUTPUT: |
1711 | OUTPUT: |
1687 | RETVAL |
1712 | RETVAL |
1688 | |
1713 | |
1689 | void |
1714 | void |
1690 | _exit (code) |
1715 | _exit (int code) |
1691 | int code |
|
|
1692 | PROTOTYPE: $ |
1716 | PROTOTYPE: $ |
1693 | CODE: |
1717 | CODE: |
1694 | _exit (code); |
1718 | _exit (code); |
1695 | |
1719 | |
1696 | int |
1720 | int |
… | |
… | |
1828 | |
1852 | |
1829 | BOOT: |
1853 | BOOT: |
1830 | { |
1854 | { |
1831 | int i; |
1855 | int i; |
1832 | |
1856 | |
|
|
1857 | av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); |
1833 | sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); |
1858 | sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); |
1834 | sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); |
1859 | sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); |
1835 | av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); |
|
|
1836 | |
1860 | |
1837 | coro_current = coro_get_sv (aTHX_ "Coro::current", FALSE); |
1861 | coro_current = coro_get_sv (aTHX_ "Coro::current", FALSE); |
1838 | SvREADONLY_on (coro_current); |
1862 | SvREADONLY_on (coro_current); |
1839 | |
1863 | |
1840 | coro_stash = gv_stashpv ("Coro", TRUE); |
1864 | coro_stash = gv_stashpv ("Coro", TRUE); |
… | |
… | |
1871 | _set_current (SV *current) |
1895 | _set_current (SV *current) |
1872 | PROTOTYPE: $ |
1896 | PROTOTYPE: $ |
1873 | CODE: |
1897 | CODE: |
1874 | SvREFCNT_dec (SvRV (coro_current)); |
1898 | SvREFCNT_dec (SvRV (coro_current)); |
1875 | SvRV_set (coro_current, SvREFCNT_inc (SvRV (current))); |
1899 | SvRV_set (coro_current, SvREFCNT_inc (SvRV (current))); |
|
|
1900 | |
|
|
1901 | void |
|
|
1902 | _set_readyhook (SV *hook) |
|
|
1903 | PROTOTYPE: $ |
|
|
1904 | CODE: |
|
|
1905 | LOCK; |
|
|
1906 | if (coro_readyhook) |
|
|
1907 | SvREFCNT_dec (coro_readyhook); |
|
|
1908 | coro_readyhook = SvOK (hook) ? newSVsv (hook) : 0; |
|
|
1909 | UNLOCK; |
1876 | |
1910 | |
1877 | int |
1911 | int |
1878 | prio (Coro::State coro, int newprio = 0) |
1912 | prio (Coro::State coro, int newprio = 0) |
1879 | ALIAS: |
1913 | ALIAS: |
1880 | nice = 1 |
1914 | nice = 1 |
… | |
… | |
2037 | PL_laststype = data->laststype; |
2071 | PL_laststype = data->laststype; |
2038 | PL_laststatval = data->laststatval; |
2072 | PL_laststatval = data->laststatval; |
2039 | PL_statcache = data->statcache; |
2073 | PL_statcache = data->statcache; |
2040 | } |
2074 | } |
2041 | |
2075 | |
|
|
2076 | |
|
|
2077 | MODULE = Coro::State PACKAGE = Coro::AnyEvent |
|
|
2078 | |
|
|
2079 | BOOT: |
|
|
2080 | sv_activity = coro_get_sv (aTHX_ "Coro::AnyEvent::ACTIVITY", TRUE); |
|
|
2081 | |
|
|
2082 | SV * |
|
|
2083 | _schedule () |
|
|
2084 | PROTOTYPE: @ |
|
|
2085 | CODE: |
|
|
2086 | { |
|
|
2087 | static int incede; |
|
|
2088 | fprintf (stderr, "_schedule\n");//D |
|
|
2089 | |
|
|
2090 | api_cede_notself (); |
|
|
2091 | |
|
|
2092 | ++incede; |
|
|
2093 | while (coro_nready >= incede && api_cede ()) |
|
|
2094 | ; |
|
|
2095 | |
|
|
2096 | sv_setsv (sv_activity, &PL_sv_undef); |
|
|
2097 | if (coro_nready >= incede) |
|
|
2098 | { |
|
|
2099 | PUSHMARK (SP); |
|
|
2100 | PUTBACK; |
|
|
2101 | fprintf (stderr, "call act %d >= %d\n", coro_nready, incede);//D |
|
|
2102 | call_pv ("Coro::AnyEvent::_activity", G_DISCARD | G_EVAL); |
|
|
2103 | SPAGAIN; |
|
|
2104 | } |
|
|
2105 | |
|
|
2106 | --incede; |
|
|
2107 | } |
|
|
2108 | |