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.123 by root, Sat Apr 25 14:12:48 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/* 5.6.x */
35#ifndef SvRV_set
36# define SvRV_set(a,b) SvRV ((a)) = (b)
37#endif
38
34#if __GNUC__ >= 3 39#if __GNUC__ >= 3
35# define expect(expr,value) __builtin_expect ((expr),(value)) 40# define expect(expr,value) __builtin_expect ((expr),(value))
36#else 41#else
37# define expect(expr,value) (expr) 42# define expect(expr,value) (expr)
38#endif 43#endif
41#define expect_true(expr) expect ((expr) != 0, 1) 46#define expect_true(expr) expect ((expr) != 0, 1)
42 47
43#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 48#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
44 49
45#define WFLAG_KEEPALIVE 1 50#define WFLAG_KEEPALIVE 1
51#define WFLAG_UNREFED 2 /* has been unref'ed */
46 52
47#define UNREF(w) \ 53#define UNREF(w) \
48 if (!((w)->e_flags & WFLAG_KEEPALIVE) \ 54 if (!((w)->e_flags & (WFLAG_KEEPALIVE | WFLAG_UNREFED)) \
49 && !ev_is_active (w)) \ 55 && ev_is_active (w)) \
56 { \
50 ev_unref (e_loop (w)); 57 ev_unref (e_loop (w)); \
58 (w)->e_flags |= WFLAG_UNREFED; \
59 }
51 60
52#define REF(w) \ 61#define REF(w) \
53 if (!((w)->e_flags & WFLAG_KEEPALIVE) \ 62 if ((w)->e_flags & WFLAG_UNREFED) \
54 && ev_is_active (w)) \ 63 { \
64 (w)->e_flags &= ~WFLAG_UNREFED; \
55 ev_ref (e_loop (w)); 65 ev_ref (e_loop (w)); \
66 }
56 67
57#define START(type,w) \ 68#define START(type,w) \
58 do { \ 69 do { \
70 ev_ ## type ## _start (e_loop (w), w); \
59 UNREF (w); \ 71 UNREF (w); \
60 ev_ ## type ## _start (e_loop (w), w); \
61 } while (0) 72 } while (0)
62 73
63#define STOP(type,w) \ 74#define STOP(type,w) \
64 do { \ 75 do { \
65 REF (w); \ 76 REF (w); \
214{ 225{
215 dSP; 226 dSP;
216 I32 mark = SP - PL_stack_base; 227 I32 mark = SP - PL_stack_base;
217 SV *sv_self, *sv_events; 228 SV *sv_self, *sv_events;
218 229
230 /* libev might have stopped the watcher */
231 if (expect_false (w->e_flags & WFLAG_UNREFED)
232 && !ev_is_active (w))
233 REF (w);
234
219 if (expect_true (sv_self_cache)) 235 if (expect_true (sv_self_cache))
220 { 236 {
221 sv_self = sv_self_cache; sv_self_cache = 0; 237 sv_self = sv_self_cache; sv_self_cache = 0;
222 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self)); 238 SvRV_set (sv_self, SvREFCNT_inc_NN (w->self));
223 } 239 }
244 PUSHs (sv_events); 260 PUSHs (sv_events);
245 261
246 PUTBACK; 262 PUTBACK;
247 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); 263 call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL);
248 264
249 if (expect_false (sv_self_cache)) 265 if (expect_false (SvREFCNT (sv_self) != 1 || sv_self_cache))
250 SvREFCNT_dec (sv_self); 266 SvREFCNT_dec (sv_self);
251 else 267 else
252 { 268 {
253 SvREFCNT_dec (SvRV (sv_self)); 269 SvREFCNT_dec (SvRV (sv_self));
254 SvRV_set (sv_self, &PL_sv_undef); 270 SvRV_set (sv_self, &PL_sv_undef);
255 sv_self_cache = sv_self; 271 sv_self_cache = sv_self;
256 } 272 }
257 273
258 if (expect_false (sv_events_cache)) 274 if (expect_false (SvREFCNT (sv_events) != 1 || sv_events_cache))
275 SvREFCNT_dec (sv_events);
276 else
277 sv_events_cache = sv_events;
278
279 if (expect_false (SvTRUE (ERRSV)))
280 {
281 SPAGAIN;
282 PUSHMARK (SP);
283 PUTBACK;
284 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
285 }
286
287 SP = PL_stack_base + mark;
288 PUTBACK;
289}
290
291static void
292e_once_cb (int revents, void *arg)
293{
294 dSP;
295 I32 mark = SP - PL_stack_base;
296 SV *sv_events;
297
298 if (sv_events_cache)
299 {
300 sv_events = sv_events_cache; sv_events_cache = 0;
301 SvIV_set (sv_events, revents);
302 }
303 else
304 sv_events = newSViv (revents);
305
306 PUSHMARK (SP);
307 XPUSHs (sv_events);
308
309 PUTBACK;
310 call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL);
311
312 SvREFCNT_dec ((SV *)arg);
313
314 if (sv_events_cache)
259 SvREFCNT_dec (sv_events); 315 SvREFCNT_dec (sv_events);
260 else 316 else
261 sv_events_cache = sv_events; 317 sv_events_cache = sv_events;
262 318
263 if (SvTRUE (ERRSV)) 319 if (SvTRUE (ERRSV))
270 326
271 SP = PL_stack_base + mark; 327 SP = PL_stack_base + mark;
272 PUTBACK; 328 PUTBACK;
273} 329}
274 330
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 331static ev_tstamp
316e_periodic_cb (ev_periodic *w, ev_tstamp now) 332e_periodic_cb (ev_periodic *w, ev_tstamp now)
317{ 333{
318 ev_tstamp retval; 334 ev_tstamp retval;
319 int count; 335 int count;
383 const_iv (EV_, MINPRI) 399 const_iv (EV_, MINPRI)
384 const_iv (EV_, MAXPRI) 400 const_iv (EV_, MAXPRI)
385 401
386 const_iv (EV_, UNDEF) 402 const_iv (EV_, UNDEF)
387 const_iv (EV_, NONE) 403 const_iv (EV_, NONE)
388 const_iv (EV_, TIMEOUT)
389 const_iv (EV_, READ) 404 const_iv (EV_, READ)
390 const_iv (EV_, WRITE) 405 const_iv (EV_, WRITE)
406 const_iv (EV_, IO)
407 const_iv (EV_, TIMEOUT)
408 const_iv (EV_, TIMER)
409 const_iv (EV_, PERIODIC)
391 const_iv (EV_, SIGNAL) 410 const_iv (EV_, SIGNAL)
411 const_iv (EV_, CHILD)
412 const_iv (EV_, STAT)
392 const_iv (EV_, IDLE) 413 const_iv (EV_, IDLE)
414 const_iv (EV_, PREPARE)
393 const_iv (EV_, CHECK) 415 const_iv (EV_, CHECK)
416 const_iv (EV_, EMBED)
417 const_iv (EV_, FORK)
418 const_iv (EV_, ASYNC)
419 const_iv (EV_, CUSTOM)
394 const_iv (EV_, ERROR) 420 const_iv (EV_, ERROR)
395 421
422 const_iv (EV, LOOP_NONBLOCK)
396 const_iv (EV, LOOP_ONESHOT) 423 const_iv (EV, LOOP_ONESHOT)
424
397 const_iv (EV, LOOP_NONBLOCK) 425 const_iv (EV, UNLOOP_CANCEL)
398 const_iv (EV, UNLOOP_ONE) 426 const_iv (EV, UNLOOP_ONE)
399 const_iv (EV, UNLOOP_ALL) 427 const_iv (EV, UNLOOP_ALL)
400 428
401 const_iv (EV, BACKEND_SELECT) 429 const_iv (EV, BACKEND_SELECT)
402 const_iv (EV, BACKEND_POLL) 430 const_iv (EV, BACKEND_POLL)
405 const_iv (EV, BACKEND_DEVPOLL) 433 const_iv (EV, BACKEND_DEVPOLL)
406 const_iv (EV, BACKEND_PORT) 434 const_iv (EV, BACKEND_PORT)
407 const_iv (EV, FLAG_AUTO) 435 const_iv (EV, FLAG_AUTO)
408 const_iv (EV, FLAG_NOENV) 436 const_iv (EV, FLAG_NOENV)
409 const_iv (EV, FLAG_FORKCHECK) 437 const_iv (EV, FLAG_FORKCHECK)
438
439 const_iv (EV_, VERSION_MAJOR)
440 const_iv (EV_, VERSION_MINOR)
410 }; 441 };
411 442
412 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 443 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
413 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 444 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
414 445
445 evapi.loop_destroy = ev_loop_destroy; 476 evapi.loop_destroy = ev_loop_destroy;
446 evapi.loop_fork = ev_loop_fork; 477 evapi.loop_fork = ev_loop_fork;
447 evapi.loop_count = ev_loop_count; 478 evapi.loop_count = ev_loop_count;
448 evapi.now = ev_now; 479 evapi.now = ev_now;
449 evapi.now_update = ev_now_update; 480 evapi.now_update = ev_now_update;
481 evapi.suspend = ev_suspend;
482 evapi.resume = ev_resume;
450 evapi.backend = ev_backend; 483 evapi.backend = ev_backend;
451 evapi.unloop = ev_unloop; 484 evapi.unloop = ev_unloop;
452 evapi.ref = ev_ref; 485 evapi.ref = ev_ref;
453 evapi.unref = ev_unref; 486 evapi.unref = ev_unref;
454 evapi.loop = ev_loop; 487 evapi.loop = ev_loop;
530 C_ARGS: evapi.default_loop 563 C_ARGS: evapi.default_loop
531 564
532void ev_now_update () 565void ev_now_update ()
533 C_ARGS: evapi.default_loop 566 C_ARGS: evapi.default_loop
534 567
568void ev_suspend ()
569 C_ARGS: evapi.default_loop
570
571void ev_resume ()
572 C_ARGS: evapi.default_loop
573
535unsigned int ev_backend () 574unsigned int ev_backend ()
536 C_ARGS: evapi.default_loop 575 C_ARGS: evapi.default_loop
537 576
538unsigned int ev_loop_count () 577unsigned int ev_loop_count ()
539 C_ARGS: evapi.default_loop 578 C_ARGS: evapi.default_loop
742 RETVAL = w->e_flags & WFLAG_KEEPALIVE; 781 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
743 new_value = new_value ? WFLAG_KEEPALIVE : 0; 782 new_value = new_value ? WFLAG_KEEPALIVE : 0;
744 783
745 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) 784 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
746 { 785 {
786 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
747 REF (w); 787 REF (w);
748 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
749 UNREF (w); 788 UNREF (w);
750 } 789 }
751} 790}
752 OUTPUT: 791 OUTPUT:
753 RETVAL 792 RETVAL
928 967
929void ev_timer_again (ev_timer *w) 968void ev_timer_again (ev_timer *w)
930 INIT: 969 INIT:
931 CHECK_REPEAT (w->repeat); 970 CHECK_REPEAT (w->repeat);
932 CODE: 971 CODE:
933 REF (w);
934 ev_timer_again (e_loop (w), w); 972 ev_timer_again (e_loop (w), w);
935 UNREF (w); 973 UNREF (w);
936 974
937void DESTROY (ev_timer *w) 975void DESTROY (ev_timer *w)
938 CODE: 976 CODE:
957 CODE: 995 CODE:
958 STOP (periodic, w); 996 STOP (periodic, w);
959 997
960void ev_periodic_again (ev_periodic *w) 998void ev_periodic_again (ev_periodic *w)
961 CODE: 999 CODE:
962 REF (w);
963 ev_periodic_again (e_loop (w), w); 1000 ev_periodic_again (e_loop (w), w);
964 UNREF (w); 1001 UNREF (w);
965 1002
966void DESTROY (ev_periodic *w) 1003void DESTROY (ev_periodic *w)
967 CODE: 1004 CODE:
1250 1287
1251NV ev_now (struct ev_loop *loop) 1288NV ev_now (struct ev_loop *loop)
1252 1289
1253void ev_now_update (struct ev_loop *loop) 1290void ev_now_update (struct ev_loop *loop)
1254 1291
1292void ev_suspend (struct ev_loop *loop)
1293
1294void ev_resume (struct ev_loop *loop)
1295
1255void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) 1296void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1256 1297
1257void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) 1298void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1258 1299
1259unsigned int ev_backend (struct ev_loop *loop) 1300unsigned int ev_backend (struct ev_loop *loop)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines