… | |
… | |
170 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
170 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
171 | static JMPENV *main_top_env; |
171 | static JMPENV *main_top_env; |
172 | static HV *coro_state_stash, *coro_stash; |
172 | static HV *coro_state_stash, *coro_stash; |
173 | static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */ |
173 | static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */ |
174 | |
174 | |
|
|
175 | static AV *av_destroy; /* destruction queue */ |
|
|
176 | static SV *sv_manager; /* the manager coro */ |
|
|
177 | |
175 | static GV *irsgv; /* $/ */ |
178 | static GV *irsgv; /* $/ */ |
176 | static GV *stdoutgv; /* *STDOUT */ |
179 | static GV *stdoutgv; /* *STDOUT */ |
177 | static SV *rv_diehook; |
180 | static SV *rv_diehook; |
178 | static SV *rv_warnhook; |
181 | static SV *rv_warnhook; |
179 | static HV *hv_sig; /* %SIG */ |
182 | static HV *hv_sig; /* %SIG */ |
180 | |
183 | |
181 | /* async_pool helper stuff */ |
184 | /* async_pool helper stuff */ |
182 | static SV *sv_pool_rss; |
185 | static SV *sv_pool_rss; |
183 | static SV *sv_pool_size; |
186 | static SV *sv_pool_size; |
184 | static SV *sv_async_pool_idle; |
187 | static SV *sv_async_pool_idle; /* description string */ |
185 | static AV *av_async_pool; |
188 | static AV *av_async_pool; /* idle pool */ |
186 | static SV *sv_Coro; |
189 | static SV *sv_Coro; /* class string */ |
187 | static CV *cv_pool_handler; |
190 | static CV *cv_pool_handler; |
188 | static CV *cv_coro_state_new; |
191 | static CV *cv_coro_state_new; |
189 | |
192 | |
190 | /* Coro::AnyEvent */ |
193 | /* Coro::AnyEvent */ |
191 | static SV *sv_activity; |
194 | static SV *sv_activity; |
… | |
… | |
832 | |
835 | |
833 | static int |
836 | static int |
834 | slf_check_nop (pTHX_ struct CoroSLF *frame) |
837 | slf_check_nop (pTHX_ struct CoroSLF *frame) |
835 | { |
838 | { |
836 | return 0; |
839 | return 0; |
|
|
840 | } |
|
|
841 | |
|
|
842 | static int |
|
|
843 | slf_check_repeat (pTHX_ struct CoroSLF *frame) |
|
|
844 | { |
|
|
845 | return 1; |
837 | } |
846 | } |
838 | |
847 | |
839 | static UNOP coro_setup_op; |
848 | static UNOP coro_setup_op; |
840 | |
849 | |
841 | static void NOINLINE /* noinline to keep it out of the transfer fast path */ |
850 | static void NOINLINE /* noinline to keep it out of the transfer fast path */ |
… | |
… | |
1763 | if (coro->flags & CF_RUNNING) |
1772 | if (coro->flags & CF_RUNNING) |
1764 | PL_runops = RUNOPS_DEFAULT; |
1773 | PL_runops = RUNOPS_DEFAULT; |
1765 | else |
1774 | else |
1766 | coro->slot->runops = RUNOPS_DEFAULT; |
1775 | coro->slot->runops = RUNOPS_DEFAULT; |
1767 | } |
1776 | } |
|
|
1777 | } |
|
|
1778 | |
|
|
1779 | static void |
|
|
1780 | coro_call_on_destroy (pTHX_ struct coro *coro) |
|
|
1781 | { |
|
|
1782 | SV **on_destroyp = hv_fetch (coro->hv, "_on_destroy", sizeof ("_on_destroy") - 1, 0); |
|
|
1783 | SV **statusp = hv_fetch (coro->hv, "_status", sizeof ("_status") - 1, 0); |
|
|
1784 | |
|
|
1785 | if (on_destroyp) |
|
|
1786 | { |
|
|
1787 | AV *on_destroy = (AV *)SvRV (*on_destroyp); |
|
|
1788 | |
|
|
1789 | while (AvFILLp (on_destroy) >= 0) |
|
|
1790 | { |
|
|
1791 | dSP; /* don't disturb outer sp */ |
|
|
1792 | SV *cb = av_pop (on_destroy); |
|
|
1793 | |
|
|
1794 | PUSHMARK (SP); |
|
|
1795 | |
|
|
1796 | if (statusp) |
|
|
1797 | { |
|
|
1798 | int i; |
|
|
1799 | AV *status = (AV *)SvRV (*statusp); |
|
|
1800 | EXTEND (SP, AvFILLp (status) + 1); |
|
|
1801 | |
|
|
1802 | for (i = 0; i <= AvFILLp (status); ++i) |
|
|
1803 | PUSHs (AvARRAY (status)[i]); |
|
|
1804 | } |
|
|
1805 | |
|
|
1806 | PUTBACK; |
|
|
1807 | call_sv (sv_2mortal (cb), G_VOID | G_DISCARD); |
|
|
1808 | } |
|
|
1809 | } |
|
|
1810 | } |
|
|
1811 | |
|
|
1812 | static void |
|
|
1813 | slf_init_terminate (pTHX_ struct CoroSLF *frame, CV *cv, SV **arg, int items) |
|
|
1814 | { |
|
|
1815 | int i; |
|
|
1816 | HV *hv = (HV *)SvRV (coro_current); |
|
|
1817 | AV *av = newAV (); |
|
|
1818 | |
|
|
1819 | av_extend (av, items - 1); |
|
|
1820 | for (i = 0; i < items; ++i) |
|
|
1821 | av_push (av, SvREFCNT_inc_NN (arg [i])); |
|
|
1822 | |
|
|
1823 | hv_store (hv, "_status", sizeof ("_status") - 1, newRV_noinc ((SV *)av), 0); |
|
|
1824 | |
|
|
1825 | av_push (av_destroy, (SV *)newRV_inc ((SV *)hv)); /* RVinc for perl */ |
|
|
1826 | api_ready (aTHX_ sv_manager); |
|
|
1827 | |
|
|
1828 | frame->prepare = prepare_schedule; |
|
|
1829 | frame->check = slf_check_repeat; |
1768 | } |
1830 | } |
1769 | |
1831 | |
1770 | /*****************************************************************************/ |
1832 | /*****************************************************************************/ |
1771 | /* async pool handler */ |
1833 | /* async pool handler */ |
1772 | |
1834 | |
… | |
… | |
2996 | |
3058 | |
2997 | BOOT: |
3059 | BOOT: |
2998 | { |
3060 | { |
2999 | int i; |
3061 | int i; |
3000 | |
3062 | |
3001 | av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); |
|
|
3002 | sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); |
3063 | sv_pool_rss = coro_get_sv (aTHX_ "Coro::POOL_RSS" , TRUE); |
3003 | sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); |
3064 | sv_pool_size = coro_get_sv (aTHX_ "Coro::POOL_SIZE" , TRUE); |
3004 | cv_coro_run = get_cv ( "Coro::_terminate", GV_ADD); |
3065 | cv_coro_run = get_cv ( "Coro::_terminate", GV_ADD); |
3005 | cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); |
3066 | cv_coro_terminate = get_cv ( "Coro::terminate" , GV_ADD); |
3006 | coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current); |
3067 | coro_current = coro_get_sv (aTHX_ "Coro::current" , FALSE); SvREADONLY_on (coro_current); |
|
|
3068 | av_async_pool = coro_get_av (aTHX_ "Coro::async_pool", TRUE); |
|
|
3069 | av_destroy = coro_get_av (aTHX_ "Coro::destroy" , TRUE); |
|
|
3070 | sv_manager = coro_get_sv (aTHX_ "Coro::manager" , TRUE); |
3007 | |
3071 | |
3008 | sv_async_pool_idle = newSVpv ("[async pool idle]", 0); SvREADONLY_on (sv_async_pool_idle); |
3072 | sv_async_pool_idle = newSVpv ("[async pool idle]", 0); SvREADONLY_on (sv_async_pool_idle); |
3009 | sv_Coro = newSVpv ("Coro", 0); SvREADONLY_on (sv_Coro); |
3073 | sv_Coro = newSVpv ("Coro", 0); SvREADONLY_on (sv_Coro); |
3010 | cv_pool_handler = get_cv ("Coro::pool_handler", GV_ADD); SvREADONLY_on (cv_pool_handler); |
3074 | cv_pool_handler = get_cv ("Coro::pool_handler", GV_ADD); SvREADONLY_on (cv_pool_handler); |
3011 | cv_coro_state_new = get_cv ("Coro::State::new", 0); SvREADONLY_on (cv_coro_state_new); |
3075 | cv_coro_state_new = get_cv ("Coro::State::new", 0); SvREADONLY_on (cv_coro_state_new); |
… | |
… | |
3039 | SvREADONLY_on (sv); |
3103 | SvREADONLY_on (sv); |
3040 | } |
3104 | } |
3041 | } |
3105 | } |
3042 | |
3106 | |
3043 | void |
3107 | void |
|
|
3108 | terminate (...) |
|
|
3109 | CODE: |
|
|
3110 | CORO_EXECUTE_SLF_XS (slf_init_terminate); |
|
|
3111 | |
|
|
3112 | void |
3044 | schedule (...) |
3113 | schedule (...) |
3045 | CODE: |
3114 | CODE: |
3046 | CORO_EXECUTE_SLF_XS (slf_init_schedule); |
3115 | CORO_EXECUTE_SLF_XS (slf_init_schedule); |
3047 | |
3116 | |
3048 | void |
3117 | void |
… | |
… | |
3062 | |
3131 | |
3063 | void |
3132 | void |
3064 | cede_notself (...) |
3133 | cede_notself (...) |
3065 | CODE: |
3134 | CODE: |
3066 | CORO_EXECUTE_SLF_XS (slf_init_cede_notself); |
3135 | CORO_EXECUTE_SLF_XS (slf_init_cede_notself); |
|
|
3136 | |
|
|
3137 | void |
|
|
3138 | _cancel (Coro::State self) |
|
|
3139 | CODE: |
|
|
3140 | coro_state_destroy (aTHX_ self); |
|
|
3141 | coro_call_on_destroy (aTHX_ self); |
3067 | |
3142 | |
3068 | void |
3143 | void |
3069 | _set_current (SV *current) |
3144 | _set_current (SV *current) |
3070 | PROTOTYPE: $ |
3145 | PROTOTYPE: $ |
3071 | CODE: |
3146 | CODE: |