… | |
… | |
167 | static size_t coro_stacksize = CORO_STACKSIZE; |
167 | static size_t coro_stacksize = CORO_STACKSIZE; |
168 | static struct CoroAPI coroapi; |
168 | static struct CoroAPI coroapi; |
169 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
169 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
170 | static JMPENV *main_top_env; |
170 | static JMPENV *main_top_env; |
171 | static HV *coro_state_stash, *coro_stash; |
171 | static HV *coro_state_stash, *coro_stash; |
172 | static volatile SV *coro_mortal; /* will be freed after next transfer */ |
172 | static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */ |
173 | |
173 | |
174 | static GV *irsgv; /* $/ */ |
174 | static GV *irsgv; /* $/ */ |
175 | static GV *stdoutgv; /* *STDOUT */ |
175 | static GV *stdoutgv; /* *STDOUT */ |
176 | static SV *rv_diehook; |
176 | static SV *rv_diehook; |
177 | static SV *rv_warnhook; |
177 | static SV *rv_warnhook; |
… | |
… | |
1208 | /* always use the TRANSFER macro */ |
1208 | /* always use the TRANSFER macro */ |
1209 | static void NOINLINE |
1209 | static void NOINLINE |
1210 | transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx) |
1210 | transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx) |
1211 | { |
1211 | { |
1212 | dSTACKLEVEL; |
1212 | dSTACKLEVEL; |
1213 | static volatile int has_throw; |
|
|
1214 | |
1213 | |
1215 | /* sometimes transfer is only called to set idle_sp */ |
1214 | /* sometimes transfer is only called to set idle_sp */ |
1216 | if (expect_false (!next)) |
1215 | if (expect_false (!next)) |
1217 | { |
1216 | { |
1218 | ((coro_cctx *)prev)->idle_sp = STACKLEVEL; |
1217 | ((coro_cctx *)prev)->idle_sp = STACKLEVEL; |
1219 | assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */ |
1218 | assert (((coro_cctx *)prev)->idle_te = PL_top_env); /* just for the side-effect when asserts are enabled */ |
1220 | } |
1219 | } |
1221 | else if (expect_true (prev != next)) |
1220 | else if (expect_true (prev != next)) |
1222 | { |
1221 | { |
|
|
1222 | static volatile int has_throw; |
1223 | coro_cctx *prev__cctx; |
1223 | coro_cctx *prev__cctx; |
1224 | |
1224 | |
1225 | if (expect_false (prev->flags & CF_NEW)) |
1225 | if (expect_false (prev->flags & CF_NEW)) |
1226 | { |
1226 | { |
1227 | /* create a new empty context */ |
1227 | /* create a new empty context */ |
… | |
… | |
1834 | ta.next = 0; |
1834 | ta.next = 0; |
1835 | break; |
1835 | break; |
1836 | |
1836 | |
1837 | case 1: |
1837 | case 1: |
1838 | if (items != 2) |
1838 | if (items != 2) |
1839 | croak ("Coro::State::transfer (prev,next) expects two arguments, not %d", items); |
1839 | croak ("Coro::State::transfer (prev, next) expects two arguments, not %d", items); |
1840 | |
1840 | |
1841 | prepare_transfer (aTHX_ &ta, ST (0), ST (1)); |
1841 | prepare_transfer (aTHX_ &ta, ST (0), ST (1)); |
1842 | break; |
1842 | break; |
1843 | |
1843 | |
1844 | case 2: |
1844 | case 2: |
… | |
… | |
2007 | CODE: |
2007 | CODE: |
2008 | struct coro *coro = SvSTATE (coro_current); |
2008 | struct coro *coro = SvSTATE (coro_current); |
2009 | coro->cctx->idle_sp = 0; |
2009 | coro->cctx->idle_sp = 0; |
2010 | |
2010 | |
2011 | void |
2011 | void |
2012 | throw (Coro::State self, SV *throw = &PL_sv_undef) |
|
|
2013 | PROTOTYPE: $;$ |
|
|
2014 | CODE: |
|
|
2015 | SvREFCNT_dec (self->throw); |
|
|
2016 | self->throw = SvOK (throw) ? newSVsv (throw) : 0; |
|
|
2017 | |
|
|
2018 | void |
|
|
2019 | swap_defsv (Coro::State self) |
2012 | swap_defsv (Coro::State self) |
2020 | PROTOTYPE: $ |
2013 | PROTOTYPE: $ |
2021 | ALIAS: |
2014 | ALIAS: |
2022 | swap_defav = 1 |
2015 | swap_defav = 1 |
2023 | CODE: |
2016 | CODE: |
… | |
… | |
2126 | CODE: |
2119 | CODE: |
2127 | RETVAL = coro_nready; |
2120 | RETVAL = coro_nready; |
2128 | OUTPUT: |
2121 | OUTPUT: |
2129 | RETVAL |
2122 | RETVAL |
2130 | |
2123 | |
|
|
2124 | void |
|
|
2125 | throw (Coro::State self, SV *throw = &PL_sv_undef) |
|
|
2126 | PROTOTYPE: $;$ |
|
|
2127 | CODE: |
|
|
2128 | SvREFCNT_dec (self->throw); |
|
|
2129 | self->throw = SvOK (throw) ? newSVsv (throw) : 0; |
|
|
2130 | |
2131 | # for async_pool speedup |
2131 | # for async_pool speedup |
2132 | void |
2132 | void |
2133 | _pool_1 (SV *cb) |
2133 | _pool_1 (SV *cb) |
2134 | CODE: |
2134 | CODE: |
2135 | { |
2135 | { |