Browse Source

*** empty log message ***

master
Marc Alexander Lehmann 11 years ago
parent
commit
ed0919e0e8
  1. 9
      Changes
  2. 9
      ev++.h
  3. 61
      ev.c
  4. 17
      ev.h
  5. 163
      ev.pod

9
Changes

@ -1,8 +1,9 @@
Revision history for libev, a high-performance and full-featured event loop.
TODO: include ev_xyz_start in each example?
TODO: ev_pdef stupid idea?
TODO: EVRUN_XXX?
TODO: which supports signals and child events
TODO: pointer races
TODO: ev_default_destroy, ev_default_fork
- "PORTING FROM LIBEV 3.X TO 4.X" (in ev.pod) is recommended reading.
- ev_embed_stop did not correctly stop the watcher (very good
testcase by Vladimir Timofeev).
@ -14,6 +15,8 @@ TODO: EVRUN_XXX?
- replace EV_MINIMAL by EV_FEATURES.
- prefer EPOLL_CTL_ADD over EPOLL_CTL_MOD in some more cases, as it
seems the former is *much* faster than the latter.
- linux kernel version detection (for inotify bug workarounds)
did not work properly.
- reduce the number of spurious wake-ups with the ports backend.
- remove dependency on sys/queue.h on freebsd (patch by Vanilla Hsu).
- do async init within ev_async_start, not ev_async_set, which avoids
@ -42,6 +45,7 @@ TODO: EVRUN_XXX?
- add section on accept() problems to the manpage.
- rename EV_TIMEOUT to EV_TIMER.
- rename ev_loop_count/depth/verify/loop/unloop.
- remove ev_default_destroy and ev_default_fork.
- switch to two-digit minor version.
- work around an apparent gentoo compiler bug.
- define _DARWIN_UNLIMITED_SELECT. just so.
@ -50,6 +54,7 @@ TODO: EVRUN_XXX?
- (experimental) ev_run/ev_default_loop/ev_break/ev_loop_new have now
default arguments when compiled as C++.
- enable automake dependency tracking.
- ev_loop_new no longer leaks memory when loop creation failed.
3.9 Thu Dec 31 07:59:59 CET 2009
- signalfd is no longer used by default and has to be requested

9
ev++.h

@ -219,11 +219,7 @@ namespace ev {
void post_fork () throw ()
{
#if EV_MULTIPLICITY
ev_loop_fork (EV_AX);
#else
ev_default_fork ();
#endif
}
unsigned int backend () const throw ()
@ -396,11 +392,6 @@ namespace ev {
throw bad_loop ();
}
~default_loop () throw ()
{
ev_default_destroy ();
}
private:
default_loop (const default_loop &);
default_loop &operator = (const default_loop &);

61
ev.c

@ -532,8 +532,8 @@ static unsigned int noinline
ev_linux_version (void)
{
#ifdef __linux
unsigned int v = 0;
struct utsname buf;
unsigned int v;
int i;
char *p = buf.release;
@ -1733,11 +1733,19 @@ loop_init (EV_P_ unsigned int flags)
}
/* free up a loop structure */
static void noinline
loop_destroy (EV_P)
void
ev_loop_destroy (EV_P)
{
int i;
#if EV_CHILD_ENABLE
if (ev_is_active (&childev))
{
ev_ref (EV_A); /* child watcher */
ev_signal_stop (EV_A_ &childev);
}
#endif
if (ev_is_active (&pipe_w))
{
/*ev_ref (EV_A);*/
@ -1814,6 +1822,15 @@ loop_destroy (EV_P)
#endif
backend = 0;
#if EV_MULTIPLICITY
if (ev_is_default_loop (EV_A))
#endif
ev_default_loop_ptr = 0;
#if EV_MULTIPLICITY
else
ev_free (EV_A);
#endif
}
#if EV_USE_INOTIFY
@ -1882,21 +1899,10 @@ ev_loop_new (unsigned int flags)
if (ev_backend (EV_A))
return EV_A;
ev_free (EV_A);
return 0;
}
void
ev_loop_destroy (EV_P)
{
loop_destroy (EV_A);
ev_free (loop);
}
void
ev_loop_fork (EV_P)
{
postfork = 1; /* must be in line with ev_default_fork */
}
#endif /* multiplicity */
#if EV_VERIFY
@ -2040,30 +2046,9 @@ ev_default_loop (unsigned int flags)
}
void
ev_default_destroy (void)
{
#if EV_MULTIPLICITY
EV_P = ev_default_loop_ptr;
#endif
ev_default_loop_ptr = 0;
#if EV_CHILD_ENABLE
ev_ref (EV_A); /* child watcher */
ev_signal_stop (EV_A_ &childev);
#endif
loop_destroy (EV_A);
}
void
ev_default_fork (void)
ev_loop_fork (EV_P)
{
#if EV_MULTIPLICITY
EV_P = ev_default_loop_ptr;
#endif
postfork = 1; /* must be in line with ev_loop_fork */
postfork = 1; /* must be in line with ev_default_fork */
}
/*****************************************************************************/

17
ev.h

@ -158,7 +158,7 @@ struct ev_loop;
# 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 */
@ -516,7 +516,7 @@ void ev_set_syserr_cb (void (*cb)(const char *msg));
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;
@ -526,13 +526,13 @@ ev_default_loop_uc (void)
EV_INLINE int
ev_is_default_loop (EV_P)
{
return EV_A == ev_default_loop_uc ();
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));
/* destroy event loops, also works for the default loop */
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 */
@ -557,12 +557,11 @@ ev_is_default_loop (void)
#endif /* multiplicity */
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 */
/* 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 */
@ -778,6 +777,8 @@ void ev_async_send (EV_P_ ev_async *w);
#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); }

163
ev.pod

@ -45,7 +45,7 @@ libev - a high performance full-featured event loop written in C
main (void)
{
// use the default event loop unless you have special needs
struct ev_loop *loop = ev_default_loop (0);
struct ev_loop *loop = EV_DEFAULT;
// initialise an io watcher, then start it
// this one will watch for stdin to become readable
@ -295,7 +295,7 @@ Example: This is basically the same thing that libev does internally, too.
=back
=head1 FUNCTIONS CONTROLLING THE EVENT LOOP
=head1 FUNCTIONS CONTROLLING EVENT LOOPS
An event loop is described by a C<struct ev_loop *> (the C<struct> is
I<not> optional in this case unless libev 3 compatibility is disabled, as
@ -309,24 +309,56 @@ which do not.
=item struct ev_loop *ev_default_loop (unsigned int flags)
This will initialise the default event loop if it hasn't been initialised
yet and return it. If the default loop could not be initialised, returns
false. If it already was initialised it simply returns it (and ignores the
flags. If that is troubling you, check C<ev_backend ()> afterwards).
This returns the "default" event loop object, which is what you should
normally use when you just need "the event loop". Event loop objects and
the C<flags> parameter are described in more detail in the entry for
C<ev_loop_new>.
If the default loop is already initialised then this function simply
returns it (and ignores the flags. If that is troubling you, check
C<ev_backend ()> afterwards). Otherwise it will create it with the given
flags, which should almost always be C<0>, unless the caller is also the
one calling C<ev_run> or otherwise qualifies as "the main program".
If you don't know what event loop to use, use the one returned from this
function.
function (or via the C<EV_DEFAULT> macro).
Note that this function is I<not> thread-safe, so if you want to use it
from multiple threads, you have to lock (note also that this is unlikely,
as loops cannot be shared easily between threads anyway).
from multiple threads, you have to employ some kind of mutex (note also
that this case is unlikely, as loops cannot be shared easily between
threads anyway).
The default loop is the only loop that can handle C<ev_child> watchers,
and to do this, it always registers a handler for C<SIGCHLD>. If this is
a problem for your application you can either create a dynamic loop with
C<ev_loop_new> which doesn't do that, or you can simply overwrite the
C<SIGCHLD> signal handler I<after> calling C<ev_default_init>.
Example: This is the most typical usage.
if (!ev_default_loop (0))
fatal ("could not initialise libev, bad $LIBEV_FLAGS in environment?");
Example: Restrict libev to the select and poll backends, and do not allow
environment settings to be taken into account:
ev_default_loop (EVBACKEND_POLL | EVBACKEND_SELECT | EVFLAG_NOENV);
The default loop is the only loop that can handle C<ev_signal> and
C<ev_child> watchers, and to do this, it always registers a handler
for C<SIGCHLD>. If this is a problem for your application you can either
create a dynamic loop with C<ev_loop_new> that doesn't do that, or you
can simply overwrite the C<SIGCHLD> signal handler I<after> calling
C<ev_default_init>.
Example: Use whatever libev has to offer, but make sure that kqueue is
used if available (warning, breaks stuff, best use only with your own
private event loop and only if you know the OS supports your types of
fds):
ev_default_loop (ev_recommended_backends () | EVBACKEND_KQUEUE);
=item struct ev_loop *ev_loop_new (unsigned int flags)
This will create and initialise a new event loop object. If the loop
could not be initialised, returns false.
Note that this function I<is> thread-safe, and one common way to use
libev with threads is indeed to create one loop per thread, and using the
default loop in the "main" or "initial" thread.
The flags argument can be used to specify special behaviour or specific
backends to use, and is usually specified as C<0> (or C<EVFLAG_AUTO>).
@ -554,69 +586,42 @@ then only these backends will be tried (in the reverse order as listed
here). If none are specified, all backends in C<ev_recommended_backends
()> will be tried.
Example: This is the most typical usage.
if (!ev_default_loop (0))
fatal ("could not initialise libev, bad $LIBEV_FLAGS in environment?");
Example: Restrict libev to the select and poll backends, and do not allow
environment settings to be taken into account:
ev_default_loop (EVBACKEND_POLL | EVBACKEND_SELECT | EVFLAG_NOENV);
Example: Use whatever libev has to offer, but make sure that kqueue is
used if available (warning, breaks stuff, best use only with your own
private event loop and only if you know the OS supports your types of
fds):
ev_default_loop (ev_recommended_backends () | EVBACKEND_KQUEUE);
=item struct ev_loop *ev_loop_new (unsigned int flags)
Similar to C<ev_default_loop>, but always creates a new event loop that is
always distinct from the default loop.
Note that this function I<is> thread-safe, and one common way to use
libev with threads is indeed to create one loop per thread, and using the
default loop in the "main" or "initial" thread.
Example: Try to create a event loop that uses epoll and nothing else.
struct ev_loop *epoller = ev_loop_new (EVBACKEND_EPOLL | EVFLAG_NOENV);
if (!epoller)
fatal ("no epoll found here, maybe it hides under your chair");
=item ev_default_destroy ()
=item ev_loop_destroy (loop)
Destroys the default loop (frees all memory and kernel state etc.). None
of the active event watchers will be stopped in the normal sense, so
e.g. C<ev_is_active> might still return true. It is your responsibility to
either stop all watchers cleanly yourself I<before> calling this function,
or cope with the fact afterwards (which is usually the easiest thing, you
can just ignore the watchers and/or C<free ()> them for example).
Destroys an event loop object (frees all memory and kernel state
etc.). None of the active event watchers will be stopped in the normal
sense, so e.g. C<ev_is_active> might still return true. It is your
responsibility to either stop all watchers cleanly yourself I<before>
calling this function, or cope with the fact afterwards (which is usually
the easiest thing, you can just ignore the watchers and/or C<free ()> them
for example).
Note that certain global state, such as signal state (and installed signal
handlers), will not be freed by this function, and related watchers (such
as signal and child watchers) would need to be stopped manually.
In general it is not advisable to call this function except in the
rare occasion where you really need to free e.g. the signal handling
pipe fds. If you need dynamically allocated loops it is better to use
C<ev_loop_new> and C<ev_loop_destroy>.
This function is normally used on loop objects allocated by
C<ev_loop_new>, but it can also be used on the default loop returned by
C<ev_default_loop>, in which case it is not thread-safe.
=item ev_loop_destroy (loop)
Like C<ev_default_destroy>, but destroys an event loop created by an
earlier call to C<ev_loop_new>.
Note that it is not advisable to call this function on the default loop
except in the rare occasion where you really need to free it's resources.
If you need dynamically allocated loops it is better to use C<ev_loop_new>
and C<ev_loop_destroy>.
=item ev_default_fork ()
=item ev_loop_fork (loop)
This function sets a flag that causes subsequent C<ev_run> iterations
to reinitialise the kernel state for backends that have one. Despite the
This function sets a flag that causes subsequent C<ev_run> iterations to
reinitialise the kernel state for backends that have one. Despite the
name, you can call it anytime, but it makes most sense after forking, in
the child process (or both child and parent, but that again makes little
sense). You I<must> call it in the child before using any of the libev
functions, and it will only take effect at the next C<ev_run> iteration.
the child process. You I<must> call it (or use C<EVFLAG_FORKCHECK>) in the
child before resuming or calling C<ev_run>.
Again, you I<have> to call it on I<any> loop that you want to re-use after
a fork, I<even if you do not plan to use the loop in the parent>. This is
@ -631,17 +636,19 @@ difference, but libev will usually detect this case on its own and do a
costly reset of the backend).
The function itself is quite fast and it's usually not a problem to call
it just in case after a fork. To make this easy, the function will fit in
quite nicely into a call to C<pthread_atfork>:
it just in case after a fork.
pthread_atfork (0, 0, ev_default_fork);
Example: Automate calling C<ev_loop_fork> on the default loop when
using pthreads.
=item ev_loop_fork (loop)
static void
post_fork_child (void)
{
ev_loop_fork (EV_DEFAULT);
}
Like C<ev_default_fork>, but acts on an event loop created by
C<ev_loop_new>. Yes, you have to call this on every allocated event loop
after fork that you want to re-use in the child, and how you keep track of
them is entirely your own problem.
...
pthread_atfork (0, 0, post_fork_child);
=item int ev_is_default_loop (loop)
@ -3077,10 +3084,11 @@ signal watchers).
When this is not possible, or you want to use the default loop for
other reasons, then in the process that wants to start "fresh", call
C<ev_default_destroy ()> followed by C<ev_default_loop (...)>. Destroying
the default loop will "orphan" (not stop) all registered watchers, so you
have to be careful not to execute code that modifies those watchers. Note
also that in that case, you have to re-register any signal watchers.
C<ev_loop_destroy (EV_DEFAULT)> followed by C<ev_default_loop (...)>.
Destroying the default loop will "orphan" (not stop) all registered
watchers, so you have to be careful not to execute code that modifies
those watchers. Note also that in that case, you have to re-register any
signal watchers.
=head3 Watcher-Specific Functions and Data Members
@ -4832,6 +4840,13 @@ removed in later versions of libev, so better update early than late.
=over 4
=item C<ev_default_destroy> and C<ev_default_fork> have been removed
These calls can be replaced easily by their C<ev_loop_xxx> counterparts:
ev_loop_destroy (EV_DEFAULT);
ev_loop_fork (EV_DEFAULT);
=item function/symbol renames
A number of functions and symbols have been renamed:

Loading…
Cancel
Save