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