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.317 by root, Thu Nov 20 06:28:52 2008 UTC vs.
Revision 1.318 by root, Thu Nov 20 07:02:43 2008 UTC

170static AV *main_mainstack; /* used to differentiate between $main and others */ 170static AV *main_mainstack; /* used to differentiate between $main and others */
171static JMPENV *main_top_env; 171static JMPENV *main_top_env;
172static HV *coro_state_stash, *coro_stash; 172static HV *coro_state_stash, *coro_stash;
173static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */ 173static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */
174 174
175static AV *av_destroy; /* destruction queue */
176static SV *sv_manager; /* the manager coro */
177
175static GV *irsgv; /* $/ */ 178static GV *irsgv; /* $/ */
176static GV *stdoutgv; /* *STDOUT */ 179static GV *stdoutgv; /* *STDOUT */
177static SV *rv_diehook; 180static SV *rv_diehook;
178static SV *rv_warnhook; 181static SV *rv_warnhook;
179static HV *hv_sig; /* %SIG */ 182static HV *hv_sig; /* %SIG */
180 183
181/* async_pool helper stuff */ 184/* async_pool helper stuff */
182static SV *sv_pool_rss; 185static SV *sv_pool_rss;
183static SV *sv_pool_size; 186static SV *sv_pool_size;
184static SV *sv_async_pool_idle; 187static SV *sv_async_pool_idle; /* description string */
185static AV *av_async_pool; 188static AV *av_async_pool; /* idle pool */
186static SV *sv_Coro; 189static SV *sv_Coro; /* class string */
187static CV *cv_pool_handler; 190static CV *cv_pool_handler;
188static CV *cv_coro_state_new; 191static CV *cv_coro_state_new;
189 192
190/* Coro::AnyEvent */ 193/* Coro::AnyEvent */
191static SV *sv_activity; 194static SV *sv_activity;
832 835
833static int 836static int
834slf_check_nop (pTHX_ struct CoroSLF *frame) 837slf_check_nop (pTHX_ struct CoroSLF *frame)
835{ 838{
836 return 0; 839 return 0;
840}
841
842static int
843slf_check_repeat (pTHX_ struct CoroSLF *frame)
844{
845 return 1;
837} 846}
838 847
839static UNOP coro_setup_op; 848static UNOP coro_setup_op;
840 849
841static void NOINLINE /* noinline to keep it out of the transfer fast path */ 850static 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
1779static void
1780coro_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
1812static void
1813slf_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
2997BOOT: 3059BOOT:
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
3043void 3107void
3108terminate (...)
3109 CODE:
3110 CORO_EXECUTE_SLF_XS (slf_init_terminate);
3111
3112void
3044schedule (...) 3113schedule (...)
3045 CODE: 3114 CODE:
3046 CORO_EXECUTE_SLF_XS (slf_init_schedule); 3115 CORO_EXECUTE_SLF_XS (slf_init_schedule);
3047 3116
3048void 3117void
3062 3131
3063void 3132void
3064cede_notself (...) 3133cede_notself (...)
3065 CODE: 3134 CODE:
3066 CORO_EXECUTE_SLF_XS (slf_init_cede_notself); 3135 CORO_EXECUTE_SLF_XS (slf_init_cede_notself);
3136
3137void
3138_cancel (Coro::State self)
3139 CODE:
3140 coro_state_destroy (aTHX_ self);
3141 coro_call_on_destroy (aTHX_ self);
3067 3142
3068void 3143void
3069_set_current (SV *current) 3144_set_current (SV *current)
3070 PROTOTYPE: $ 3145 PROTOTYPE: $
3071 CODE: 3146 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines