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

Comparing EV/EV.xs (file contents):
Revision 1.87 by root, Fri Dec 7 18:09:38 2007 UTC vs.
Revision 1.91 by root, Thu Dec 20 07:12:57 2007 UTC

28#define WFLAG_KEEPALIVE 1 28#define WFLAG_KEEPALIVE 1
29 29
30#define UNREF(w) \ 30#define UNREF(w) \
31 if (!((w)->flags & WFLAG_KEEPALIVE) \ 31 if (!((w)->flags & WFLAG_KEEPALIVE) \
32 && !ev_is_active (w)) \ 32 && !ev_is_active (w)) \
33 ev_unref (); 33 ev_unref (w->loop);
34 34
35#define REF(w) \ 35#define REF(w) \
36 if (!((w)->flags & WFLAG_KEEPALIVE) \ 36 if (!((w)->flags & WFLAG_KEEPALIVE) \
37 && ev_is_active (w)) \ 37 && ev_is_active (w)) \
38 ev_ref (); 38 ev_ref (w->loop);
39 39
40#define START(type,w) \ 40#define START(type,w) \
41 do { \ 41 do { \
42 UNREF (w); \ 42 UNREF (w); \
43 ev_ ## type ## _start (w); \ 43 ev_ ## type ## _start (w->loop, w); \
44 } while (0) 44 } while (0)
45 45
46#define STOP(type,w) \ 46#define STOP(type,w) \
47 do { \ 47 do { \
48 REF (w); \ 48 REF (w); \
49 ev_ ## type ## _stop (w); \ 49 ev_ ## type ## _stop (w->loop, w); \
50 } while (0) 50 } while (0)
51 51
52#define RESET(type,w,seta) \ 52#define RESET(type,w,seta) \
53 do { \ 53 do { \
54 int active = ev_is_active (w); \ 54 int active = ev_is_active (w); \
101} 101}
102 102
103///////////////////////////////////////////////////////////////////////////// 103/////////////////////////////////////////////////////////////////////////////
104// Event 104// Event
105 105
106static void e_cb (ev_watcher *w, int revents); 106static void e_cb (EV_P_ ev_watcher *w, int revents);
107 107
108static int 108static int
109sv_fileno (SV *fh) 109sv_fileno (SV *fh)
110{ 110{
111 SvGETMAGIC (fh); 111 SvGETMAGIC (fh);
132 132
133 w = (ev_watcher *)SvPVX (self); 133 w = (ev_watcher *)SvPVX (self);
134 134
135 ev_init (w, e_cb); 135 ev_init (w, e_cb);
136 136
137 w->loop = EV_DEFAULT;
137 w->flags = WFLAG_KEEPALIVE; 138 w->flags = WFLAG_KEEPALIVE;
138 w->data = 0; 139 w->data = 0;
139 w->fh = 0; 140 w->fh = 0;
140 w->cb_sv = newSVsv (cb_sv); 141 w->cb_sv = newSVsv (cb_sv);
141 w->self = self; 142 w->self = self;
171} 172}
172 173
173static SV *sv_events_cache; 174static SV *sv_events_cache;
174 175
175static void 176static void
176e_cb (ev_watcher *w, int revents) 177e_cb (EV_P_ ev_watcher *w, int revents)
177{ 178{
178 dSP; 179 dSP;
179 I32 mark = SP - PL_stack_base; 180 I32 mark = SP - PL_stack_base;
180 SV *sv_self, *sv_events; 181 SV *sv_self, *sv_events;
181 182
365 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 366 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
366 stash_check = gv_stashpv ("EV::Check" , 1); 367 stash_check = gv_stashpv ("EV::Check" , 1);
367 stash_child = gv_stashpv ("EV::Child" , 1); 368 stash_child = gv_stashpv ("EV::Child" , 1);
368 stash_embed = gv_stashpv ("EV::Embed" , 1); 369 stash_embed = gv_stashpv ("EV::Embed" , 1);
369 stash_stat = gv_stashpv ("EV::Stat" , 1); 370 stash_stat = gv_stashpv ("EV::Stat" , 1);
371 stash_fork = gv_stashpv ("EV::Fork" , 1);
370 372
371 { 373 {
372 SV *sv = perl_get_sv ("EV::API", TRUE); 374 SV *sv = perl_get_sv ("EV::API", TRUE);
373 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 375 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
374 376
375 /* the poor man's shared library emulator */ 377 /* the poor man's shared library emulator */
376 evapi.ver = EV_API_VERSION; 378 evapi.ver = EV_API_VERSION;
377 evapi.rev = EV_API_REVISION; 379 evapi.rev = EV_API_REVISION;
378 evapi.sv_fileno = sv_fileno; 380 evapi.sv_fileno = sv_fileno;
379 evapi.sv_signum = sv_signum; 381 evapi.sv_signum = sv_signum;
382 evapi.supported_backends = ev_supported_backends ();
383 evapi.recommended_backends = ev_recommended_backends ();
384 evapi.embeddable_backends = ev_embeddable_backends ();
385 evapi.time = ev_time;
386 evapi.loop_new = ev_loop_new;
387 evapi.loop_destroy = ev_loop_destroy;
388 evapi.loop_fork = ev_loop_fork;
389 evapi.loop_count = ev_loop_count;
380 evapi.now = ev_now; 390 evapi.now = ev_now;
381 evapi.backend = ev_backend; 391 evapi.backend = ev_backend;
382 evapi.unloop = ev_unloop; 392 evapi.unloop = ev_unloop;
383 evapi.ref = ev_ref; 393 evapi.ref = ev_ref;
384 evapi.unref = ev_unref; 394 evapi.unref = ev_unref;
385 evapi.time = ev_time;
386 evapi.loop = ev_loop; 395 evapi.loop = ev_loop;
387 evapi.once = ev_once; 396 evapi.once = ev_once;
388 evapi.io_start = ev_io_start; 397 evapi.io_start = ev_io_start;
389 evapi.io_stop = ev_io_stop; 398 evapi.io_stop = ev_io_stop;
390 evapi.timer_start = ev_timer_start; 399 evapi.timer_start = ev_timer_start;
391 evapi.timer_stop = ev_timer_stop; 400 evapi.timer_stop = ev_timer_stop;
392 evapi.timer_again = ev_timer_again; 401 evapi.timer_again = ev_timer_again;
393 evapi.periodic_start = ev_periodic_start; 402 evapi.periodic_start = ev_periodic_start;
394 evapi.periodic_stop = ev_periodic_stop; 403 evapi.periodic_stop = ev_periodic_stop;
395 evapi.signal_start = ev_signal_start; 404 evapi.signal_start = ev_signal_start;
396 evapi.signal_stop = ev_signal_stop; 405 evapi.signal_stop = ev_signal_stop;
397 evapi.idle_start = ev_idle_start; 406 evapi.idle_start = ev_idle_start;
398 evapi.idle_stop = ev_idle_stop; 407 evapi.idle_stop = ev_idle_stop;
399 evapi.prepare_start = ev_prepare_start; 408 evapi.prepare_start = ev_prepare_start;
400 evapi.prepare_stop = ev_prepare_stop; 409 evapi.prepare_stop = ev_prepare_stop;
401 evapi.check_start = ev_check_start; 410 evapi.check_start = ev_check_start;
402 evapi.check_stop = ev_check_stop; 411 evapi.check_stop = ev_check_stop;
403 evapi.child_start = ev_child_start; 412 evapi.child_start = ev_child_start;
404 evapi.child_stop = ev_child_stop; 413 evapi.child_stop = ev_child_stop;
405 evapi.stat_start = ev_stat_start; 414 evapi.stat_start = ev_stat_start;
406 evapi.stat_stop = ev_stat_stop; 415 evapi.stat_stop = ev_stat_stop;
407 evapi.stat_stat = ev_stat_stat; 416 evapi.stat_stat = ev_stat_stat;
417 evapi.embed_start = ev_embed_start;
418 evapi.embed_stop = ev_embed_stop;
419 evapi.embed_sweep = ev_embed_sweep;
420 evapi.fork_start = ev_fork_start;
421 evapi.fork_stop = ev_fork_stop;
422 evapi.clear_pending = ev_clear_pending;
423 evapi.invoke = ev_invoke;
408 424
409 sv_setiv (sv, (IV)&evapi); 425 sv_setiv (sv, (IV)&evapi);
410 SvREADONLY_on (sv); 426 SvREADONLY_on (sv);
411 } 427 }
412#ifndef _WIN32 428#ifndef _WIN32
413 pthread_atfork (0, 0, ev_default_fork); 429 pthread_atfork (0, 0, ev_default_fork);
414#endif 430#endif
415} 431}
416 432
433SV *ev_default_loop (unsigned int flags = ev_supported_backends ())
434 CODE:
435{
436 evapi.default_loop = ev_default_loop (flags);
437 if (!evapi.default_loop)
438 XSRETURN_UNDEF;
439
440 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (ev_default_loop (flags)))),
441 gv_stashpv ("EV::Loop::Default", 1));
442}
443 OUTPUT:
444 RETVAL
445
446NV ev_time ()
447
417NV ev_now () 448NV ev_now ()
449 C_ARGS: evapi.default_loop
418 450
419unsigned int ev_backend () 451unsigned int ev_backend ()
420 452 C_ARGS: evapi.default_loop
421NV ev_time ()
422
423unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
424 453
425unsigned int ev_loop_count () 454unsigned int ev_loop_count ()
455 C_ARGS: evapi.default_loop
426 456
427void ev_loop (int flags = 0) 457void ev_loop (int flags = 0)
458 C_ARGS: evapi.default_loop, flags
428 459
429void ev_unloop (int how = 1) 460void ev_unloop (int how = 1)
461 C_ARGS: evapi.default_loop, how
462
463void ev_feed_fd_event (int fd, int revents = EV_NONE)
464 C_ARGS: evapi.default_loop, fd, revents
465
466void ev_feed_signal_event (SV *signal)
467 CODE:
468{
469 Signal signum = sv_signum (signal);
470 CHECK_SIG (signal, signum);
471
472 ev_feed_signal_event (evapi.default_loop, signum);
473}
430 474
431ev_io *io (SV *fh, int events, SV *cb) 475ev_io *io (SV *fh, int events, SV *cb)
432 ALIAS: 476 ALIAS:
433 io_ns = 1 477 io_ns = 1
434 CODE: 478 CODE:
516 ev_check_set (RETVAL); 560 ev_check_set (RETVAL);
517 if (!ix) START (check, RETVAL); 561 if (!ix) START (check, RETVAL);
518 OUTPUT: 562 OUTPUT:
519 RETVAL 563 RETVAL
520 564
565ev_fork *fork (SV *cb)
566 ALIAS:
567 fork_ns = 1
568 CODE:
569 RETVAL = e_new (sizeof (ev_fork), cb);
570 ev_fork_set (RETVAL);
571 if (!ix) START (fork, RETVAL);
572 OUTPUT:
573 RETVAL
574
521ev_child *child (int pid, SV *cb) 575ev_child *child (int pid, SV *cb)
522 ALIAS: 576 ALIAS:
523 child_ns = 1 577 child_ns = 1
524 CODE: 578 CODE:
525 RETVAL = e_new (sizeof (ev_child), cb); 579 RETVAL = e_new (sizeof (ev_child), cb);
540 RETVAL 594 RETVAL
541 595
542void once (SV *fh, int events, SV *timeout, SV *cb) 596void once (SV *fh, int events, SV *timeout, SV *cb)
543 CODE: 597 CODE:
544 ev_once ( 598 ev_once (
599 evapi.default_loop,
545 sv_fileno (fh), events, 600 sv_fileno (fh), events,
546 SvOK (timeout) ? SvNV (timeout) : -1., 601 SvOK (timeout) ? SvNV (timeout) : -1.,
547 e_once_cb, 602 e_once_cb,
548 newSVsv (cb) 603 newSVsv (cb)
549 ); 604 );
553MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 608MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
554 609
555int ev_is_active (ev_watcher *w) 610int ev_is_active (ev_watcher *w)
556 611
557int ev_is_pending (ev_watcher *w) 612int ev_is_pending (ev_watcher *w)
613
614void ev_invoke (ev_watcher *w, int revents = EV_NONE)
615 C_ARGS: w->loop, w, revents
616
617int ev_clear_pending (ev_watcher *w)
618 C_ARGS: w->loop, w
619
620void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
621 C_ARGS: w->loop, w, revents
558 622
559int keepalive (ev_watcher *w, int new_value = 0) 623int keepalive (ev_watcher *w, int new_value = 0)
560 CODE: 624 CODE:
561{ 625{
562 RETVAL = w->flags & WFLAG_KEEPALIVE; 626 RETVAL = w->flags & WFLAG_KEEPALIVE;
594 w->data = newSVsv (new_data); 658 w->data = newSVsv (new_data);
595 } 659 }
596} 660}
597 OUTPUT: 661 OUTPUT:
598 RETVAL 662 RETVAL
599
600void trigger (ev_watcher *w, int revents = EV_NONE)
601 CODE:
602 w->cb (w, revents);
603 663
604int priority (ev_watcher *w, int new_priority = 0) 664int priority (ev_watcher *w, int new_priority = 0)
605 CODE: 665 CODE:
606{ 666{
607 RETVAL = w->priority; 667 RETVAL = w->priority;
743void ev_timer_again (ev_timer *w) 803void ev_timer_again (ev_timer *w)
744 INIT: 804 INIT:
745 CHECK_REPEAT (w->repeat); 805 CHECK_REPEAT (w->repeat);
746 CODE: 806 CODE:
747 REF (w); 807 REF (w);
748 ev_timer_again (w); 808 ev_timer_again (w->loop, w);
749 UNREF (w); 809 UNREF (w);
750 810
751void DESTROY (ev_timer *w) 811void DESTROY (ev_timer *w)
752 CODE: 812 CODE:
753 STOP (timer, w); 813 STOP (timer, w);
757 INIT: 817 INIT:
758 CHECK_REPEAT (repeat); 818 CHECK_REPEAT (repeat);
759 CODE: 819 CODE:
760 RESET (timer, w, (w, after, repeat)); 820 RESET (timer, w, (w, after, repeat));
761 821
822NV at (ev_timer *w)
823 CODE:
824 RETVAL = w->at;
825 OUTPUT:
826 RETVAL
827
762MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 828MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
763 829
764void ev_periodic_start (ev_periodic *w) 830void ev_periodic_start (ev_periodic *w)
765 INIT: 831 INIT:
766 CHECK_REPEAT (w->interval); 832 CHECK_REPEAT (w->interval);
772 STOP (periodic, w); 838 STOP (periodic, w);
773 839
774void ev_periodic_again (ev_periodic *w) 840void ev_periodic_again (ev_periodic *w)
775 CODE: 841 CODE:
776 REF (w); 842 REF (w);
777 ev_periodic_again (w); 843 ev_periodic_again (w->loop, w);
778 UNREF (w); 844 UNREF (w);
779 845
780void DESTROY (ev_periodic *w) 846void DESTROY (ev_periodic *w)
781 CODE: 847 CODE:
782 STOP (periodic, w); 848 STOP (periodic, w);
791 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 857 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
792 858
793 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 859 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
794} 860}
795 861
862NV at (ev_periodic *w)
863 CODE:
864 RETVAL = w->at;
865 OUTPUT:
866 RETVAL
867
796MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 868MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
797 869
798void ev_idle_start (ev_idle *w) 870void ev_idle_start (ev_idle *w)
799 CODE: 871 CODE:
800 START (idle, w); 872 START (idle, w);
834 STOP (check, w); 906 STOP (check, w);
835 907
836void DESTROY (ev_check *w) 908void DESTROY (ev_check *w)
837 CODE: 909 CODE:
838 STOP (check, w); 910 STOP (check, w);
911 e_destroy (w);
912
913MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
914
915void ev_fork_start (ev_fork *w)
916 CODE:
917 START (fork, w);
918
919void ev_fork_stop (ev_fork *w)
920 CODE:
921 STOP (fork, w);
922
923void DESTROY (ev_fork *w)
924 CODE:
925 STOP (fork, w);
839 e_destroy (w); 926 e_destroy (w);
840 927
841MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 928MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
842 929
843void ev_child_start (ev_child *w) 930void ev_child_start (ev_child *w)
932 PPCODE: 1019 PPCODE:
933{ 1020{
934 ev_statdata *s = ix ? &w->attr : &w->prev; 1021 ev_statdata *s = ix ? &w->attr : &w->prev;
935 1022
936 if (ix == 1) 1023 if (ix == 1)
937 ev_stat_stat (w); 1024 ev_stat_stat (w->loop, w);
938 else if (!s->st_nlink) 1025 else if (!s->st_nlink)
939 errno = ENOENT; 1026 errno = ENOENT;
940 1027
941 PL_statcache.st_dev = s->st_nlink; 1028 PL_statcache.st_dev = s->st_nlink;
942 PL_statcache.st_ino = s->st_ino; 1029 PL_statcache.st_ino = s->st_ino;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines