… | |
… | |
23 | #include "libev/ev.c" |
23 | #include "libev/ev.c" |
24 | |
24 | |
25 | #ifndef _WIN32 |
25 | #ifndef _WIN32 |
26 | # include <pthread.h> |
26 | # include <pthread.h> |
27 | #endif |
27 | #endif |
|
|
28 | |
|
|
29 | /* 5.10.0 */ |
|
|
30 | #ifndef SvREFCNT_inc_NN |
|
|
31 | # define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) |
|
|
32 | #endif |
|
|
33 | |
|
|
34 | #if __GNUC__ >= 3 |
|
|
35 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
36 | #else |
|
|
37 | # define expect(expr,value) (expr) |
|
|
38 | #endif |
|
|
39 | |
|
|
40 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
41 | #define expect_true(expr) expect ((expr) != 0, 1) |
28 | |
42 | |
29 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
43 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) |
30 | |
44 | |
31 | #define WFLAG_KEEPALIVE 1 |
45 | #define WFLAG_KEEPALIVE 1 |
32 | |
46 | |
… | |
… | |
191 | } |
205 | } |
192 | |
206 | |
193 | return rv; |
207 | return rv; |
194 | } |
208 | } |
195 | |
209 | |
196 | static SV *sv_events_cache; |
210 | static SV *sv_self_cache, *sv_events_cache; |
197 | |
211 | |
198 | static void |
212 | static void |
199 | e_cb (EV_P_ ev_watcher *w, int revents) |
213 | e_cb (EV_P_ ev_watcher *w, int revents) |
200 | { |
214 | { |
201 | dSP; |
215 | dSP; |
202 | I32 mark = SP - PL_stack_base; |
216 | I32 mark = SP - PL_stack_base; |
203 | SV *sv_self, *sv_events; |
217 | SV *sv_self, *sv_events; |
204 | |
218 | |
|
|
219 | if (expect_true (sv_self_cache)) |
|
|
220 | { |
|
|
221 | sv_self = sv_self_cache; sv_self_cache = 0; |
|
|
222 | SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); |
|
|
223 | } |
|
|
224 | else |
|
|
225 | { |
205 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
226 | sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ |
|
|
227 | SvREADONLY_on (sv_self); |
|
|
228 | } |
206 | |
229 | |
207 | if (sv_events_cache) |
230 | if (expect_true (sv_events_cache)) |
208 | { |
231 | { |
209 | sv_events = sv_events_cache; sv_events_cache = 0; |
232 | sv_events = sv_events_cache; sv_events_cache = 0; |
210 | SvIV_set (sv_events, revents); |
233 | SvIV_set (sv_events, revents); |
211 | } |
234 | } |
212 | else |
235 | else |
|
|
236 | { |
213 | sv_events = newSViv (revents); |
237 | sv_events = newSViv (revents); |
|
|
238 | SvREADONLY_on (sv_events); |
|
|
239 | } |
214 | |
240 | |
215 | PUSHMARK (SP); |
241 | PUSHMARK (SP); |
216 | EXTEND (SP, 2); |
242 | EXTEND (SP, 2); |
217 | PUSHs (sv_self); |
243 | PUSHs (sv_self); |
218 | PUSHs (sv_events); |
244 | PUSHs (sv_events); |
219 | |
245 | |
220 | PUTBACK; |
246 | PUTBACK; |
221 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
247 | call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); |
222 | |
248 | |
|
|
249 | if (expect_false (sv_self_cache)) |
223 | SvREFCNT_dec (sv_self); |
250 | SvREFCNT_dec (sv_self); |
|
|
251 | else |
|
|
252 | { |
|
|
253 | SvREFCNT_dec (SvRV (sv_self)); |
|
|
254 | SvRV_set (sv_self, &PL_sv_undef); |
|
|
255 | sv_self_cache = sv_self; |
|
|
256 | } |
224 | |
257 | |
225 | if (sv_events_cache) |
258 | if (expect_false (sv_events_cache)) |
226 | SvREFCNT_dec (sv_events); |
259 | SvREFCNT_dec (sv_events); |
227 | else |
260 | else |
228 | sv_events_cache = sv_events; |
261 | sv_events_cache = sv_events; |
229 | |
262 | |
230 | if (SvTRUE (ERRSV)) |
263 | if (SvTRUE (ERRSV)) |