… | |
… | |
199 | |
199 | |
200 | #define VAR(name,type) type name; |
200 | #define VAR(name,type) type name; |
201 | # include "state.h" |
201 | # include "state.h" |
202 | #undef VAR |
202 | #undef VAR |
203 | |
203 | |
|
|
204 | /* statistics */ |
|
|
205 | int usecount; /* number of switches to this coro */ |
|
|
206 | |
204 | /* coro process data */ |
207 | /* coro process data */ |
205 | int prio; |
208 | int prio; |
206 | |
209 | |
207 | /* linked list */ |
210 | /* linked list */ |
208 | struct coro *next, *prev; |
211 | struct coro *next, *prev; |
… | |
… | |
307 | HV *stash; |
310 | HV *stash; |
308 | MAGIC *mg; |
311 | MAGIC *mg; |
309 | |
312 | |
310 | if (SvROK (coro)) |
313 | if (SvROK (coro)) |
311 | coro = SvRV (coro); |
314 | coro = SvRV (coro); |
|
|
315 | |
|
|
316 | if (SvTYPE (coro) != SVt_PVHV) |
|
|
317 | croak ("Coro::State object required"); |
312 | |
318 | |
313 | stash = SvSTASH (coro); |
319 | stash = SvSTASH (coro); |
314 | if (stash != coro_stash && stash != coro_state_stash) |
320 | if (stash != coro_stash && stash != coro_state_stash) |
315 | { |
321 | { |
316 | /* very slow, but rare, check */ |
322 | /* very slow, but rare, check */ |
… | |
… | |
576 | Safefree (PL_retstack); |
582 | Safefree (PL_retstack); |
577 | #endif |
583 | #endif |
578 | } |
584 | } |
579 | |
585 | |
580 | static size_t |
586 | static size_t |
581 | coro_rss (struct coro *coro) |
587 | coro_rss (pTHX_ struct coro *coro) |
582 | { |
588 | { |
583 | size_t rss = sizeof (coro); |
589 | size_t rss = sizeof (coro); |
584 | |
590 | |
585 | if (coro->mainstack) |
591 | if (coro->mainstack) |
586 | { |
592 | { |
… | |
… | |
1014 | prev->cctx = 0; |
1020 | prev->cctx = 0; |
1015 | |
1021 | |
1016 | cctx_put (prev__cctx); |
1022 | cctx_put (prev__cctx); |
1017 | } |
1023 | } |
1018 | |
1024 | |
|
|
1025 | ++next->usecount; |
|
|
1026 | |
1019 | if (!next->cctx) |
1027 | if (!next->cctx) |
1020 | next->cctx = cctx_get (aTHX); |
1028 | next->cctx = cctx_get (aTHX); |
1021 | |
1029 | |
1022 | if (prev__cctx != next->cctx) |
1030 | if (prev__cctx != next->cctx) |
1023 | { |
1031 | { |
… | |
… | |
1553 | save_perl (aTHX_ coro); |
1561 | save_perl (aTHX_ coro); |
1554 | load_perl (aTHX_ &temp); |
1562 | load_perl (aTHX_ &temp); |
1555 | } |
1563 | } |
1556 | } |
1564 | } |
1557 | } |
1565 | } |
1558 | |
1566 | |
1559 | SV * |
1567 | SV * |
1560 | is_ready (Coro::State coro) |
1568 | is_ready (Coro::State coro) |
1561 | PROTOTYPE: $ |
1569 | PROTOTYPE: $ |
1562 | ALIAS: |
1570 | ALIAS: |
1563 | is_ready = CF_READY |
1571 | is_ready = CF_READY |
… | |
… | |
1610 | RETVAL |
1618 | RETVAL |
1611 | |
1619 | |
1612 | IV |
1620 | IV |
1613 | rss (Coro::State coro) |
1621 | rss (Coro::State coro) |
1614 | PROTOTYPE: $ |
1622 | PROTOTYPE: $ |
|
|
1623 | ALIAS: |
|
|
1624 | usecount = 1 |
1615 | CODE: |
1625 | CODE: |
1616 | RETVAL = coro_rss (coro); |
1626 | switch (ix) |
|
|
1627 | { |
|
|
1628 | case 0: RETVAL = coro_rss (aTHX_ coro); break; |
|
|
1629 | case 1: RETVAL = coro->usecount; break; |
|
|
1630 | } |
1617 | OUTPUT: |
1631 | OUTPUT: |
1618 | RETVAL |
1632 | RETVAL |
1619 | |
1633 | |
1620 | |
1634 | |
1621 | MODULE = Coro::State PACKAGE = Coro |
1635 | MODULE = Coro::State PACKAGE = Coro |
… | |
… | |
1744 | { |
1758 | { |
1745 | struct coro *coro = SvSTATE (coro_current); |
1759 | struct coro *coro = SvSTATE (coro_current); |
1746 | |
1760 | |
1747 | sv_setsv (cb, &PL_sv_undef); |
1761 | sv_setsv (cb, &PL_sv_undef); |
1748 | |
1762 | |
1749 | if (coro_rss (coro) > SvIV (sv_pool_rss) |
1763 | if (coro_rss (aTHX_ coro) > SvIV (sv_pool_rss) |
1750 | || av_len (av_async_pool) + 1 >= SvIV (sv_pool_size)) |
1764 | || av_len (av_async_pool) + 1 >= SvIV (sv_pool_size)) |
1751 | croak ("\3terminate\2\n"); |
1765 | croak ("\3terminate\2\n"); |
1752 | |
1766 | |
1753 | av_clear (GvAV (PL_defgv)); |
1767 | av_clear (GvAV (PL_defgv)); |
1754 | hv_store ((HV *)SvRV (coro_current), "desc", sizeof ("desc") - 1, |
1768 | hv_store ((HV *)SvRV (coro_current), "desc", sizeof ("desc") - 1, |