--- libev/ev.h 2009/03/28 22:17:17 1.112 +++ libev/ev.h 2009/07/10 00:36:21 1.119 @@ -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 */ @@ -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 */ @@ -456,10 +467,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 +502,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 +525,59 @@ 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 */ + +/* + * a single void * can be attached to each loop. this is intended + * to aid the invoke_pending/blocking callbacks. + */ +void ev_set_userdata (EV_P_ void *data); +void *ev_userdata (EV_P); + +/* + * hooks to overide how and when libev invokes callbacks, + * and hooks that wrap the actual eventloop blocking call. + */ +void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); +void ev_set_blocking_cb (EV_P_ void (*suspend_cb_)(EV_P), void (*resume_cb_)(EV_P)); + +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,9 +610,15 @@ #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) + +#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) + 0) +# define ev_set_priority(ev,pri) ( (ev_watcher *)(void *)(ev))->priority = (pri) +#endif #define ev_periodic_at(ev) (((ev_watcher_time *)(ev))->at + 0.)