ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.185 by root, Tue Sep 23 09:13:59 2008 UTC vs.
Revision 1.193 by root, Wed Oct 1 04:25:25 2008 UTC

214C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for 214C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for
215recommended ones. 215recommended ones.
216 216
217See the description of C<ev_embed> watchers for more info. 217See the description of C<ev_embed> watchers for more info.
218 218
219=item ev_set_allocator (void *(*cb)(void *ptr, long size)) 219=item ev_set_allocator (void *(*cb)(void *ptr, long size)) [NOT REENTRANT]
220 220
221Sets the allocation function to use (the prototype is similar - the 221Sets the allocation function to use (the prototype is similar - the
222semantics are identical to the C<realloc> C89/SuS/POSIX function). It is 222semantics are identical to the C<realloc> C89/SuS/POSIX function). It is
223used to allocate and free memory (no surprises here). If it returns zero 223used to allocate and free memory (no surprises here). If it returns zero
224when memory needs to be allocated (C<size != 0>), the library might abort 224when memory needs to be allocated (C<size != 0>), the library might abort
250 } 250 }
251 251
252 ... 252 ...
253 ev_set_allocator (persistent_realloc); 253 ev_set_allocator (persistent_realloc);
254 254
255=item ev_set_syserr_cb (void (*cb)(const char *msg)); 255=item ev_set_syserr_cb (void (*cb)(const char *msg)); [NOT REENTRANT]
256 256
257Set the callback function to call on a retryable system call error (such 257Set the callback function to call on a retryable system call error (such
258as failed select, poll, epoll_wait). The message is a printable string 258as failed select, poll, epoll_wait). The message is a printable string
259indicating the system call or subsystem causing the problem. If this 259indicating the system call or subsystem causing the problem. If this
260callback is set, then libev will expect it to remedy the situation, no 260callback is set, then libev will expect it to remedy the situation, no
1625 1625
1626=back 1626=back
1627 1627
1628=head3 Examples 1628=head3 Examples
1629 1629
1630Example: Try to exit cleanly on SIGINT and SIGTERM. 1630Example: Try to exit cleanly on SIGINT.
1631 1631
1632 static void 1632 static void
1633 sigint_cb (struct ev_loop *loop, struct ev_signal *w, int revents) 1633 sigint_cb (struct ev_loop *loop, struct ev_signal *w, int revents)
1634 { 1634 {
1635 ev_unloop (loop, EVUNLOOP_ALL); 1635 ev_unloop (loop, EVUNLOOP_ALL);
1636 } 1636 }
1637 1637
1638 struct ev_signal signal_watcher; 1638 struct ev_signal signal_watcher;
1639 ev_signal_init (&signal_watcher, sigint_cb, SIGINT); 1639 ev_signal_init (&signal_watcher, sigint_cb, SIGINT);
1640 ev_signal_start (loop, &sigint_cb); 1640 ev_signal_start (loop, &signal_watcher);
1641 1641
1642 1642
1643=head2 C<ev_child> - watch out for process status changes 1643=head2 C<ev_child> - watch out for process status changes
1644 1644
1645Child watchers trigger when your process receives a SIGCHLD in response to 1645Child watchers trigger when your process receives a SIGCHLD in response to
2242So when you want to use this feature you will always have to be prepared 2242So when you want to use this feature you will always have to be prepared
2243that you cannot get an embeddable loop. The recommended way to get around 2243that you cannot get an embeddable loop. The recommended way to get around
2244this is to have a separate variables for your embeddable loop, try to 2244this is to have a separate variables for your embeddable loop, try to
2245create it, and if that fails, use the normal loop for everything. 2245create it, and if that fails, use the normal loop for everything.
2246 2246
2247=head3 C<ev_embed> and fork
2248
2249While the C<ev_embed> watcher is running, forks in the embedding loop will
2250automatically be applied to the embedded loop as well, so no special
2251fork handling is required in that case. When the watcher is not running,
2252however, it is still the task of the libev user to call C<ev_loop_fork ()>
2253as applicable.
2254
2247=head3 Watcher-Specific Functions and Data Members 2255=head3 Watcher-Specific Functions and Data Members
2248 2256
2249=over 4 2257=over 4
2250 2258
2251=item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop) 2259=item ev_embed_init (ev_embed *, callback, struct ev_loop *embedded_loop)
2376=over 4 2384=over 4
2377 2385
2378=item queueing from a signal handler context 2386=item queueing from a signal handler context
2379 2387
2380To implement race-free queueing, you simply add to the queue in the signal 2388To implement race-free queueing, you simply add to the queue in the signal
2381handler but you block the signal handler in the watcher callback. Here is an example that does that for 2389handler but you block the signal handler in the watcher callback. Here is
2382some fictitious SIGUSR1 handler: 2390an example that does that for some fictitious SIGUSR1 handler:
2383 2391
2384 static ev_async mysig; 2392 static ev_async mysig;
2385 2393
2386 static void 2394 static void
2387 sigusr1_handler (void) 2395 sigusr1_handler (void)
2494=over 4 2502=over 4
2495 2503
2496=item ev_once (loop, int fd, int events, ev_tstamp timeout, callback) 2504=item ev_once (loop, int fd, int events, ev_tstamp timeout, callback)
2497 2505
2498This function combines a simple timer and an I/O watcher, calls your 2506This function combines a simple timer and an I/O watcher, calls your
2499callback on whichever event happens first and automatically stop both 2507callback on whichever event happens first and automatically stops both
2500watchers. This is useful if you want to wait for a single event on an fd 2508watchers. This is useful if you want to wait for a single event on an fd
2501or timeout without having to allocate/configure/start/stop/free one or 2509or timeout without having to allocate/configure/start/stop/free one or
2502more watchers yourself. 2510more watchers yourself.
2503 2511
2504If C<fd> is less than 0, then no I/O watcher will be started and events 2512If C<fd> is less than 0, then no I/O watcher will be started and the
2505is being ignored. Otherwise, an C<ev_io> watcher for the given C<fd> and 2513C<events> argument is being ignored. Otherwise, an C<ev_io> watcher for
2506C<events> set will be created and started. 2514the given C<fd> and C<events> set will be created and started.
2507 2515
2508If C<timeout> is less than 0, then no timeout watcher will be 2516If C<timeout> is less than 0, then no timeout watcher will be
2509started. Otherwise an C<ev_timer> watcher with after = C<timeout> (and 2517started. Otherwise an C<ev_timer> watcher with after = C<timeout> (and
2510repeat = 0) will be started. While C<0> is a valid timeout, it is of 2518repeat = 0) will be started. C<0> is a valid timeout.
2511dubious value.
2512 2519
2513The callback has the type C<void (*cb)(int revents, void *arg)> and gets 2520The callback has the type C<void (*cb)(int revents, void *arg)> and gets
2514passed an C<revents> set like normal event callbacks (a combination of 2521passed an C<revents> set like normal event callbacks (a combination of
2515C<EV_ERROR>, C<EV_READ>, C<EV_WRITE> or C<EV_TIMEOUT>) and the C<arg> 2522C<EV_ERROR>, C<EV_READ>, C<EV_WRITE> or C<EV_TIMEOUT>) and the C<arg>
2516value passed to C<ev_once>: 2523value passed to C<ev_once>. Note that it is possible to receive I<both>
2524a timeout and an io event at the same time - you probably should give io
2525events precedence.
2526
2527Example: wait up to ten seconds for data to appear on STDIN_FILENO.
2517 2528
2518 static void stdin_ready (int revents, void *arg) 2529 static void stdin_ready (int revents, void *arg)
2519 { 2530 {
2531 if (revents & EV_READ)
2532 /* stdin might have data for us, joy! */;
2520 if (revents & EV_TIMEOUT) 2533 else if (revents & EV_TIMEOUT)
2521 /* doh, nothing entered */; 2534 /* doh, nothing entered */;
2522 else if (revents & EV_READ)
2523 /* stdin might have data for us, joy! */;
2524 } 2535 }
2525 2536
2526 ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0); 2537 ev_once (STDIN_FILENO, EV_READ, 10., stdin_ready, 0);
2527 2538
2528=item ev_feed_event (ev_loop *, watcher *, int revents) 2539=item ev_feed_event (ev_loop *, watcher *, int revents)
3298And a F<ev_cpp.C> implementation file that contains libev proper and is compiled: 3309And a F<ev_cpp.C> implementation file that contains libev proper and is compiled:
3299 3310
3300 #include "ev_cpp.h" 3311 #include "ev_cpp.h"
3301 #include "ev.c" 3312 #include "ev.c"
3302 3313
3314=head1 INTERACTION WITH OTHER PROGRAMS OR LIBRARIES
3303 3315
3304=head1 THREADS AND COROUTINES 3316=head2 THREADS AND COROUTINES
3305 3317
3306=head2 THREADS 3318=head3 THREADS
3307 3319
3308Libev itself is thread-safe (unless the opposite is specifically 3320All libev functions are reentrant and thread-safe unless explicitly
3309documented for a function), but it uses no locking itself. This means that 3321documented otherwise, but libev implements no locking itself. This means
3310you can use as many loops as you want in parallel, as long as only one 3322that you can use as many loops as you want in parallel, as long as there
3311thread ever calls into one libev function with the same loop parameter: 3323are no concurrent calls into any libev function with the same loop
3324parameter (C<ev_default_*> calls have an implicit default loop parameter,
3312libev guarantees that different event loops share no data structures that 3325of course): libev guarantees that different event loops share no data
3313need locking. 3326structures that need any locking.
3314 3327
3315Or to put it differently: calls with different loop parameters can be done 3328Or to put it differently: calls with different loop parameters can be done
3316concurrently from multiple threads, calls with the same loop parameter 3329concurrently from multiple threads, calls with the same loop parameter
3317must be done serially (but can be done from different threads, as long as 3330must be done serially (but can be done from different threads, as long as
3318only one thread ever is inside a call at any point in time, e.g. by using 3331only one thread ever is inside a call at any point in time, e.g. by using
3319a mutex per loop). 3332a mutex per loop).
3320 3333
3321Specifically to support threads (and signal handlers), libev implements 3334Specifically to support threads (and signal handlers), libev implements
3322so-called C<ev_async> watchers, which allow some limited form of 3335so-called C<ev_async> watchers, which allow some limited form of
3323concurrency on the same event loop. 3336concurrency on the same event loop, namely waking it up "from the
3337outside".
3324 3338
3325If you want to know which design (one loop, locking, or multiple loops 3339If you want to know which design (one loop, locking, or multiple loops
3326without or something else still) is best for your problem, then I cannot 3340without or something else still) is best for your problem, then I cannot
3327help you. I can give some generic advice however: 3341help you, but here is some generic advice:
3328 3342
3329=over 4 3343=over 4
3330 3344
3331=item * most applications have a main thread: use the default libev loop 3345=item * most applications have a main thread: use the default libev loop
3332in that thread, or create a separate thread running only the default loop. 3346in that thread, or create a separate thread running only the default loop.
3356default loop and triggering an C<ev_async> watcher from the default loop 3370default loop and triggering an C<ev_async> watcher from the default loop
3357watcher callback into the event loop interested in the signal. 3371watcher callback into the event loop interested in the signal.
3358 3372
3359=back 3373=back
3360 3374
3361=head2 COROUTINES 3375=head3 COROUTINES
3362 3376
3363Libev is much more accommodating to coroutines ("cooperative threads"): 3377Libev is very accommodating to coroutines ("cooperative threads"):
3364libev fully supports nesting calls to it's functions from different 3378libev fully supports nesting calls to its functions from different
3365coroutines (e.g. you can call C<ev_loop> on the same loop from two 3379coroutines (e.g. you can call C<ev_loop> on the same loop from two
3366different coroutines and switch freely between both coroutines running the 3380different coroutines, and switch freely between both coroutines running the
3367loop, as long as you don't confuse yourself). The only exception is that 3381loop, as long as you don't confuse yourself). The only exception is that
3368you must not do this from C<ev_periodic> reschedule callbacks. 3382you must not do this from C<ev_periodic> reschedule callbacks.
3369 3383
3370Care has been taken to ensure that libev does not keep local state inside 3384Care has been taken to ensure that libev does not keep local state inside
3371C<ev_loop>, and other calls do not usually allow coroutine switches. 3385C<ev_loop>, and other calls do not usually allow for coroutine switches as
3386they do not clal any callbacks.
3372 3387
3388=head2 COMPILER WARNINGS
3373 3389
3374=head1 COMPLEXITIES 3390Depending on your compiler and compiler settings, you might get no or a
3391lot of warnings when compiling libev code. Some people are apparently
3392scared by this.
3375 3393
3376In this section the complexities of (many of) the algorithms used inside 3394However, these are unavoidable for many reasons. For one, each compiler
3377libev will be explained. For complexity discussions about backends see the 3395has different warnings, and each user has different tastes regarding
3378documentation for C<ev_default_init>. 3396warning options. "Warn-free" code therefore cannot be a goal except when
3397targeting a specific compiler and compiler-version.
3379 3398
3380All of the following are about amortised time: If an array needs to be 3399Another reason is that some compiler warnings require elaborate
3381extended, libev needs to realloc and move the whole array, but this 3400workarounds, or other changes to the code that make it less clear and less
3382happens asymptotically never with higher number of elements, so O(1) might 3401maintainable.
3383mean it might do a lengthy realloc operation in rare cases, but on average
3384it is much faster and asymptotically approaches constant time.
3385 3402
3386=over 4 3403And of course, some compiler warnings are just plain stupid, or simply
3404wrong (because they don't actually warn about the condition their message
3405seems to warn about). For example, certain older gcc versions had some
3406warnings that resulted an extreme number of false positives. These have
3407been fixed, but some people still insist on making code warn-free with
3408such buggy versions.
3387 3409
3388=item Starting and stopping timer/periodic watchers: O(log skipped_other_timers) 3410While libev is written to generate as few warnings as possible,
3411"warn-free" code is not a goal, and it is recommended not to build libev
3412with any compiler warnings enabled unless you are prepared to cope with
3413them (e.g. by ignoring them). Remember that warnings are just that:
3414warnings, not errors, or proof of bugs.
3389 3415
3390This means that, when you have a watcher that triggers in one hour and
3391there are 100 watchers that would trigger before that then inserting will
3392have to skip roughly seven (C<ld 100>) of these watchers.
3393 3416
3394=item Changing timer/periodic watchers (by autorepeat or calling again): O(log skipped_other_timers) 3417=head2 VALGRIND
3395 3418
3396That means that changing a timer costs less than removing/adding them 3419Valgrind has a special section here because it is a popular tool that is
3397as only the relative motion in the event queue has to be paid for. 3420highly useful. Unfortunately, valgrind reports are very hard to interpret.
3398 3421
3399=item Starting io/check/prepare/idle/signal/child/fork/async watchers: O(1) 3422If you think you found a bug (memory leak, uninitialised data access etc.)
3423in libev, then check twice: If valgrind reports something like:
3400 3424
3401These just add the watcher into an array or at the head of a list. 3425 ==2274== definitely lost: 0 bytes in 0 blocks.
3426 ==2274== possibly lost: 0 bytes in 0 blocks.
3427 ==2274== still reachable: 256 bytes in 1 blocks.
3402 3428
3403=item Stopping check/prepare/idle/fork/async watchers: O(1) 3429Then there is no memory leak, just as memory accounted to global variables
3430is not a memleak - the memory is still being refernced, and didn't leak.
3404 3431
3405=item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE)) 3432Similarly, under some circumstances, valgrind might report kernel bugs
3433as if it were a bug in libev (e.g. in realloc or in the poll backend,
3434although an acceptable workaround has been found here), or it might be
3435confused.
3406 3436
3407These watchers are stored in lists then need to be walked to find the 3437Keep in mind that valgrind is a very good tool, but only a tool. Don't
3408correct watcher to remove. The lists are usually short (you don't usually 3438make it into some kind of religion.
3409have many watchers waiting for the same fd or signal).
3410 3439
3411=item Finding the next timer in each loop iteration: O(1) 3440If you are unsure about something, feel free to contact the mailing list
3441with the full valgrind report and an explanation on why you think this
3442is a bug in libev (best check the archives, too :). However, don't be
3443annoyed when you get a brisk "this is no bug" answer and take the chance
3444of learning how to interpret valgrind properly.
3412 3445
3413By virtue of using a binary or 4-heap, the next timer is always found at a 3446If you need, for some reason, empty reports from valgrind for your project
3414fixed position in the storage array. 3447I suggest using suppression lists.
3415 3448
3416=item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)
3417 3449
3418A change means an I/O watcher gets started or stopped, which requires 3450=head1 PORTABILITY NOTES
3419libev to recalculate its status (and possibly tell the kernel, depending
3420on backend and whether C<ev_io_set> was used).
3421 3451
3422=item Activating one watcher (putting it into the pending state): O(1)
3423
3424=item Priority handling: O(number_of_priorities)
3425
3426Priorities are implemented by allocating some space for each
3427priority. When doing priority-based operations, libev usually has to
3428linearly search all the priorities, but starting/stopping and activating
3429watchers becomes O(1) with respect to priority handling.
3430
3431=item Sending an ev_async: O(1)
3432
3433=item Processing ev_async_send: O(number_of_async_watchers)
3434
3435=item Processing signals: O(max_signal_number)
3436
3437Sending involves a system call I<iff> there were no other C<ev_async_send>
3438calls in the current loop iteration. Checking for async and signal events
3439involves iterating over all running async watchers or all signal numbers.
3440
3441=back
3442
3443
3444=head1 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS 3452=head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS
3445 3453
3446Win32 doesn't support any of the standards (e.g. POSIX) that libev 3454Win32 doesn't support any of the standards (e.g. POSIX) that libev
3447requires, and its I/O model is fundamentally incompatible with the POSIX 3455requires, and its I/O model is fundamentally incompatible with the POSIX
3448model. Libev still offers limited functionality on this platform in 3456model. Libev still offers limited functionality on this platform in
3449the form of the C<EVBACKEND_SELECT> backend, and only supports socket 3457the form of the C<EVBACKEND_SELECT> backend, and only supports socket
3536wrap all I/O functions and provide your own fd management, but the cost of 3544wrap all I/O functions and provide your own fd management, but the cost of
3537calling select (O(n²)) will likely make this unworkable. 3545calling select (O(n²)) will likely make this unworkable.
3538 3546
3539=back 3547=back
3540 3548
3541
3542=head1 PORTABILITY REQUIREMENTS 3549=head2 PORTABILITY REQUIREMENTS
3543 3550
3544In addition to a working ISO-C implementation, libev relies on a few 3551In addition to a working ISO-C implementation and of course the
3545additional extensions: 3552backend-specific APIs, libev relies on a few additional extensions:
3546 3553
3547=over 4 3554=over 4
3548 3555
3549=item C<void (*)(ev_watcher_type *, int revents)> must have compatible 3556=item C<void (*)(ev_watcher_type *, int revents)> must have compatible
3550calling conventions regardless of C<ev_watcher_type *>. 3557calling conventions regardless of C<ev_watcher_type *>.
3575except the initial one, and run the default loop in the initial thread as 3582except the initial one, and run the default loop in the initial thread as
3576well. 3583well.
3577 3584
3578=item C<long> must be large enough for common memory allocation sizes 3585=item C<long> must be large enough for common memory allocation sizes
3579 3586
3580To improve portability and simplify using libev, libev uses C<long> 3587To improve portability and simplify its API, libev uses C<long> internally
3581internally instead of C<size_t> when allocating its data structures. On 3588instead of C<size_t> when allocating its data structures. On non-POSIX
3582non-POSIX systems (Microsoft...) this might be unexpectedly low, but 3589systems (Microsoft...) this might be unexpectedly low, but is still at
3583is still at least 31 bits everywhere, which is enough for hundreds of 3590least 31 bits everywhere, which is enough for hundreds of millions of
3584millions of watchers. 3591watchers.
3585 3592
3586=item C<double> must hold a time value in seconds with enough accuracy 3593=item C<double> must hold a time value in seconds with enough accuracy
3587 3594
3588The type C<double> is used to represent timestamps. It is required to 3595The type C<double> is used to represent timestamps. It is required to
3589have at least 51 bits of mantissa (and 9 bits of exponent), which is good 3596have at least 51 bits of mantissa (and 9 bits of exponent), which is good
3593=back 3600=back
3594 3601
3595If you know of other additional requirements drop me a note. 3602If you know of other additional requirements drop me a note.
3596 3603
3597 3604
3598=head1 COMPILER WARNINGS 3605=head1 ALGORITHMIC COMPLEXITIES
3599 3606
3600Depending on your compiler and compiler settings, you might get no or a 3607In this section the complexities of (many of) the algorithms used inside
3601lot of warnings when compiling libev code. Some people are apparently 3608libev will be documented. For complexity discussions about backends see
3602scared by this. 3609the documentation for C<ev_default_init>.
3603 3610
3604However, these are unavoidable for many reasons. For one, each compiler 3611All of the following are about amortised time: If an array needs to be
3605has different warnings, and each user has different tastes regarding 3612extended, libev needs to realloc and move the whole array, but this
3606warning options. "Warn-free" code therefore cannot be a goal except when 3613happens asymptotically rarer with higher number of elements, so O(1) might
3607targeting a specific compiler and compiler-version. 3614mean that libev does a lengthy realloc operation in rare cases, but on
3615average it is much faster and asymptotically approaches constant time.
3608 3616
3609Another reason is that some compiler warnings require elaborate 3617=over 4
3610workarounds, or other changes to the code that make it less clear and less
3611maintainable.
3612 3618
3613And of course, some compiler warnings are just plain stupid, or simply 3619=item Starting and stopping timer/periodic watchers: O(log skipped_other_timers)
3614wrong (because they don't actually warn about the condition their message
3615seems to warn about).
3616 3620
3617While libev is written to generate as few warnings as possible, 3621This means that, when you have a watcher that triggers in one hour and
3618"warn-free" code is not a goal, and it is recommended not to build libev 3622there are 100 watchers that would trigger before that, then inserting will
3619with any compiler warnings enabled unless you are prepared to cope with 3623have to skip roughly seven (C<ld 100>) of these watchers.
3620them (e.g. by ignoring them). Remember that warnings are just that:
3621warnings, not errors, or proof of bugs.
3622 3624
3625=item Changing timer/periodic watchers (by autorepeat or calling again): O(log skipped_other_timers)
3623 3626
3624=head1 VALGRIND 3627That means that changing a timer costs less than removing/adding them,
3628as only the relative motion in the event queue has to be paid for.
3625 3629
3626Valgrind has a special section here because it is a popular tool that is 3630=item Starting io/check/prepare/idle/signal/child/fork/async watchers: O(1)
3627highly useful, but valgrind reports are very hard to interpret.
3628 3631
3629If you think you found a bug (memory leak, uninitialised data access etc.) 3632These just add the watcher into an array or at the head of a list.
3630in libev, then check twice: If valgrind reports something like:
3631 3633
3632 ==2274== definitely lost: 0 bytes in 0 blocks. 3634=item Stopping check/prepare/idle/fork/async watchers: O(1)
3633 ==2274== possibly lost: 0 bytes in 0 blocks.
3634 ==2274== still reachable: 256 bytes in 1 blocks.
3635 3635
3636Then there is no memory leak. Similarly, under some circumstances, 3636=item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE))
3637valgrind might report kernel bugs as if it were a bug in libev, or it
3638might be confused (it is a very good tool, but only a tool).
3639 3637
3640If you are unsure about something, feel free to contact the mailing list 3638These watchers are stored in lists, so they need to be walked to find the
3641with the full valgrind report and an explanation on why you think this is 3639correct watcher to remove. The lists are usually short (you don't usually
3642a bug in libev. However, don't be annoyed when you get a brisk "this is 3640have many watchers waiting for the same fd or signal: one is typical, two
3643no bug" answer and take the chance of learning how to interpret valgrind 3641is rare).
3644properly.
3645 3642
3646If you need, for some reason, empty reports from valgrind for your project 3643=item Finding the next timer in each loop iteration: O(1)
3647I suggest using suppression lists. 3644
3645By virtue of using a binary or 4-heap, the next timer is always found at a
3646fixed position in the storage array.
3647
3648=item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd)
3649
3650A change means an I/O watcher gets started or stopped, which requires
3651libev to recalculate its status (and possibly tell the kernel, depending
3652on backend and whether C<ev_io_set> was used).
3653
3654=item Activating one watcher (putting it into the pending state): O(1)
3655
3656=item Priority handling: O(number_of_priorities)
3657
3658Priorities are implemented by allocating some space for each
3659priority. When doing priority-based operations, libev usually has to
3660linearly search all the priorities, but starting/stopping and activating
3661watchers becomes O(1) with respect to priority handling.
3662
3663=item Sending an ev_async: O(1)
3664
3665=item Processing ev_async_send: O(number_of_async_watchers)
3666
3667=item Processing signals: O(max_signal_number)
3668
3669Sending involves a system call I<iff> there were no other C<ev_async_send>
3670calls in the current loop iteration. Checking for async and signal events
3671involves iterating over all running async watchers or all signal numbers.
3672
3673=back
3648 3674
3649 3675
3650=head1 AUTHOR 3676=head1 AUTHOR
3651 3677
3652Marc Lehmann <libev@schmorp.de>. 3678Marc Lehmann <libev@schmorp.de>.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines