--- libev/ev.pod 2008/03/31 01:14:12 1.138 +++ libev/ev.pod 2008/04/23 08:21:02 1.147 @@ -198,18 +198,21 @@ =item ev_set_allocator (void *(*cb)(void *ptr, long size)) Sets the allocation function to use (the prototype is similar - the -semantics is identical - to the realloc C function). It is used to -allocate and free memory (no surprises here). If it returns zero when -memory needs to be allocated, the library might abort or take some -potentially destructive action. The default is your system realloc -function. +semantics are identical to the C C89/SuS/POSIX function). It is +used to allocate and free memory (no surprises here). If it returns zero +when memory needs to be allocated (C), the library might abort +or take some potentially destructive action. + +Since some systems (at least OpenBSD and Darwin) fail to implement +correct C semantics, libev will use a wrapper around the system +C and C functions by default. You could override this function in high-availability programs to, say, free some memory if it cannot allocate memory, to use a special allocator, or even to sleep a while and retry until some memory is available. Example: Replace the libev allocator with one that waits a bit and then -retries). +retries (example requires a standards-compliant C). static void * persistent_realloc (void *ptr, size_t size) @@ -258,13 +261,6 @@ types of such loops, the I loop, which supports signals and child events, and dynamically created loops which do not. -If you use threads, a common model is to run the default event loop -in your main thread (or in a separate thread) and for each thread you -create, you also create another event loop. Libev itself does no locking -whatsoever, so if you mix calls to the same event loop in different -threads, make sure you lock (this is usually a bad idea, though, even if -done correctly, because it's hideous and inefficient). - =over 4 =item struct ev_loop *ev_default_loop (unsigned int flags) @@ -277,6 +273,10 @@ If you don't know what event loop to use, use the one returned from this function. +Note that this function is I 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 bes hared easily between threads anyway). + The default loop is the only loop that can handle C and C watchers, and to do this, it always registers a handler for C. If this is a problem for your app you can either @@ -356,7 +356,7 @@ like O(total_fds) where n is the total number of fds (or the highest fd), epoll scales either O(1) or O(active_fds). The epoll design has a number of shortcomings, such as silently dropping events in some hard-to-detect -cases and rewiring a syscall per fd change, no fork support and bad +cases and requiring a syscall per fd change, no fork support and bad support for dup. While stopping, setting and starting an I/O watcher in the same iteration @@ -468,6 +468,10 @@ handle signal and child watchers, and attempts to do so will be greeted by undefined behaviour (or a failed assertion if assertions are enabled). +Note that this function I thread-safe, and the recommended 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); @@ -1632,9 +1636,9 @@ change detection where possible. The inotify descriptor will be created lazily when the first C watcher is being started. -Inotify presense does not change the semantics of C watchers +Inotify presence does not change the semantics of C watchers except that changes might be detected earlier, and in some cases, to avoid -making regular C calls. Even in the presense of inotify support +making regular C calls. Even in the presence of inotify support there are many cases where libev has to resort to regular C polling. (There is no support for kqueue, as apparently it cannot be used to @@ -2282,6 +2286,20 @@ so while the overhead might be noticable, it doesn't apply to repeated calls to C. +=item bool = ev_async_pending (ev_async *) + +Returns a non-zero value when C has been called on the +watcher but the event has not yet been processed (or even noted) by the +event loop. + +C sets a flag in the watcher and wakes up the loop. When +the loop iterates next and checks for the watcher to have become active, +it will reset the flag again. C can be used to very +quickly check wether invoking the loop might be a good idea. + +Not that this does I check wether the watcher itself is pending, only +wether it has been requested to make this watcher pending. + =back @@ -2362,6 +2380,9 @@ will fail and all watchers will have the same priority, even though there is an ev_pri field. +=item * In libevent, the last base created gets the signals, in libev, the +first base created (== the default loop) gets the signals. + =item * Other members are not supported. =item * The libev emulation is I ABI compatible to libevent, you need @@ -2613,6 +2634,16 @@ Similar to the other two macros, this gives you the value of the default loop, if multiple loops are supported ("ev loop default"). +=item C, C + +Usage identical to C and C, but requires that the +default loop has been initialised (C == unchecked). Their behaviour +is undefined when the default loop has not been initialised by a previous +execution of C, C or C. + +It is often prudent to use C when initialising the first +watcher in a function but use C afterwards. + =back Example: Declare and initialise a check watcher, utilising the above @@ -2717,9 +2748,9 @@ =head2 PREPROCESSOR SYMBOLS/MACROS -Libev can be configured via a variety of preprocessor symbols you have to define -before including any of its files. The default is not to build for multiplicity -and only include the select backend. +Libev can be configured via a variety of preprocessor symbols you have to +define before including any of its files. The default in the absense of +autoconf is noted for every option. =over 4 @@ -2755,6 +2786,14 @@ If defined to be C<1>, libev will assume that C is available and will use it for delays. Otherwise it will use C