ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.xs
(Generate patch)

Comparing EV/EV.xs (file contents):
Revision 1.117 by root, Wed Oct 29 14:12:34 2008 UTC vs.
Revision 1.124 by root, Mon Jun 29 18:46:52 2009 UTC

29/* 5.10.0 */ 29/* 5.10.0 */
30#ifndef SvREFCNT_inc_NN 30#ifndef SvREFCNT_inc_NN
31# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) 31# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv)
32#endif 32#endif
33 33
34#if __GNUC__ >= 3 34/* 5.6.x */
35# define expect(expr,value) __builtin_expect ((expr),(value)) 35#ifndef SvRV_set
36#else 36# define SvRV_set(a,b) SvRV ((a)) = (b)
37# define expect(expr,value) (expr)
38#endif 37#endif
39 38
40#define expect_false(expr) expect ((expr) != 0, 0)
41#define expect_true(expr) expect ((expr) != 0, 1)
42
43#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 39#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
44 40
45#define WFLAG_KEEPALIVE 1 41#define WFLAG_KEEPALIVE 1
42#define WFLAG_UNREFED 2 /* has been unref'ed */
46 43
47#define UNREF(w) \ 44#define UNREF(w) \
48 if (!((w)->e_flags & WFLAG_KEEPALIVE) \ 45 if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
49 && !ev_is_active (w)) \ 46 && ev_is_active (w)) \
47 { \
50 ev_unref (e_loop (w)); 48 ev_unref (e_loop (w)); \
49 (w)->e_flags |= WFLAG_UNREFED; \
50 }
51 51
52#define REF(w) \ 52#define REF(w) \
53 if (!((w)->e_flags & WFLAG_KEEPALIVE) \ 53 if ((w)->e_flags & WFLAG_UNREFED) \
54 && ev_is_active (w)) \ 54 { \
55 (w)->e_flags &= ~WFLAG_UNREFED; \
55 ev_ref (e_loop (w)); 56 ev_ref (e_loop (w)); \
57 }
56 58
57#define START(type,w) \ 59#define START(type,w) \
58 do { \ 60 do { \
61 ev_ ## type ## _start (e_loop (w), w); \
59 UNREF (w); \ 62 UNREF (w); \
60 ev_ ## type ## _start (e_loop (w), w); \
61 } while (0) 63 } while (0)
62 64
63#define STOP(type,w) \ 65#define STOP(type,w) \
64 do { \ 66 do { \
65 REF (w); \ 67 REF (w); \
214{ 216{
215 dSP; 217 dSP;
216 I32 mark = SP - PL_stack_base; 218 I32 mark = SP - PL_stack_base;
217 SV *sv_self, *sv_events; 219 SV *sv_self, *sv_events;
218 220
221 /* libev might have stopped the watcher */
222 if (expect_false (w->e_flags & WFLAG_UNREFED)
223 && !ev_is_active (w))
224 REF (w);
225
219 if (expect_true (sv_self_cache)) 226 if (expect_true (sv_self_cache))
220 { 227 {
221 sv_self = sv_self_cache; sv_self_cache = 0; 228 sv_self = sv_self_cache; sv_self_cache = 0;
222 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); 229 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
223 } 230 }
244 PUSHs (sv_events); 251 PUSHs (sv_events);
245 252
246 PUTBACK; 253 PUTBACK;
247 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 254 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
248 255
249 if (expect_false (sv_self_cache)) 256 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
250 SvREFCNT_dec (sv_self); 257 SvREFCNT_dec (sv_self);
251 else 258 else
252 { 259 {
253 SvREFCNT_dec (SvRV (sv_self)); 260 SvREFCNT_dec (SvRV (sv_self));
254 SvRV_set (sv_self, &PL_sv_undef); 261 SvRV_set (sv_self, &PL_sv_undef);
255 sv_self_cache = sv_self; 262 sv_self_cache = sv_self;
256 } 263 }
257 264
258 if (expect_false (sv_events_cache)) 265 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
266 SvREFCNT_dec (sv_events);
267 else
268 sv_events_cache = sv_events;
269
270 if (expect_false (SvTRUE (ERRSV)))
271 {
272 SPAGAIN;
273 PUSHMARK (SP);
274 PUTBACK;
275 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
276 }
277
278 SP = PL_stack_base + mark;
279 PUTBACK;
280}
281
282static void
283e_once_cb (int revents, void *arg)
284{
285 dSP;
286 I32 mark = SP - PL_stack_base;
287 SV *sv_events;
288
289 if (sv_events_cache)
290 {
291 sv_events = sv_events_cache; sv_events_cache = 0;
292 SvIV_set (sv_events, revents);
293 }
294 else
295 sv_events = newSViv (revents);
296
297 PUSHMARK (SP);
298 XPUSHs (sv_events);
299
300 PUTBACK;
301 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
302
303 SvREFCNT_dec ((SV *)arg);
304
305 if (sv_events_cache)
259 SvREFCNT_dec (sv_events); 306 SvREFCNT_dec (sv_events);
260 else 307 else
261 sv_events_cache = sv_events; 308 sv_events_cache = sv_events;
262 309
263 if (SvTRUE (ERRSV)) 310 if (SvTRUE (ERRSV))
270 317
271 SP = PL_stack_base + mark; 318 SP = PL_stack_base + mark;
272 PUTBACK; 319 PUTBACK;
273} 320}
274 321
275static void
276e_once_cb (int revents, void *arg)
277{
278 dSP;
279 I32 mark = SP - PL_stack_base;
280 SV *sv_events;
281
282 if (sv_events_cache)
283 {
284 sv_events = sv_events_cache; sv_events_cache = 0;
285 SvIV_set (sv_events, revents);
286 }
287 else
288 sv_events = newSViv (revents);
289
290 PUSHMARK (SP);
291 XPUSHs (sv_events);
292
293 PUTBACK;
294 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
295
296 SvREFCNT_dec ((SV *)arg);
297
298 if (sv_events_cache)
299 SvREFCNT_dec (sv_events);
300 else
301 sv_events_cache = sv_events;
302
303 if (SvTRUE (ERRSV))
304 {
305 SPAGAIN;
306 PUSHMARK (SP);
307 PUTBACK;
308 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
309 }
310
311 SP = PL_stack_base + mark;
312 PUTBACK;
313}
314
315static ev_tstamp 322static ev_tstamp
316e_periodic_cb (ev_periodic *w, ev_tstamp now) 323e_periodic_cb (ev_periodic *w, ev_tstamp now)
317{ 324{
318 ev_tstamp retval; 325 ev_tstamp retval;
319 int count; 326 int count;
383 const_iv (EV_, MINPRI) 390 const_iv (EV_, MINPRI)
384 const_iv (EV_, MAXPRI) 391 const_iv (EV_, MAXPRI)
385 392
386 const_iv (EV_, UNDEF) 393 const_iv (EV_, UNDEF)
387 const_iv (EV_, NONE) 394 const_iv (EV_, NONE)
388 const_iv (EV_, TIMEOUT)
389 const_iv (EV_, READ) 395 const_iv (EV_, READ)
390 const_iv (EV_, WRITE) 396 const_iv (EV_, WRITE)
397 const_iv (EV_, IO)
398 const_iv (EV_, TIMEOUT)
399 const_iv (EV_, TIMER)
400 const_iv (EV_, PERIODIC)
391 const_iv (EV_, SIGNAL) 401 const_iv (EV_, SIGNAL)
402 const_iv (EV_, CHILD)
403 const_iv (EV_, STAT)
392 const_iv (EV_, IDLE) 404 const_iv (EV_, IDLE)
405 const_iv (EV_, PREPARE)
393 const_iv (EV_, CHECK) 406 const_iv (EV_, CHECK)
407 const_iv (EV_, EMBED)
408 const_iv (EV_, FORK)
409 const_iv (EV_, ASYNC)
410 const_iv (EV_, CUSTOM)
394 const_iv (EV_, ERROR) 411 const_iv (EV_, ERROR)
395 412
413 const_iv (EV, LOOP_NONBLOCK)
396 const_iv (EV, LOOP_ONESHOT) 414 const_iv (EV, LOOP_ONESHOT)
415
397 const_iv (EV, LOOP_NONBLOCK) 416 const_iv (EV, UNLOOP_CANCEL)
398 const_iv (EV, UNLOOP_ONE) 417 const_iv (EV, UNLOOP_ONE)
399 const_iv (EV, UNLOOP_ALL) 418 const_iv (EV, UNLOOP_ALL)
400 419
401 const_iv (EV, BACKEND_SELECT) 420 const_iv (EV, BACKEND_SELECT)
402 const_iv (EV, BACKEND_POLL) 421 const_iv (EV, BACKEND_POLL)
405 const_iv (EV, BACKEND_DEVPOLL) 424 const_iv (EV, BACKEND_DEVPOLL)
406 const_iv (EV, BACKEND_PORT) 425 const_iv (EV, BACKEND_PORT)
407 const_iv (EV, FLAG_AUTO) 426 const_iv (EV, FLAG_AUTO)
408 const_iv (EV, FLAG_NOENV) 427 const_iv (EV, FLAG_NOENV)
409 const_iv (EV, FLAG_FORKCHECK) 428 const_iv (EV, FLAG_FORKCHECK)
429
430 const_iv (EV_, VERSION_MAJOR)
431 const_iv (EV_, VERSION_MINOR)
410 }; 432 };
411 433
412 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 434 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
413 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 435 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
414 436
445 evapi.loop_destroy = ev_loop_destroy; 467 evapi.loop_destroy = ev_loop_destroy;
446 evapi.loop_fork = ev_loop_fork; 468 evapi.loop_fork = ev_loop_fork;
447 evapi.loop_count = ev_loop_count; 469 evapi.loop_count = ev_loop_count;
448 evapi.now = ev_now; 470 evapi.now = ev_now;
449 evapi.now_update = ev_now_update; 471 evapi.now_update = ev_now_update;
472 evapi.suspend = ev_suspend;
473 evapi.resume = ev_resume;
450 evapi.backend = ev_backend; 474 evapi.backend = ev_backend;
451 evapi.unloop = ev_unloop; 475 evapi.unloop = ev_unloop;
452 evapi.ref = ev_ref; 476 evapi.ref = ev_ref;
453 evapi.unref = ev_unref; 477 evapi.unref = ev_unref;
454 evapi.loop = ev_loop; 478 evapi.loop = ev_loop;
530 C_ARGS: evapi.default_loop 554 C_ARGS: evapi.default_loop
531 555
532void ev_now_update () 556void ev_now_update ()
533 C_ARGS: evapi.default_loop 557 C_ARGS: evapi.default_loop
534 558
559void ev_suspend ()
560 C_ARGS: evapi.default_loop
561
562void ev_resume ()
563 C_ARGS: evapi.default_loop
564
535unsigned int ev_backend () 565unsigned int ev_backend ()
536 C_ARGS: evapi.default_loop 566 C_ARGS: evapi.default_loop
537 567
538unsigned int ev_loop_count () 568unsigned int ev_loop_count ()
539 C_ARGS: evapi.default_loop 569 C_ARGS: evapi.default_loop
742 RETVAL = w->e_flags & WFLAG_KEEPALIVE; 772 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
743 new_value = new_value ? WFLAG_KEEPALIVE : 0; 773 new_value = new_value ? WFLAG_KEEPALIVE : 0;
744 774
745 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) 775 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
746 { 776 {
777 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
747 REF (w); 778 REF (w);
748 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
749 UNREF (w); 779 UNREF (w);
750 } 780 }
751} 781}
752 OUTPUT: 782 OUTPUT:
753 RETVAL 783 RETVAL
928 958
929void ev_timer_again (ev_timer *w) 959void ev_timer_again (ev_timer *w)
930 INIT: 960 INIT:
931 CHECK_REPEAT (w->repeat); 961 CHECK_REPEAT (w->repeat);
932 CODE: 962 CODE:
933 REF (w);
934 ev_timer_again (e_loop (w), w); 963 ev_timer_again (e_loop (w), w);
935 UNREF (w); 964 UNREF (w);
936 965
937void DESTROY (ev_timer *w) 966void DESTROY (ev_timer *w)
938 CODE: 967 CODE:
957 CODE: 986 CODE:
958 STOP (periodic, w); 987 STOP (periodic, w);
959 988
960void ev_periodic_again (ev_periodic *w) 989void ev_periodic_again (ev_periodic *w)
961 CODE: 990 CODE:
962 REF (w);
963 ev_periodic_again (e_loop (w), w); 991 ev_periodic_again (e_loop (w), w);
964 UNREF (w); 992 UNREF (w);
965 993
966void DESTROY (ev_periodic *w) 994void DESTROY (ev_periodic *w)
967 CODE: 995 CODE:
1250 1278
1251NV ev_now (struct ev_loop *loop) 1279NV ev_now (struct ev_loop *loop)
1252 1280
1253void ev_now_update (struct ev_loop *loop) 1281void ev_now_update (struct ev_loop *loop)
1254 1282
1283void ev_suspend (struct ev_loop *loop)
1284
1285void ev_resume (struct ev_loop *loop)
1286
1255void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) 1287void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1256 1288
1257void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) 1289void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1258 1290
1259unsigned int ev_backend (struct ev_loop *loop) 1291unsigned int ev_backend (struct ev_loop *loop)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines