… | |
… | |
81 | # ifndef IS_PADCONST |
81 | # ifndef IS_PADCONST |
82 | # define IS_PADCONST(v) 0 |
82 | # define IS_PADCONST(v) 0 |
83 | # endif |
83 | # endif |
84 | #endif |
84 | #endif |
85 | |
85 | |
|
|
86 | /* 5.11 */ |
|
|
87 | #ifndef CxHASARGS |
|
|
88 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
|
|
89 | #endif |
|
|
90 | |
|
|
91 | /* 5.10.0 */ |
|
|
92 | #ifndef SvREFCNT_inc_NN |
|
|
93 | # define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) |
|
|
94 | #endif |
|
|
95 | |
86 | /* 5.8.8 */ |
96 | /* 5.8.8 */ |
87 | #ifndef GV_NOTQUAL |
97 | #ifndef GV_NOTQUAL |
88 | # define GV_NOTQUAL 0 |
98 | # define GV_NOTQUAL 0 |
89 | #endif |
99 | #endif |
90 | #ifndef newSV |
100 | #ifndef newSV |
91 | # define newSV(l) NEWSV(0,l) |
101 | # define newSV(l) NEWSV(0,l) |
92 | #endif |
|
|
93 | #ifndef SvREFCNT_inc_NN |
|
|
94 | # define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) |
|
|
95 | #endif |
|
|
96 | |
|
|
97 | /* 5.11 */ |
|
|
98 | #ifndef CxHASARGS |
|
|
99 | # define CxHASARGS(cx) (cx)->blk_sub.hasargs |
|
|
100 | #endif |
102 | #endif |
101 | |
103 | |
102 | /* 5.8.7 */ |
104 | /* 5.8.7 */ |
103 | #ifndef SvRV_set |
105 | #ifndef SvRV_set |
104 | # define SvRV_set(s,v) SvRV(s) = (v) |
106 | # define SvRV_set(s,v) SvRV(s) = (v) |
… | |
… | |
165 | static size_t coro_stacksize = CORO_STACKSIZE; |
167 | static size_t coro_stacksize = CORO_STACKSIZE; |
166 | static struct CoroAPI coroapi; |
168 | static struct CoroAPI coroapi; |
167 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
169 | static AV *main_mainstack; /* used to differentiate between $main and others */ |
168 | static JMPENV *main_top_env; |
170 | static JMPENV *main_top_env; |
169 | static HV *coro_state_stash, *coro_stash; |
171 | static HV *coro_state_stash, *coro_stash; |
170 | static volatile SV *coro_mortal; /* will be freed after next transfer */ |
172 | static volatile SV *coro_mortal; /* will be freed/thrown after next transfer */ |
171 | |
173 | |
172 | static GV *irsgv; /* $/ */ |
174 | static GV *irsgv; /* $/ */ |
173 | static GV *stdoutgv; /* *STDOUT */ |
175 | static GV *stdoutgv; /* *STDOUT */ |
174 | static SV *rv_diehook; |
176 | static SV *rv_diehook; |
175 | static SV *rv_warnhook; |
177 | static SV *rv_warnhook; |
… | |
… | |
1206 | /* always use the TRANSFER macro */ |
1208 | /* always use the TRANSFER macro */ |
1207 | static void NOINLINE |
1209 | static void NOINLINE |
1208 | transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx) |
1210 | transfer (pTHX_ struct coro *prev, struct coro *next, int force_cctx) |
1209 | { |
1211 | { |
1210 | dSTACKLEVEL; |
1212 | dSTACKLEVEL; |
1211 | static volatile int has_throw; |
|
|
1212 | |
1213 | |
1213 | /* sometimes transfer is only called to set idle_sp */ |
1214 | /* sometimes transfer is only called to set idle_sp */ |
1214 | if (expect_false (!next)) |
1215 | if (expect_false (!next)) |
1215 | { |
1216 | { |
1216 | ((coro_cctx *)prev)->idle_sp = STACKLEVEL; |
1217 | ((coro_cctx *)prev)->idle_sp = STACKLEVEL; |
1217 | 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 */ |
1218 | } |
1219 | } |
1219 | else if (expect_true (prev != next)) |
1220 | else if (expect_true (prev != next)) |
1220 | { |
1221 | { |
|
|
1222 | static volatile int has_throw; |
1221 | coro_cctx *prev__cctx; |
1223 | coro_cctx *prev__cctx; |
1222 | |
1224 | |
1223 | if (expect_false (prev->flags & CF_NEW)) |
1225 | if (expect_false (prev->flags & CF_NEW)) |
1224 | { |
1226 | { |
1225 | /* create a new empty context */ |
1227 | /* create a new empty context */ |
… | |
… | |
1832 | ta.next = 0; |
1834 | ta.next = 0; |
1833 | break; |
1835 | break; |
1834 | |
1836 | |
1835 | case 1: |
1837 | case 1: |
1836 | if (items != 2) |
1838 | if (items != 2) |
1837 | 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); |
1838 | |
1840 | |
1839 | prepare_transfer (aTHX_ &ta, ST (0), ST (1)); |
1841 | prepare_transfer (aTHX_ &ta, ST (0), ST (1)); |
1840 | break; |
1842 | break; |
1841 | |
1843 | |
1842 | case 2: |
1844 | case 2: |
… | |
… | |
2005 | CODE: |
2007 | CODE: |
2006 | struct coro *coro = SvSTATE (coro_current); |
2008 | struct coro *coro = SvSTATE (coro_current); |
2007 | coro->cctx->idle_sp = 0; |
2009 | coro->cctx->idle_sp = 0; |
2008 | |
2010 | |
2009 | void |
2011 | void |
2010 | throw (Coro::State self, SV *throw = &PL_sv_undef) |
|
|
2011 | PROTOTYPE: $;$ |
|
|
2012 | CODE: |
|
|
2013 | SvREFCNT_dec (self->throw); |
|
|
2014 | self->throw = SvOK (throw) ? newSVsv (throw) : 0; |
|
|
2015 | |
|
|
2016 | void |
|
|
2017 | swap_defsv (Coro::State self) |
2012 | swap_defsv (Coro::State self) |
2018 | PROTOTYPE: $ |
2013 | PROTOTYPE: $ |
2019 | ALIAS: |
2014 | ALIAS: |
2020 | swap_defav = 1 |
2015 | swap_defav = 1 |
2021 | CODE: |
2016 | CODE: |
… | |
… | |
2124 | CODE: |
2119 | CODE: |
2125 | RETVAL = coro_nready; |
2120 | RETVAL = coro_nready; |
2126 | OUTPUT: |
2121 | OUTPUT: |
2127 | RETVAL |
2122 | RETVAL |
2128 | |
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 | |
2129 | # for async_pool speedup |
2131 | # for async_pool speedup |
2130 | void |
2132 | void |
2131 | _pool_1 (SV *cb) |
2133 | _pool_1 (SV *cb) |
2132 | CODE: |
2134 | CODE: |
2133 | { |
2135 | { |