--- libev/ev.h 2009/03/28 22:17:17 1.112 +++ libev/ev.h 2010/01/18 13:31:42 1.131 @@ -37,8 +37,8 @@ * either the BSD or the GPL. */ -#ifndef EV_H__ -#define EV_H__ +#ifndef EV_H_ +#define EV_H_ #ifdef __cplusplus extern "C" { @@ -82,6 +82,10 @@ # define EV_ASYNC_ENABLE 1 #endif +#ifndef EV_WALK_ENABLE +# define EV_WALK_ENABLE 0 /* not yet */ +#endif + #ifndef EV_ATOMIC_T # include # define EV_ATOMIC_T sig_atomic_t volatile @@ -147,6 +151,7 @@ #define EV_EMBED 0x00010000 /* embedded event loop needs sweep */ #define EV_FORK 0x00020000 /* event loop resumed in child */ #define EV_ASYNC 0x00040000 /* async intra-loop signal */ +#define EV_CUSTOM 0x01000000 /* for use by user code */ #define EV_ERROR 0x80000000 /* sent when an error occurs */ /* can be used to add custom fields to all watchers, while losing binary compatibility */ @@ -158,7 +163,7 @@ #endif #define EV_VERSION_MAJOR 3 -#define EV_VERSION_MINOR 0 +#define EV_VERSION_MINOR 9 #ifndef EV_CB_DECLARE # define EV_CB_DECLARE(type) void (*cb)(EV_P_ struct type *w, int revents); @@ -184,11 +189,17 @@ * or the array index + 1 in the pendings array. */ +#if EV_MINPRI == EV_MAXPRI +# define EV_DECL_PRIORITY +#else +# define EV_DECL_PRIORITY int priority; +#endif + /* shared by all watchers */ #define EV_WATCHER(type) \ int active; /* private */ \ int pending; /* private */ \ - int priority; /* private */ \ + EV_DECL_PRIORITY /* private */ \ EV_COMMON /* rw */ \ EV_CB_DECLARE (type) /* private */ @@ -354,7 +365,7 @@ EV_ATOMIC_T sent; /* private */ } ev_async; -# define ev_async_pending(w) ((w)->sent + 0) +# define ev_async_pending(w) (+(w)->sent) #endif /* the presence of this union forces similar struct layout */ @@ -393,6 +404,10 @@ /* flag bits */ #define EVFLAG_NOENV 0x01000000U /* do NOT consult environment */ #define EVFLAG_FORKCHECK 0x02000000U /* check for a fork in each iteration */ +/* debugging/feature disable */ +#define EVFLAG_NOINOTIFY 0x00100000U /* do not attempt to use inotify */ +#define EVFLAG_NOSIGFD 0 /* compatibility to pre-3.9 */ +#define EVFLAG_SIGNALFD 0x00200000U /* attempt to use signalfd */ /* method bits to be ored together */ #define EVBACKEND_SELECT 0x00000001U /* about anywhere */ #define EVBACKEND_POLL 0x00000002U /* !win */ @@ -400,6 +415,7 @@ #define EVBACKEND_KQUEUE 0x00000008U /* bsd */ #define EVBACKEND_DEVPOLL 0x00000010U /* solaris 8 */ /* NYI */ #define EVBACKEND_PORT 0x00000020U /* solaris 10 */ +#define EVBACKEND_ALL 0x0000003FU #if EV_PROTOTYPES int ev_version_major (void); @@ -456,10 +472,8 @@ struct ev_loop *ev_loop_new (unsigned int flags); void ev_loop_destroy (EV_P); void ev_loop_fork (EV_P); -void ev_loop_verify (EV_P); ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ -void ev_now_update (EV_P); #else @@ -493,15 +507,17 @@ /* you can actually call it at any time, anywhere :) */ void ev_default_fork (void); -#if 0 +unsigned int ev_backend (EV_P); /* backend in use by loop */ + +void ev_now_update (EV_P); /* update event loop time */ + +#if EV_WALK_ENABLE /* walk (almost) all watchers in the loop of a given type, invoking the */ /* callback on every such watcher. The callback might stop the watcher, */ /* but do nothing else with the loop */ void ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)); #endif -unsigned int ev_backend (EV_P); /* backend in use by loop */ -unsigned int ev_loop_count (EV_P); /* number of loop iterations */ #endif /* prototypes */ #define EVLOOP_NONBLOCK 1 /* do not block/wait */ @@ -514,28 +530,52 @@ void ev_loop (EV_P_ int flags); void ev_unloop (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */ -void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ -void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ - /* * ref/unref can be used to add or remove a refcount on the mainloop. every watcher - * keeps one reference. if you have a long-runing watcher you never unregister that + * keeps one reference. if you have a long-running watcher you never unregister that * should not keep ev_loop from running, unref() after starting, and ref() before stopping. */ void ev_ref (EV_P); void ev_unref (EV_P); -/* convenience function, wait for a single event, without registering an event watcher */ -/* if timeout is < 0, do wait indefinitely */ +/* + * convenience function, wait for a single event, without registering an event watcher + * if timeout is < 0, do wait indefinitely + */ void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); + +# if EV_MINIMAL < 2 +unsigned int ev_loop_count (EV_P); /* number of loop iterations */ +unsigned int ev_loop_depth (EV_P); /* #ev_loop enters - #ev_loop leaves */ +void ev_loop_verify (EV_P); /* abort if loop data corrupted */ + +void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ +void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ + +/* advanced stuff for threading etc. support, see docs */ +void ev_set_userdata (EV_P_ void *data); +void *ev_userdata (EV_P); +void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); +void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)); + +unsigned int ev_pending_count (EV_P); /* number of pending events, if any */ +void ev_invoke_pending (EV_P); /* invoke all pending watchers */ + +/* + * stop/start the timer handling. + */ +void ev_suspend (EV_P); +void ev_resume (EV_P); +#endif + #endif /* these may evaluate ev multiple times, and the other arguments at most once */ /* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ #define ev_init(ev,cb_) do { \ - ((ev_watcher *)(void *)(ev))->active = \ - ((ev_watcher *)(void *)(ev))->pending = \ - ((ev_watcher *)(void *)(ev))->priority = 0; \ + ((ev_watcher *)(void *)(ev))->active = \ + ((ev_watcher *)(void *)(ev))->pending = 0; \ + ev_set_priority ((ev), 0); \ ev_set_cb ((ev), cb_); \ } while (0) @@ -568,11 +608,17 @@ #define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ #define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ -#define ev_priority(ev) ((((ev_watcher *)(void *)(ev))->priority) + 0) #define ev_cb(ev) (ev)->cb /* rw */ -#define ev_set_priority(ev,pri) ((ev_watcher *)(void *)(ev))->priority = (pri) -#define ev_periodic_at(ev) (((ev_watcher_time *)(ev))->at + 0.) +#if EV_MINPRI == EV_MAXPRI +# define ev_priority(ev) ((ev), EV_MINPRI) +# define ev_set_priority(ev,pri) ((ev), (pri)) +#else +# define ev_priority(ev) (+(((ev_watcher *)(void *)(ev))->priority)) +# define ev_set_priority(ev,pri) ( (ev_watcher *)(void *)(ev))->priority = (pri) +#endif + +#define ev_periodic_at(ev) (+((ev_watcher_time *)(ev))->at) #ifndef ev_set_cb # define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) @@ -597,6 +643,8 @@ void ev_timer_stop (EV_P_ ev_timer *w); /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ void ev_timer_again (EV_P_ ev_timer *w); +/* return remaining time */ +ev_tstamp ev_timer_remaining (EV_P_ ev_timer *w); #if EV_PERIODIC_ENABLE void ev_periodic_start (EV_P_ ev_periodic *w);