--- libev/ev.pod 2011/08/15 10:18:07 1.382 +++ libev/ev.pod 2014/04/26 14:28:48 1.432 @@ -1,3 +1,5 @@ +=encoding utf-8 + =head1 NAME libev - a high performance full-featured event loop written in C @@ -84,9 +86,9 @@ This manual tries to be very detailed, but unfortunately, this also makes it very long. If you just want to know the basics of libev, I suggest -reading L, then the L above and -look up the missing functions in L and the C and -C sections in L. +reading L, then the L above and +look up the missing functions in L and the C and +C sections in L. =head1 ABOUT LIBEV @@ -176,7 +178,7 @@ Returns the current time as libev would use it. Please note that the C function is usually faster and also often returns the timestamp you actually want to know. Also interesting is the combination of -C and C. +C and C. =item ev_sleep (ev_tstamp interval) @@ -249,7 +251,7 @@ See the description of C watchers for more info. -=item ev_set_allocator (void *(*cb)(void *ptr, long size)) +=item ev_set_allocator (void *(*cb)(void *ptr, long size) throw ()) Sets the allocation function to use (the prototype is similar - the semantics are identical to the C C89/SuS/POSIX function). It is @@ -285,7 +287,7 @@ ... ev_set_allocator (persistent_realloc); -=item ev_set_syserr_cb (void (*cb)(const char *msg)) +=item ev_set_syserr_cb (void (*cb)(const char *msg) throw ()) Set the callback function to call on a retryable system call error (such as failed select, poll, epoll_wait). The message is a printable string @@ -398,8 +400,10 @@ or setgid) then libev will I look at the environment variable C. Otherwise (the default), this environment variable will override the flags completely if it is found in the environment. This is -useful to try out specific backends to test their performance, or to work -around bugs. +useful to try out specific backends to test their performance, to work +around bugs, or to make libev threadsafe (accessing environment variables +cannot be done in a threadsafe way, but usually it works if no other +thread modifies them). =item C @@ -569,9 +573,9 @@ kernel is more efficient (which says nothing about its actual speed, of course). While stopping, setting and starting an I/O watcher does never cause an extra system call as with C, it still adds up to -two event changes per incident. Support for C is very bad (but -sane, unlike epoll) and it drops fds silently in similarly hard-to-detect -cases +two event changes per incident. Support for C is very bad (you +might have to leak fd's on fork, but it's more sane than epoll) and it +drops fds silently in similarly hard-to-detect cases. This backend usually performs well under most conditions. @@ -686,7 +690,7 @@ the child process. You I call it (or use C) in the child before resuming or calling C. -Again, you I to call it on I loop that you want to re-use after +Again, you I to call it on I loop that you want to re-use after a fork, I. This is because some kernel interfaces *cough* I *cough* do funny things during fork. @@ -766,7 +770,7 @@ very long time without entering the event loop, updating libev's idea of the current time is a good idea. -See also L in the C section. +See also L in the C section. =item ev_suspend (loop) @@ -794,18 +798,22 @@ Calling C/C has the side effect of updating the event loop time (see C). -=item ev_run (loop, int flags) +=item bool ev_run (loop, int flags) Finally, this is it, the event handler. This function usually is called after you have initialised all your watchers and you want to start handling events. It will ask the operating system for any new events, call -the watcher callbacks, an then repeat the whole process indefinitely: This +the watcher callbacks, and then repeat the whole process indefinitely: This is why event loops are called I. If the flags argument is specified as C<0>, it will keep handling events until either no event watchers are active anymore or C was called. +The return value is false if there are no more active watchers (which +usually means "all jobs done" or "deadlock"), and true in all other cases +(which usually means " you should call C again"). + Please note that an explicit C is usually better than relying on all watchers to be stopped when deciding when a program has finished (especially in interactive programs), but having a program @@ -813,8 +821,8 @@ of relying on its watchers stopping correctly, that is truly a thing of beauty. -This function is also I exception-safe - you can break out of -a C call by calling C in a callback, throwing a C++ +This function is I exception-safe - you can break out of a +C call by calling C in a callback, throwing a C++ exception and so on. This does not decrement the C value, nor will it clear any outstanding C breaks. @@ -1014,7 +1022,7 @@ If you want to reset the callback, use C as new callback. -=item ev_set_loop_release_cb (loop, void (*release)(EV_P), void (*acquire)(EV_P)) +=item ev_set_loop_release_cb (loop, void (*release)(EV_P) throw (), void (*acquire)(EV_P) throw ()) Sometimes you want to share the same loop between multiple threads. This can be done relatively simply by putting mutex_lock/unlock calls around @@ -1022,7 +1030,7 @@ However, C can run an indefinite time, so it is not feasible to wait for it to return. One way around this is to wake up the event -loop via C and C, another way is to set these +loop via C and C, another way is to set these I and I callbacks on the loop. When set, then C will be called just before the thread is @@ -1172,13 +1180,18 @@ =item C -All C watchers are invoked just I C starts -to gather new events, and all C watchers are invoked just after -C has gathered them, but before it invokes any callbacks for any -received events. Callbacks of both watcher types can start and stop as -many watchers as they want, and all of them will be taken into account -(for example, a C watcher might start an idle watcher to keep -C from blocking). +All C watchers are invoked just I C starts to +gather new events, and all C watchers are queued (not invoked) +just after C has gathered them, but before it queues any callbacks +for any received events. That means C watchers are the last +watchers invoked before the event loop sleeps or polls for new events, and +C watchers will be invoked before any other watchers of the same +or lower priority within an event loop iteration. + +Callbacks of both watcher types can start and stop as many watchers as +they want, and all of them will be taken into account (for example, a +C watcher might start an idle watcher to keep C from +blocking). =item C @@ -1311,7 +1324,7 @@ Returns the callback currently set on the watcher. -=item ev_cb_set (ev_TYPE *watcher, callback) +=item ev_set_cb (ev_TYPE *watcher, callback) Change the callback. You can change the callback at virtually any time (modulo threads). @@ -1339,7 +1352,7 @@ The default priority used by watchers when no priority has been set is always C<0>, which is supposed to not be too high and not be too low :). -See L, below, for a more thorough treatment of +See L, below, for a more thorough treatment of priorities. =item ev_invoke (loop, ev_TYPE *watcher, int revents) @@ -1374,7 +1387,7 @@ =back -See also the L and L and L idioms. =head2 WATCHER STATES @@ -1386,7 +1399,7 @@ =over 4 -=item initialiased +=item initialised Before a watcher can be registered with the event loop it has to be initialised. This can be done with a call to C, or calls to @@ -1862,63 +1875,77 @@ but remember the time of last activity, and check for a real timeout only within the callback: + ev_tstamp timeout = 60.; ev_tstamp last_activity; // time of last activity + ev_timer timer; static void callback (EV_P_ ev_timer *w, int revents) { - ev_tstamp now = ev_now (EV_A); - ev_tstamp timeout = last_activity + 60.; + // calculate when the timeout would happen + ev_tstamp after = last_activity - ev_now (EV_A) + timeout; - // if last_activity + 60. is older than now, we did time out - if (timeout < now) + // if negative, it means we the timeout already occurred + if (after < 0.) { // timeout occurred, take action } else { - // callback was invoked, but there was some activity, re-arm - // the watcher to fire in last_activity + 60, which is - // guaranteed to be in the future, so "again" is positive: - w->repeat = timeout - now; - ev_timer_again (EV_A_ w); + // callback was invoked, but there was some recent + // activity. simply restart the timer to time out + // after "after" seconds, which is the earliest time + // the timeout can occur. + ev_timer_set (w, after, 0.); + ev_timer_start (EV_A_ w); } } -To summarise the callback: first calculate the real timeout (defined -as "60 seconds after the last activity"), then check if that time has -been reached, which means something I, in fact, time out. Otherwise -the callback was invoked too early (C is in the future), so -re-schedule the timer to fire at that future time, to see if maybe we have -a timeout then. - -Note how C is used, taking advantage of the -C optimisation when the timer is already running. +To summarise the callback: first calculate in how many seconds the +timeout will occur (by calculating the absolute time when it would occur, +C, and subtracting the current time, C from that). + +If this value is negative, then we are already past the timeout, i.e. we +timed out, and need to do whatever is needed in this case. + +Otherwise, we now the earliest time at which the timeout would trigger, +and simply start the timer with this timeout value. + +In other words, each time the callback is invoked it will check whether +the timeout occurred. If not, it will simply reschedule itself to check +again at the earliest time it could time out. Rinse. Repeat. This scheme causes more callback invocations (about one every 60 seconds minus half the average time between activity), but virtually no calls to libev to change the timeout. -To start the timer, simply initialise the watcher and set C -to the current time (meaning we just have some activity :), then call the -callback, which will "do the right thing" and start the timer: - - ev_init (timer, callback); - last_activity = ev_now (loop); - callback (loop, timer, EV_TIMER); +To start the machinery, simply initialise the watcher and set +C to the current time (meaning there was some activity just +now), then call the callback, which will "do the right thing" and start +the timer: + + last_activity = ev_now (EV_A); + ev_init (&timer, callback); + callback (EV_A_ &timer, 0); -And when there is some activity, simply store the current time in +When there is some activity, simply store the current time in C, no libev calls at all: - last_activity = ev_now (loop); + if (activity detected) + last_activity = ev_now (EV_A); + +When your timeout value changes, then the timeout can be changed by simply +providing a new value, stopping the timer and calling the callback, which +will again do the right thing (for example, time out immediately :). + + timeout = new_value; + ev_timer_stop (EV_A_ &timer); + callback (EV_A_ &timer, 0); This technique is slightly more complex, but in most cases where the time-out is unlikely to be triggered, much more efficient. -Changing the timeout is trivial as well (if it isn't hard-coded in the -callback :) - just change the timeout and invoke the callback, which will -fix things for you. - =item 4. Wee, just use a double-linked list for your timeouts. If there is not one request, but many thousands (millions...), all @@ -1960,7 +1987,7 @@ you expect it to be invoked after three seconds - but of course, this cannot be guaranteed to infinite precision. Less obviously, it cannot be guaranteed to any precision by libev - imagine somebody suspending the -process a STOP signal for a few hours for example. +process with a STOP signal for a few hours for example. So, libev tries to invoke your callback as soon as possible I the delay has occurred, but cannot guarantee this. @@ -1993,8 +2020,8 @@ =head3 The special problem of time updates -Establishing the current time is a costly operation (it usually takes at -least two system calls): EV therefore updates its idea of the current +Establishing the current time is a costly operation (it usually takes +at least one system call): EV therefore updates its idea of the current time only before and after C collects new events, which causes a growing difference between C and C when handling lots of events in one iteration. @@ -2011,7 +2038,7 @@ update of the time returned by C by calling C. -=head3 The special problem of unsychronised clocks +=head3 The special problem of unsynchronised clocks Modern systems have a variety of clocks - libev itself uses the normal "wall clock" clock and, if available, the monotonic clock (to avoid time @@ -2096,17 +2123,26 @@ =item ev_timer_again (loop, ev_timer *) -This will act as if the timer timed out and restarts it again if it is -repeating. The exact semantics are: +This will act as if the timer timed out, and restarts it again if it is +repeating. It basically works like calling C, updating the +timeout to the C value and calling C. -If the timer is pending, its pending status is cleared. +The exact semantics are as in the following rules, all of which will be +applied to the watcher: + +=over 4 -If the timer is started but non-repeating, stop it (as if it timed out). +=item If the timer is pending, the pending status is always cleared. -If the timer is repeating, either start it if necessary (with the -C value), or reset the running timer to the C value. +=item If the timer is started but non-repeating, stop it (as if it timed +out, without invoking it). -This sounds a bit complicated, see L, above, for a +=item If the timer is repeating, make the C value the new timeout +and start the timer, if necessary. + +=back + +This sounds a bit complicated, see L, above, for a usage example. =item ev_tstamp ev_timer_remaining (loop, ev_timer *) @@ -2359,7 +2395,7 @@ ev_periodic_init (&hourly_tick, clock_cb, fmod (ev_now (loop), 3600.), 3600., 0); ev_periodic_start (loop, &hourly_tick); - + =head2 C - signal me when a signal gets signalled! @@ -2379,9 +2415,9 @@ C in both the default loop and another loop at the same time. At the moment, C is permanently tied to the default loop. -When the first watcher gets started will libev actually register something -with the kernel (thus it coexists with your own signal handlers as long as -you don't register any with libev for the same signal). +Only after the first watcher for a signal is started will libev actually +register something with the kernel. It thus coexists with your own signal +handlers as long as you don't register any with libev for the same signal. If possible and supported, libev will install its handlers with C (or equivalent) behaviour enabled, so system calls should @@ -2576,8 +2612,9 @@ This watches a file system path for attribute changes. That is, it calls C on that path in regular intervals (or when the OS says it changed) -and sees if it changed compared to the last time, invoking the callback if -it did. +and sees if it changed compared to the last time, invoking the callback +if it did. Starting the watcher C's the file, so only changes that +happen after the watcher has been started will be reported. The path does not need to exist: changing from "path exists" to "path does not exist" is a status change like any other. The condition "path does not @@ -2817,6 +2854,20 @@ "pseudo-background processing", or delay processing stuff to after the event loop has handled all outstanding events. +=head3 Abusing an C watcher for its side-effect + +As long as there is at least one active idle watcher, libev will never +sleep unnecessarily. Or in other words, it will loop as fast as possible. +For this to work, the idle watcher doesn't need to be invoked at all - the +lowest priority will do. + +This mode of operation can be useful together with an C watcher, +to do something on each event loop iteration - for example to balance load +between different connections. + +See L for a longer +example. + =head3 Watcher-Specific Functions and Data Members =over 4 @@ -2837,7 +2888,12 @@ static void idle_cb (struct ev_loop *loop, ev_idle *w, int revents) { + // stop the watcher + ev_idle_stop (loop, w); + + // now we can free it free (w); + // now do something you wanted to do when the program has // no longer anything immediate to do. } @@ -2849,7 +2905,7 @@ =head2 C and C - customise your event loop! -Prepare and check watchers are usually (but not always) used in pairs: +Prepare and check watchers are often (but not always) used in pairs: prepare watchers get invoked before the process blocks and check watchers afterwards. @@ -2887,9 +2943,10 @@ loop from blocking if lower-priority coroutines are active, thus mapping low-priority coroutines to idle/background tasks). -It is recommended to give C watchers highest (C) -priority, to ensure that they are being run before any other watchers -after the poll (this doesn't matter for C watchers). +When used for this purpose, it is recommended to give C watchers +highest (C) priority, to ensure that they are being run before +any other watchers after the poll (this doesn't matter for C +watchers). Also, C watchers (and C watchers, too) should not activate ("feed") events into libev. While libev fully supports this, they @@ -2899,6 +2956,25 @@ C watcher ran (always remind yourself to coexist peacefully with others). +=head3 Abusing an C watcher for its side-effect + +C (and less often also C) watchers can also be +useful because they are called once per event loop iteration. For +example, if you want to handle a large number of connections fairly, you +normally only do a bit of work for each active connection, and if there +is more work to do, you wait for the next event loop iteration, so other +connections have a chance of making progress. + +Using an C watcher is almost enough: it will be called on the +next event loop iteration. However, that isn't as soon as possible - +without external events, your C watcher will not be invoked. + +This is where C watchers come in handy - all you need is a +single global idle watcher that is active as long as you have one active +C watcher. The C watcher makes sure the event loop +will not sleep, and the C watcher makes sure a callback gets +invoked. Neither watcher alone can do that. + =head3 Watcher-Specific Functions and Data Members =over 4 @@ -3108,7 +3184,7 @@ =item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) -=item ev_embed_set (ev_embed *, callback, struct ev_loop *embedded_loop) +=item ev_embed_set (ev_embed *, struct ev_loop *embedded_loop) Configures the watcher to embed the given loop, which must be embeddable. If the callback is C<0>, then C will be @@ -3139,7 +3215,7 @@ struct ev_loop *loop_hi = ev_default_init (0); struct ev_loop *loop_lo = 0; ev_embed embed; - + // see if there is a chance of getting one that works // (remember that a flags value of 0 means autodetection) loop_lo = ev_embeddable_backends () & ev_recommended_backends () @@ -3163,7 +3239,7 @@ struct ev_loop *loop = ev_default_init (0); struct ev_loop *loop_socket = 0; ev_embed embed; - + if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) if ((loop_socket = ev_loop_new (EVBACKEND_KQUEUE)) { @@ -3181,11 +3257,11 @@ Fork watchers are called when a C was detected (usually because whoever is a good citizen cared to tell libev about it by calling -C or C). The invocation is done before the -event loop blocks next and before C watchers are being called, -and only in the child after the fork. If whoever good citizen calling -C cheats and calls it in the wrong process, the fork -handlers will be invoked, too, of course. +C). The invocation is done before the event loop blocks next +and before C watchers are being called, and only in the child +after the fork. If whoever good citizen calling C cheats +and calls it in the wrong process, the fork handlers will be invoked, too, +of course. =head3 The special problem of life after fork - how is it possible? @@ -3288,7 +3364,7 @@ This functionality is very similar to C watchers, as signals, too, are asynchronous in nature, and signals, too, will be compressed (i.e. the number of callback invocations may be less than the number of -C calls). In fact, you could use signal watchers as a kind +C calls). In fact, you could use signal watchers as a kind of "global async watchers" by using a watcher on an otherwise unused signal, and C to signal this watcher from another thread, even without knowing which loop owns the signal. @@ -3475,7 +3551,7 @@ =item ev_feed_fd_event (loop, int fd, int revents) Feed an event on the given fd, as if a file descriptor backend detected -the given events it. +the given events. =item ev_feed_signal_event (loop, int signum) @@ -3559,6 +3635,46 @@ (((char *)w) - offsetof (struct my_biggy, t2)); } +=head2 AVOIDING FINISHING BEFORE RETURNING + +Often you have structures like this in event-based programs: + + callback () + { + free (request); + } + + request = start_new_request (..., callback); + +The intent is to start some "lengthy" operation. The C could be +used to cancel the operation, or do other things with it. + +It's not uncommon to have code paths in C that +immediately invoke the callback, for example, to report errors. Or you add +some caching layer that finds that it can skip the lengthy aspects of the +operation and simply invoke the callback with the result. + +The problem here is that this will happen I C +has returned, so C is not set. + +Even if you pass the request by some safer means to the callback, you +might want to do something to the request after starting it, such as +canceling it, which probably isn't working so well when the callback has +already been invoked. + +A common way around all these issues is to make sure that +C I returns before the callback is invoked. If +C immediately knows the result, it can artificially +delay invoking the callback by using a C or C watcher for +example, or more sneakily, by reusing an existing (stopped) watcher and +pushing it into the pending queue: + + ev_set_cb (watcher, callback); + ev_feed_event (EV_A_ watcher, 0); + +This way, C can safely return before the callback is +invoked, while not delaying callback invocation too much. + =head2 MODEL/NESTED EVENT LOOP INVOCATIONS AND EXIT CONDITIONS Often (especially in GUI toolkits) there are places where you have @@ -3569,7 +3685,7 @@ main C call, but not the nested one (e.g. user clicked "Quit", but a modal "Are you sure?" dialog is still waiting), or just the nested one and not the main one (e.g. user clocked "Ok" in a modal dialog), or some -other combination: In these cases, C will not work alone. +other combination: In these cases, a simple C will not work. The solution is to maintain "break this loop" variable for each C invocation, and use a loop around C until the condition is @@ -3581,7 +3697,7 @@ while (!exit_main_loop) ev_run (EV_DEFAULT_ EVRUN_ONCE); - // in a model watcher + // in a modal watcher int exit_nested_loop = 0; while (!exit_nested_loop) @@ -3765,20 +3881,20 @@ void wait_for_event (ev_watcher *w) { - ev_cb_set (w) = current_coro; + ev_set_cb (w, current_coro); switch_to (libev_coro); } That basically suspends the coroutine inside C and continues the libev coroutine, which, when appropriate, switches back to -this or any other coroutine. I am sure if you sue this your own :) +this or any other coroutine. You can do similar tricks if you have, say, threads with an event queue - instead of storing a coroutine, you store the queue object and instead of switching to a coroutine, you push the watcher onto the queue and notify any waiters. -To embed libev, see L, but in short, it's easiest to create two +To embed libev, see L, but in short, it's easiest to create two files, F and F that include the respective libev files: // my_ev.h @@ -3832,12 +3948,45 @@ =head1 C++ SUPPORT +=head2 C API + +The normal C API should work fine when used from C++: both ev.h and the +libev sources can be compiled as C++. Therefore, code that uses the C API +will work fine. + +Proper exception specifications might have to be added to callbacks passed +to libev: exceptions may be thrown only from watcher callbacks, all +other callbacks (allocator, syserr, loop acquire/release and periodic +reschedule callbacks) must not throw exceptions, and might need a C specification. If you have code that needs to be compiled as both C +and C++ you can use the C macro for this: + + static void + fatal_error (const char *msg) EV_THROW + { + perror (msg); + abort (); + } + + ... + ev_set_syserr_cb (fatal_error); + +The only API functions that can currently throw exceptions are C, +C, C and C (the latter +because it runs cleanup watchers). + +Throwing exceptions in watcher callbacks is only supported if libev itself +is compiled with a C++ compiler or your C and C++ environments allow +throwing exceptions through C libraries (most do). + +=head2 C++ API + Libev comes with some simplistic wrapper classes for C++ that mainly allow you to use some convenience methods to start/stop watchers and also change the callback model to a model using method callbacks on objects. To use it, - + #include This automatically includes F and puts all of its definitions (many @@ -3856,6 +4005,10 @@ you need support for other types of functors please contact the author (preferably after implementing it). +For all this to work, your C++ compiler either has to use the same calling +conventions as your C compiler (for static member functions), or you have +to embed libev and compile libev itself as C++. + Here is a list of things available in the C namespace: =over 4 @@ -3874,7 +4027,7 @@ For each C watcher in F there is a corresponding class of the same name in the C namespace, with the exception of C which is called C to avoid clashes with the C macro -defines by many implementations. +defined by many implementations. All of those classes have these methods: @@ -3946,7 +4099,7 @@ ... } } - + myfunctor f; ev::io w; @@ -3974,10 +4127,14 @@ =item w->set ([arguments]) -Basically the same as C, with the same arguments. Either this -method or a suitable start method must be called at least once. Unlike the -C counterpart, an active watcher gets automatically stopped and restarted -when reconfiguring it with this method. +Basically the same as C (except for C watchers>), +with the same arguments. Either this method or a suitable start method +must be called at least once. Unlike the C counterpart, an active watcher +gets automatically stopped and restarted when reconfiguring it with this +method. + +For C watchers this method is called C, to avoid +clashing with the C method. =item w->start () @@ -4091,6 +4248,14 @@ time of this writing, only C and C), to be found at L. +=item Javascript + +Node.js (L) uses libev as the underlying event library. + +=item Others + +There are others, and I stopped counting. + =back @@ -4399,6 +4564,13 @@ file descriptors again. Note that the replacement function has to close the underlying OS handle. +=item EV_USE_WSASOCKET + +If defined to be C<1>, libev will use C to create its internal +communication socket, which works better in some environments. Otherwise, +the normal C function will be used, which works better in other +environments. + =item EV_USE_POLL If defined to be C<1>, libev will compile in support for the C(2) @@ -4443,19 +4615,31 @@ be detected at runtime. If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. +=item EV_NO_SMP + +If defined to be C<1>, libev will assume that memory is always coherent +between threads, that is, threads can be used, but threads never run on +different cpus (or different cpu cores). This reduces dependencies +and makes libev faster. + +=item EV_NO_THREADS + +If defined to be C<1>, libev will assume that it will never be called from +different threads (that includes signal handlers), which is a stronger +assumption than C, above. This reduces dependencies and makes +libev faster. + =item EV_ATOMIC_T Libev requires an integer type (suitable for storing C<0> or C<1>) whose -access is atomic and serialised with respect to other threads or signal -contexts. No such type is easily found in the C language, so you can -provide your own type that you know is safe for your purposes. It is used -both for signal handler "locking" as well as for signal and thread safety -in C watchers. +access is atomic with respect to other threads or signal contexts. No +such type is easily found in the C language, so you can provide your own +type that you know is safe for your purposes. It is used both for signal +handler "locking" as well as for signal and thread safety in C +watchers. In the absence of this define, libev will use C -(from F), which is usually good enough on most platforms, -although strictly speaking using a type that also implies a memory fence -is required. +(from F), which is usually good enough on most platforms. =item EV_H (h) @@ -4538,7 +4722,7 @@ #define EV_ASYNC_ENABLE 1 The actual value is a bitset, it can be a combination of the following -values: +values (by default, all of these are enabled): =over 4 @@ -4553,6 +4737,9 @@ gcc is recommended, as well as C<-DNDEBUG>, as libev contains a number of assertions. +The default is off when C<__OPTIMIZE_SIZE__> is defined by your compiler +(e.g. gcc with C<-Os>). + =item C<2> - faster/larger data structures Replaces the small 2-heap for timer management by a faster 4-heap, larger @@ -4560,6 +4747,9 @@ and can additionally have an effect on the size of data structures at runtime. +The default is off when C<__OPTIMIZE_SIZE__> is defined by your compiler +(e.g. gcc with C<-Os>). + =item C<4> - full API configuration This enables priorities (sets C=2 and C=-2), and @@ -4600,6 +4790,20 @@ your program might be left out as well - a binary starting a timer and an I/O watcher then might come out at only 5Kb. +=item EV_API_STATIC + +If this symbol is defined (by default it is not), then all identifiers +will have static linkage. This means that libev will not export any +identifiers, and you cannot link against libev anymore. This can be useful +when you embed libev, only want to use libev functions in a single file, +and do not want its identifiers to be visible. + +To use this, define C and include F in the file that +wants to use libev. + +This option only works when libev is compiled with a C compiler, as C++ +doesn't support the required declaration syntax. + =item EV_AVOID_STDIO If this is set to C<1> at compiletime, then libev will avoid using stdio @@ -4813,7 +5017,7 @@ =back -See also L. +See also L. =head3 COROUTINES @@ -5114,8 +5318,8 @@ C could complicate things, however. The most portable way to handle signals is to block signals in all threads -except the initial one, and run the default loop in the initial thread as -well. +except the initial one, and run the signal handling loop in the initial +thread as well. =item C must be large enough for common memory allocation sizes @@ -5229,7 +5433,7 @@ =item C backwards compatibility mechanism The backward compatibility mechanism can be controlled by -C. See L in the L +C. See L in the L section. =item C and C have been removed @@ -5282,7 +5486,7 @@ =item active A watcher is active as long as it has been started and not yet stopped. -See L for details. +See L for details. =item application @@ -5328,7 +5532,7 @@ =item pending A watcher is pending as soon as the corresponding event has been -detected. See L for details. +detected. See L for details. =item real time