--- libev/ev.h 2010/10/22 09:24:11 1.147 +++ libev/ev.h 2011/02/16 08:02:50 1.159 @@ -1,19 +1,19 @@ /* * libev native API header * - * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann + * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann * All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO @@ -103,6 +103,10 @@ # define EV_FORK_ENABLE EV_FEATURE_WATCHERS #endif +#ifndef EV_CLEANUP_ENABLE +# define EV_CLEANUP_ENABLE EV_FEATURE_WATCHERS +#endif + #ifndef EV_SIGNAL_ENABLE # define EV_SIGNAL_ENABLE EV_FEATURE_WATCHERS #endif @@ -158,7 +162,7 @@ # define EV_P_ EV_P, /* a loop as first of multiple parameters */ # define EV_A loop /* a loop as sole argument to a function call */ # define EV_A_ EV_A, /* a loop as first of multiple arguments */ -# define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */ +# define EV_DEFAULT_UC ev_default_loop_uc_ () /* the default loop, if initialised, as sole arg */ # define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */ # define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */ # define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */ @@ -189,11 +193,11 @@ /*****************************************************************************/ #define EV_VERSION_MAJOR 4 -#define EV_VERSION_MINOR 0 +#define EV_VERSION_MINOR 3 /* eventmask, revents, events... */ enum { - EV_UNDEF = -1, /* guaranteed to be invalid */ + EV_UNDEF = 0xFFFFFFFF, /* guaranteed to be invalid */ EV_NONE = 0x00, /* no events */ EV_READ = 0x01, /* ev_io detected read will not block */ EV_WRITE = 0x02, /* ev_io detected write will not block */ @@ -212,7 +216,8 @@ EV_CHECK = 0x00008000, /* event loop finished poll */ EV_EMBED = 0x00010000, /* embedded event loop needs sweep */ EV_FORK = 0x00020000, /* event loop resumed in child */ - EV_ASYNC = 0x00040000, /* async intra-loop signal */ + EV_CLEANUP = 0x00040000, /* event loop resumed in child */ + EV_ASYNC = 0x00080000, /* async intra-loop signal */ EV_CUSTOM = 0x01000000, /* for use by user code */ EV_ERROR = 0x80000000 /* sent when an error occurs */ }; @@ -391,12 +396,22 @@ #if EV_FORK_ENABLE /* the callback gets invoked before check in the child process when a fork was detected */ +/* revent EV_FORK */ typedef struct ev_fork { EV_WATCHER (ev_fork) } ev_fork; #endif +#if EV_CLEANUP_ENABLE +/* is invoked just before the loop gets destroyed */ +/* revent EV_CLEANUP */ +typedef struct ev_cleanup +{ + EV_WATCHER (ev_cleanup) +} ev_cleanup; +#endif + #if EV_EMBED_ENABLE /* used to embed an event loop inside another */ /* the callback gets invoked when the event loop has handled events, and can be 0 */ @@ -412,6 +427,9 @@ ev_periodic periodic; /* unused */ ev_idle idle; /* unused */ ev_fork fork; /* private */ +#if EV_CLEANUP_ENABLE + ev_cleanup cleanup; /* unused */ +#endif } ev_embed; #endif @@ -450,6 +468,9 @@ #if EV_FORK_ENABLE struct ev_fork fork; #endif +#if EV_CLEANUP_ENABLE + struct ev_cleanup cleanup; +#endif #if EV_EMBED_ENABLE struct ev_embed embed; #endif @@ -470,7 +491,8 @@ #if EV_COMPAT3 EVFLAG_NOSIGFD = 0, /* compatibility to pre-3.9 */ #endif - EVFLAG_SIGNALFD = 0x00200000U /* attempt to use signalfd */ + EVFLAG_SIGNALFD = 0x00200000U, /* attempt to use signalfd */ + EVFLAG_NOSIGMASK = 0x00400000U /* avoid modifying the signal mask */ }; /* method bits to be ored together */ @@ -481,7 +503,8 @@ EVBACKEND_KQUEUE = 0x00000008U, /* bsd */ EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */ EVBACKEND_PORT = 0x00000020U, /* solaris 10 */ - EVBACKEND_ALL = 0x0000003FU + EVBACKEND_ALL = 0x0000003FU, /* all known backends */ + EVBACKEND_MASK = 0x0000FFFFU /* all future backends */ }; #if EV_PROTOTYPES @@ -510,35 +533,27 @@ void ev_set_syserr_cb (void (*cb)(const char *msg)); #if EV_MULTIPLICITY + +/* the default loop is the only one that handles signals and child watchers */ +/* you can call this as often as you like */ +struct ev_loop *ev_default_loop (unsigned int flags EV_CPP (= 0)); + EV_INLINE struct ev_loop * -ev_default_loop_uc (void) +ev_default_loop_uc_ (void) { extern struct ev_loop *ev_default_loop_ptr; return ev_default_loop_ptr; } -/* the default loop is the only one that handles signals and child watchers */ -/* you can call this as often as you like */ -EV_INLINE struct ev_loop * -ev_default_loop (unsigned int flags EV_CPP (= 0)) +EV_INLINE int +ev_is_default_loop (EV_P) { - struct ev_loop *loop = ev_default_loop_uc (); - - if (!loop) - { - extern struct ev_loop *ev_default_loop_init (unsigned int flags); - - loop = ev_default_loop_init (flags); - } - - return loop; + return EV_A == EV_DEFAULT_UC; } /* create and destroy alternative loops that don't handle signals */ struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)); -void ev_loop_destroy (EV_P); -void ev_loop_fork (EV_P); ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ @@ -553,26 +568,24 @@ return ev_rt_now; } -#endif /* multiplicity */ +/* looks weird, but ev_is_default_loop (EV_A) still works if this exists */ EV_INLINE int -ev_is_default_loop (EV_P) +ev_is_default_loop (void) { -#if EV_MULTIPLICITY - extern struct ev_loop *ev_default_loop_ptr; - - return !!(EV_A == ev_default_loop_ptr); -#else return 1; -#endif } -void ev_default_destroy (void); /* destroy the default loop */ -/* this needs to be called after fork, to duplicate the default loop */ -/* if you create alternative loops you have to call ev_loop_fork on them */ +#endif /* multiplicity */ + +/* destroy event loops, also works for the default loop */ +void ev_loop_destroy (EV_P); + +/* this needs to be called after fork, to duplicate the loop */ +/* when you want to re-use it in the child */ /* you can call it in either the parent or the child */ /* you can actually call it at any time, anywhere :) */ -void ev_default_fork (void); +void ev_loop_fork (EV_P); unsigned int ev_backend (EV_P); /* backend in use by loop */ @@ -664,6 +677,7 @@ #define ev_check_set(ev) /* nop, yes, this is a serious in-joke */ #define ev_embed_set(ev,other_) do { (ev)->other = (other_); } while (0) #define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */ +#define ev_cleanup_set(ev) /* nop, yes, this is a serious in-joke */ #define ev_async_set(ev) /* nop, yes, this is a serious in-joke */ #define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0) @@ -677,6 +691,7 @@ #define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0) #define ev_embed_init(ev,cb,other) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(other)); } while (0) #define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0) +#define ev_cleanup_init(ev,cb) do { ev_init ((ev), (cb)); ev_cleanup_set ((ev)); } while (0) #define ev_async_init(ev,cb) do { ev_init ((ev), (cb)); ev_async_set ((ev)); } while (0) #define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ @@ -707,6 +722,7 @@ void ev_feed_event (EV_P_ void *w, int revents); void ev_feed_fd_event (EV_P_ int fd, int revents); #if EV_SIGNAL_ENABLE +void ev_feed_signal (int signum); void ev_feed_signal_event (EV_P_ int signum); #endif void ev_invoke (EV_P_ void *w, int revents); @@ -766,6 +782,11 @@ void ev_fork_stop (EV_P_ ev_fork *w); # endif +# if EV_CLEANUP_ENABLE +void ev_cleanup_start (EV_P_ ev_cleanup *w); +void ev_cleanup_stop (EV_P_ ev_cleanup *w); +# endif + # if EV_EMBED_ENABLE /* only supported when loop to be embedded is in fact embeddable */ void ev_embed_start (EV_P_ ev_embed *w); @@ -788,10 +809,12 @@ #if EV_PROTOTYPES EV_INLINE void ev_loop (EV_P_ int flags) { ev_run (EV_A_ flags); } EV_INLINE void ev_unloop (EV_P_ int how ) { ev_break (EV_A_ how ); } + EV_INLINE void ev_default_destroy (void) { ev_loop_destroy (EV_DEFAULT); } + EV_INLINE void ev_default_fork (void) { ev_loop_fork (EV_DEFAULT); } #if EV_FEATURE_API - EV_INLINE void ev_loop_count (EV_P) { ev_iteration (EV_A); } - EV_INLINE void ev_loop_depth (EV_P) { ev_depth (EV_A); } - EV_INLINE void ev_loop_verify (EV_P) { ev_verify (EV_A); } + EV_INLINE unsigned int ev_loop_count (EV_P) { return ev_iteration (EV_A); } + EV_INLINE unsigned int ev_loop_depth (EV_P) { return ev_depth (EV_A); } + EV_INLINE void ev_loop_verify (EV_P) { ev_verify (EV_A); } #endif #endif #else