X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/c3a3f33d0d4ad477f0b40f4ea649d6ac523a45fa..39ca7b64db757c30ab6f0dc5dad63206f1d5a375:/ev.html diff --git a/ev.html b/ev.html index 81ff69b..63ddf3b 100644 --- a/ev.html +++ b/ev.html @@ -6,7 +6,7 @@ - +
@@ -121,6 +121,9 @@The newest version of this document is also available as a html-formatted +web page you might find easier to navigate when reading it for the first +time: http://cvs.schmorp.de/libev/ev.html.
Libev is an event loop: you register interest in certain events (such as a file descriptor being readable or a timeout occuring), and it will manage these event sources and provide your program with events.
@@ -919,7 +922,7 @@ it is best to always use non-blocking I/O: An extraread
(2) returni
EAGAIN
is far preferable to a program hanging until some data arrives.
If you cannot run the fd in non-blocking mode (for example you should not play around with an Xlib connection), then you have to seperately re-test -wether a file descriptor is really ready with a known-to-be good interface +whether a file descriptor is really ready with a known-to-be good interface such as poll (fortunately in our Xlib example, Xlib already does this on its own, so its quite safe to use).
Libev can be compiled with a variety of options, the most fundemantal is
-EV_MULTIPLICITY
. This option determines wether (most) functions and
+EV_MULTIPLICITY
. This option determines whether (most) functions and
callbacks have an initial struct ev_loop *
argument.
To make it easier to write programs that cope with either variant, the following macros are defined:
@@ -1874,7 +1877,7 @@ loop, if multiple loops are supported ("ev loop default").Example: Declare and initialise a check watcher, utilising the above -macros so it will work regardless of wether multiple loops are supported +macros so it will work regardless of whether multiple loops are supported or not.
static void
check_cb (EV_P_ ev_timer *w, int revents)
@@ -2111,6 +2114,20 @@ will have the struct ev_loop *
as first argument, and you can creat
additional independent event loops. Otherwise there will be no support
for multiple event loops and there is no first event loop pointer
argument. Instead, all functions act on the single default loop.
+
+
The range of allowed priorities. EV_MINPRI
must be smaller or equal to
+EV_MAXPRI
, but otherwise there are no non-obvious limitations. You can
+provide for more priorities by overriding those symbols (usually defined
+to be -2
and 2
, respectively).
When doing priority-based operations, libev usually has to linearly search +all the priorities, so having many of them (hundreds) uses a lot of space +and time, so using the defaults of five priorities (-2 .. +2) is usually +fine.
+If your embedding app does not need any priorities, defining these both to
+0
will save some memory and cpu.
In this section the complexities of (many of) the algorithms used inside
libev will be explained. For complexity discussions about backends see the
documentation for ev_default_init
.
All of the following are about amortised time: If an array needs to be +extended, libev needs to realloc and move the whole array, but this +happens asymptotically never with higher number of elements, so O(1) might +mean it might do a lengthy realloc operation in rare cases, but on average +it is much faster and asymptotically approaches constant time.
This means that, when you have a watcher that triggers in one hour and +there are 100 watchers that would trigger before that then inserting will +have to skip those 100 watchers.
+That means that for changing a timer costs less than removing/adding them +as only the relative motion in the event queue has to be paid for.
+These just add the watcher into an array or at the head of a list. +=item Stopping check/prepare/idle watchers: O(1)
+These watchers are stored in lists then need to be walked to find the +correct watcher to remove. The lists are usually short (you don't usually +have many watchers waiting for the same fd or signal).
+A change means an I/O watcher gets started or stopped, which requires +libev to recalculate its status (and possibly tell the kernel).
+Priorities are implemented by allocating some space for each +priority. When doing priority-based operations, libev usually has to +linearly search all the priorities.
+