4 typedef double ev_tstamp;
6 /* eventmask, revents, events... */
7 #define EV_UNDEF -1 /* guaranteed to be invalid */
11 #define EV_TIMEOUT 0x04
12 #define EV_SIGNAL 0x08
16 /* shared by all watchers */
17 #define EV_WATCHER(type) \
18 int active; /* private */ \
19 int pending; /* private */ \
20 void *data; /* rw */ \
21 void (*cb)(struct type *, int revents) /* rw */ /* gets invoked with an eventmask */
23 #define EV_WATCHER_LIST(type) \
25 struct type *next /* private */
27 /* invoked at a specific time or after a specific time, repeatable */
30 EV_WATCHER_LIST (ev_timer);
32 ev_tstamp at; /* private */
33 ev_tstamp repeat; /* rw */
34 unsigned char is_abs; /* ro */
37 /* invoked when fd is either EV_READable or EV_WRITEable */
40 EV_WATCHER_LIST (ev_io);
46 /* invoked when the given signal has been received */
49 EV_WATCHER_LIST (ev_signal);
54 /* invoked when the nothing else needs to be done, keeps the process from blocking */
60 /* invoked for each run of the mainloop, just before the next blocking vall is initiated */
63 EV_WATCHER (ev_check);
66 #define EVMETHOD_NONE 0
67 #define EVMETHOD_SELECT 1
68 #define EVMETHOD_EPOLL 2
69 int ev_init (int flags); /* returns ev_method */
72 /* these three calls are suitable for plugging into pthread_atfork */
73 void ev_prefork (void);
74 void ev_postfork_parent (void);
75 void ev_postfork_child (void);
77 extern ev_tstamp ev_now; /* time w.r.t. timers and the eventloop, updated after each poll */
78 ev_tstamp ev_time (void);
80 #define EVLOOP_NONBLOCK 1 /* do not block/wait */
81 #define EVLOOP_ONESHOT 2 /* block *once* only */
82 void ev_loop (int flags);
83 extern int ev_loop_done; /* set to 1 to break out of event loop */
85 /* these may evaluate ev multiple times, and the other arguments at most once */
86 #define evw_init(ev,cb_,data_) do { (ev)->active = 0; (ev)->cb = (cb_); (ev)->data = (void *)data_; } while (0)
88 #define evio_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0)
89 #define evtimer_set_rel(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); (ev)->is_abs = 0; } while (0)
90 #define evtimer_set_abs(ev,at_,repeat_) do { (ev)->at = (at_); (ev)->repeat = (repeat_); (ev)->is_abs = 1; } while (0)
91 #define evsignal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0)
93 #define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */
95 /* stopping (enabling, adding) a watcher does nothing if it is already running */
96 /* stopping (disabling, deleting) a watcher does nothing unless its already running */
97 void evio_start (struct ev_io *w);
98 void evio_stop (struct ev_io *w);
100 void evtimer_start (struct ev_timer *w);
101 void evtimer_stop (struct ev_timer *w);
103 void evsignal_start (struct ev_signal *w);
104 void evsignal_stop (struct ev_signal *w);
106 void evidle_start (struct ev_idle *w);
107 void evidle_stop (struct ev_idle *w);
109 void evcheck_start (struct ev_check *w);
110 void evcheck_stop (struct ev_check *w);