… | |
… | |
196 | \& return 0; |
196 | \& return 0; |
197 | \& } |
197 | \& } |
198 | .Ve |
198 | .Ve |
199 | .SH "DESCRIPTION" |
199 | .SH "DESCRIPTION" |
200 | .IX Header "DESCRIPTION" |
200 | .IX Header "DESCRIPTION" |
|
|
201 | The newest version of this document is also available as a html-formatted |
|
|
202 | web page you might find easier to navigate when reading it for the first |
|
|
203 | time: <http://cvs.schmorp.de/libev/ev.html>. |
|
|
204 | .PP |
201 | Libev is an event loop: you register interest in certain events (such as a |
205 | Libev is an event loop: you register interest in certain events (such as a |
202 | file descriptor being readable or a timeout occuring), and it will manage |
206 | file descriptor being readable or a timeout occuring), and it will manage |
203 | these event sources and provide your program with events. |
207 | these event sources and provide your program with events. |
204 | .PP |
208 | .PP |
205 | To do this, it must take more or less complete control over your process |
209 | To do this, it must take more or less complete control over your process |
… | |
… | |
2274 | If undefined or defined to \f(CW1\fR, then all event-loop-specific functions |
2278 | If undefined or defined to \f(CW1\fR, then all event-loop-specific functions |
2275 | will have the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument, and you can create |
2279 | will have the \f(CW\*(C`struct ev_loop *\*(C'\fR as first argument, and you can create |
2276 | additional independent event loops. Otherwise there will be no support |
2280 | additional independent event loops. Otherwise there will be no support |
2277 | for multiple event loops and there is no first event loop pointer |
2281 | for multiple event loops and there is no first event loop pointer |
2278 | argument. Instead, all functions act on the single default loop. |
2282 | argument. Instead, all functions act on the single default loop. |
|
|
2283 | .IP "\s-1EV_MINPRI\s0" 4 |
|
|
2284 | .IX Item "EV_MINPRI" |
|
|
2285 | .PD 0 |
|
|
2286 | .IP "\s-1EV_MAXPRI\s0" 4 |
|
|
2287 | .IX Item "EV_MAXPRI" |
|
|
2288 | .PD |
|
|
2289 | The range of allowed priorities. \f(CW\*(C`EV_MINPRI\*(C'\fR must be smaller or equal to |
|
|
2290 | \&\f(CW\*(C`EV_MAXPRI\*(C'\fR, but otherwise there are no non-obvious limitations. You can |
|
|
2291 | provide for more priorities by overriding those symbols (usually defined |
|
|
2292 | to be \f(CW\*(C`\-2\*(C'\fR and \f(CW2\fR, respectively). |
|
|
2293 | .Sp |
|
|
2294 | When doing priority-based operations, libev usually has to linearly search |
|
|
2295 | all the priorities, so having many of them (hundreds) uses a lot of space |
|
|
2296 | and time, so using the defaults of five priorities (\-2 .. +2) is usually |
|
|
2297 | fine. |
|
|
2298 | .Sp |
|
|
2299 | If your embedding app does not need any priorities, defining these both to |
|
|
2300 | \&\f(CW0\fR will save some memory and cpu. |
2279 | .IP "\s-1EV_PERIODIC_ENABLE\s0" 4 |
2301 | .IP "\s-1EV_PERIODIC_ENABLE\s0" 4 |
2280 | .IX Item "EV_PERIODIC_ENABLE" |
2302 | .IX Item "EV_PERIODIC_ENABLE" |
2281 | If undefined or defined to be \f(CW1\fR, then periodic timers are supported. If |
2303 | If undefined or defined to be \f(CW1\fR, then periodic timers are supported. If |
2282 | defined to be \f(CW0\fR, then they are not. Disabling them saves a few kB of |
2304 | defined to be \f(CW0\fR, then they are not. Disabling them saves a few kB of |
2283 | code. |
2305 | code. |
… | |
… | |
2385 | libev will be explained. For complexity discussions about backends see the |
2407 | libev will be explained. For complexity discussions about backends see the |
2386 | documentation for \f(CW\*(C`ev_default_init\*(C'\fR. |
2408 | documentation for \f(CW\*(C`ev_default_init\*(C'\fR. |
2387 | .RS 4 |
2409 | .RS 4 |
2388 | .IP "Starting and stopping timer/periodic watchers: O(log skipped_other_timers)" 4 |
2410 | .IP "Starting and stopping timer/periodic watchers: O(log skipped_other_timers)" 4 |
2389 | .IX Item "Starting and stopping timer/periodic watchers: O(log skipped_other_timers)" |
2411 | .IX Item "Starting and stopping timer/periodic watchers: O(log skipped_other_timers)" |
2390 | .PD 0 |
2412 | This means that, when you have a watcher that triggers in one hour and |
|
|
2413 | there are 100 watchers that would trigger before that then inserting will |
|
|
2414 | have to skip those 100 watchers. |
2391 | .IP "Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)" 4 |
2415 | .IP "Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)" 4 |
2392 | .IX Item "Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)" |
2416 | .IX Item "Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers)" |
|
|
2417 | That means that for changing a timer costs less than removing/adding them |
|
|
2418 | as only the relative motion in the event queue has to be paid for. |
2393 | .IP "Starting io/check/prepare/idle/signal/child watchers: O(1)" 4 |
2419 | .IP "Starting io/check/prepare/idle/signal/child watchers: O(1)" 4 |
2394 | .IX Item "Starting io/check/prepare/idle/signal/child watchers: O(1)" |
2420 | .IX Item "Starting io/check/prepare/idle/signal/child watchers: O(1)" |
|
|
2421 | These just add the watcher into an array or at the head of a list. If |
|
|
2422 | the array needs to be extended libev needs to realloc and move the whole |
|
|
2423 | array, but this happen asymptotically less and less with more watchers, |
|
|
2424 | thus amortised O(1). |
2395 | .IP "Stopping check/prepare/idle watchers: O(1)" 4 |
2425 | .IP "Stopping check/prepare/idle watchers: O(1)" 4 |
2396 | .IX Item "Stopping check/prepare/idle watchers: O(1)" |
2426 | .IX Item "Stopping check/prepare/idle watchers: O(1)" |
|
|
2427 | .PD 0 |
2397 | .IP "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % \s-1EV_PID_HASHSIZE\s0))" 4 |
2428 | .IP "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % \s-1EV_PID_HASHSIZE\s0))" 4 |
2398 | .IX Item "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))" |
2429 | .IX Item "Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))" |
|
|
2430 | .PD |
|
|
2431 | These watchers are stored in lists then need to be walked to find the |
|
|
2432 | correct watcher to remove. The lists are usually short (you don't usually |
|
|
2433 | have many watchers waiting for the same fd or signal). |
2399 | .IP "Finding the next timer per loop iteration: O(1)" 4 |
2434 | .IP "Finding the next timer per loop iteration: O(1)" 4 |
2400 | .IX Item "Finding the next timer per loop iteration: O(1)" |
2435 | .IX Item "Finding the next timer per loop iteration: O(1)" |
|
|
2436 | .PD 0 |
2401 | .IP "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" 4 |
2437 | .IP "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" 4 |
2402 | .IX Item "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" |
2438 | .IX Item "Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)" |
|
|
2439 | .PD |
|
|
2440 | A change means an I/O watcher gets started or stopped, which requires |
|
|
2441 | libev to recalculate its status (and possibly tell the kernel). |
2403 | .IP "Activating one watcher: O(1)" 4 |
2442 | .IP "Activating one watcher: O(1)" 4 |
2404 | .IX Item "Activating one watcher: O(1)" |
2443 | .IX Item "Activating one watcher: O(1)" |
|
|
2444 | .PD 0 |
|
|
2445 | .IP "Priority handling: O(number_of_priorities)" 4 |
|
|
2446 | .IX Item "Priority handling: O(number_of_priorities)" |
|
|
2447 | .PD |
|
|
2448 | Priorities are implemented by allocating some space for each |
|
|
2449 | priority. When doing priority-based operations, libev usually has to |
|
|
2450 | linearly search all the priorities. |
2405 | .RE |
2451 | .RE |
2406 | .RS 4 |
2452 | .RS 4 |
2407 | .PD |
|
|
2408 | .SH "AUTHOR" |
2453 | .SH "AUTHOR" |
2409 | .IX Header "AUTHOR" |
2454 | .IX Header "AUTHOR" |
2410 | Marc Lehmann <libev@schmorp.de>. |
2455 | Marc Lehmann <libev@schmorp.de>. |