… | |
… | |
130 | .\} |
130 | .\} |
131 | .rm #[ #] #H #V #F C |
131 | .rm #[ #] #H #V #F C |
132 | .\" ======================================================================== |
132 | .\" ======================================================================== |
133 | .\" |
133 | .\" |
134 | .IX Title "EV 1" |
134 | .IX Title "EV 1" |
135 | .TH EV 1 "2008-03-13" "perl v5.10.0" "User Contributed Perl Documentation" |
135 | .TH EV 1 "2008-04-11" "perl v5.10.0" "User Contributed Perl Documentation" |
136 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
136 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
137 | .\" way too many mistakes in technical documents. |
137 | .\" way too many mistakes in technical documents. |
138 | .if n .ad l |
138 | .if n .ad l |
139 | .nh |
139 | .nh |
140 | .SH "NAME" |
140 | .SH "NAME" |
… | |
… | |
328 | .Sp |
328 | .Sp |
329 | See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. |
329 | See the description of \f(CW\*(C`ev_embed\*(C'\fR watchers for more info. |
330 | .IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4 |
330 | .IP "ev_set_allocator (void *(*cb)(void *ptr, long size))" 4 |
331 | .IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))" |
331 | .IX Item "ev_set_allocator (void *(*cb)(void *ptr, long size))" |
332 | Sets the allocation function to use (the prototype is similar \- the |
332 | Sets the allocation function to use (the prototype is similar \- the |
333 | semantics is identical \- to the realloc C function). It is used to |
333 | semantics are identical to the \f(CW\*(C`realloc\*(C'\fR C89/SuS/POSIX function). It is |
334 | allocate and free memory (no surprises here). If it returns zero when |
334 | used to allocate and free memory (no surprises here). If it returns zero |
335 | memory needs to be allocated, the library might abort or take some |
335 | when memory needs to be allocated (\f(CW\*(C`size != 0\*(C'\fR), the library might abort |
336 | potentially destructive action. The default is your system realloc |
336 | or take some potentially destructive action. |
337 | function. |
337 | .Sp |
|
|
338 | Since some systems (at least OpenBSD and Darwin) fail to implement |
|
|
339 | correct \f(CW\*(C`realloc\*(C'\fR semantics, libev will use a wrapper around the system |
|
|
340 | \&\f(CW\*(C`realloc\*(C'\fR and \f(CW\*(C`free\*(C'\fR functions by default. |
338 | .Sp |
341 | .Sp |
339 | You could override this function in high-availability programs to, say, |
342 | You could override this function in high-availability programs to, say, |
340 | free some memory if it cannot allocate memory, to use a special allocator, |
343 | free some memory if it cannot allocate memory, to use a special allocator, |
341 | or even to sleep a while and retry until some memory is available. |
344 | or even to sleep a while and retry until some memory is available. |
342 | .Sp |
345 | .Sp |
343 | Example: Replace the libev allocator with one that waits a bit and then |
346 | Example: Replace the libev allocator with one that waits a bit and then |
344 | retries). |
347 | retries (example requires a standards-compliant \f(CW\*(C`realloc\*(C'\fR). |
345 | .Sp |
348 | .Sp |
346 | .Vb 6 |
349 | .Vb 6 |
347 | \& static void * |
350 | \& static void * |
348 | \& persistent_realloc (void *ptr, size_t size) |
351 | \& persistent_realloc (void *ptr, size_t size) |
349 | \& { |
352 | \& { |
… | |
… | |
387 | .SH "FUNCTIONS CONTROLLING THE EVENT LOOP" |
390 | .SH "FUNCTIONS CONTROLLING THE EVENT LOOP" |
388 | .IX Header "FUNCTIONS CONTROLLING THE EVENT LOOP" |
391 | .IX Header "FUNCTIONS CONTROLLING THE EVENT LOOP" |
389 | An event loop is described by a \f(CW\*(C`struct ev_loop *\*(C'\fR. The library knows two |
392 | An event loop is described by a \f(CW\*(C`struct ev_loop *\*(C'\fR. The library knows two |
390 | types of such loops, the \fIdefault\fR loop, which supports signals and child |
393 | types of such loops, the \fIdefault\fR loop, which supports signals and child |
391 | events, and dynamically created loops which do not. |
394 | events, and dynamically created loops which do not. |
392 | .PP |
|
|
393 | If you use threads, a common model is to run the default event loop |
|
|
394 | in your main thread (or in a separate thread) and for each thread you |
|
|
395 | create, you also create another event loop. Libev itself does no locking |
|
|
396 | whatsoever, so if you mix calls to the same event loop in different |
|
|
397 | threads, make sure you lock (this is usually a bad idea, though, even if |
|
|
398 | done correctly, because it's hideous and inefficient). |
|
|
399 | .IP "struct ev_loop *ev_default_loop (unsigned int flags)" 4 |
395 | .IP "struct ev_loop *ev_default_loop (unsigned int flags)" 4 |
400 | .IX Item "struct ev_loop *ev_default_loop (unsigned int flags)" |
396 | .IX Item "struct ev_loop *ev_default_loop (unsigned int flags)" |
401 | This will initialise the default event loop if it hasn't been initialised |
397 | This will initialise the default event loop if it hasn't been initialised |
402 | yet and return it. If the default loop could not be initialised, returns |
398 | yet and return it. If the default loop could not be initialised, returns |
403 | false. If it already was initialised it simply returns it (and ignores the |
399 | false. If it already was initialised it simply returns it (and ignores the |
404 | flags. If that is troubling you, check \f(CW\*(C`ev_backend ()\*(C'\fR afterwards). |
400 | flags. If that is troubling you, check \f(CW\*(C`ev_backend ()\*(C'\fR afterwards). |
405 | .Sp |
401 | .Sp |
406 | If you don't know what event loop to use, use the one returned from this |
402 | If you don't know what event loop to use, use the one returned from this |
407 | function. |
403 | function. |
|
|
404 | .Sp |
|
|
405 | Note that this function is \fInot\fR thread-safe, so if you want to use it |
|
|
406 | from multiple threads, you have to lock (note also that this is unlikely, |
|
|
407 | as loops cannot bes hared easily between threads anyway). |
408 | .Sp |
408 | .Sp |
409 | The default loop is the only loop that can handle \f(CW\*(C`ev_signal\*(C'\fR and |
409 | The default loop is the only loop that can handle \f(CW\*(C`ev_signal\*(C'\fR and |
410 | \&\f(CW\*(C`ev_child\*(C'\fR watchers, and to do this, it always registers a handler |
410 | \&\f(CW\*(C`ev_child\*(C'\fR watchers, and to do this, it always registers a handler |
411 | for \f(CW\*(C`SIGCHLD\*(C'\fR. If this is a problem for your app you can either |
411 | for \f(CW\*(C`SIGCHLD\*(C'\fR. If this is a problem for your app you can either |
412 | create a dynamic loop with \f(CW\*(C`ev_loop_new\*(C'\fR that doesn't do that, or you |
412 | create a dynamic loop with \f(CW\*(C`ev_loop_new\*(C'\fR that doesn't do that, or you |
… | |
… | |
482 | For few fds, this backend is a bit little slower than poll and select, |
482 | For few fds, this backend is a bit little slower than poll and select, |
483 | but it scales phenomenally better. While poll and select usually scale |
483 | but it scales phenomenally better. While poll and select usually scale |
484 | like O(total_fds) where n is the total number of fds (or the highest fd), |
484 | like O(total_fds) where n is the total number of fds (or the highest fd), |
485 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
485 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
486 | of shortcomings, such as silently dropping events in some hard-to-detect |
486 | of shortcomings, such as silently dropping events in some hard-to-detect |
487 | cases and rewiring a syscall per fd change, no fork support and bad |
487 | cases and requiring a syscall per fd change, no fork support and bad |
488 | support for dup. |
488 | support for dup. |
489 | .Sp |
489 | .Sp |
490 | While stopping, setting and starting an I/O watcher in the same iteration |
490 | While stopping, setting and starting an I/O watcher in the same iteration |
491 | will result in some caching, there is still a syscall per such incident |
491 | will result in some caching, there is still a syscall per such incident |
492 | (because the fd could point to a different file description now), so its |
492 | (because the fd could point to a different file description now), so its |
… | |
… | |
599 | .IX Item "struct ev_loop *ev_loop_new (unsigned int flags)" |
599 | .IX Item "struct ev_loop *ev_loop_new (unsigned int flags)" |
600 | Similar to \f(CW\*(C`ev_default_loop\*(C'\fR, but always creates a new event loop that is |
600 | Similar to \f(CW\*(C`ev_default_loop\*(C'\fR, but always creates a new event loop that is |
601 | always distinct from the default loop. Unlike the default loop, it cannot |
601 | always distinct from the default loop. Unlike the default loop, it cannot |
602 | handle signal and child watchers, and attempts to do so will be greeted by |
602 | handle signal and child watchers, and attempts to do so will be greeted by |
603 | undefined behaviour (or a failed assertion if assertions are enabled). |
603 | undefined behaviour (or a failed assertion if assertions are enabled). |
|
|
604 | .Sp |
|
|
605 | Note that this function \fIis\fR thread-safe, and the recommended way to use |
|
|
606 | libev with threads is indeed to create one loop per thread, and using the |
|
|
607 | default loop in the \*(L"main\*(R" or \*(L"initial\*(R" thread. |
604 | .Sp |
608 | .Sp |
605 | Example: Try to create a event loop that uses epoll and nothing else. |
609 | Example: Try to create a event loop that uses epoll and nothing else. |
606 | .Sp |
610 | .Sp |
607 | .Vb 3 |
611 | .Vb 3 |
608 | \& struct ev_loop *epoller = ev_loop_new (EVBACKEND_EPOLL | EVFLAG_NOENV); |
612 | \& struct ev_loop *epoller = ev_loop_new (EVBACKEND_EPOLL | EVFLAG_NOENV); |
… | |
… | |
1219 | To support fork in your programs, you either have to call |
1223 | To support fork in your programs, you either have to call |
1220 | \&\f(CW\*(C`ev_default_fork ()\*(C'\fR or \f(CW\*(C`ev_loop_fork ()\*(C'\fR after a fork in the child, |
1224 | \&\f(CW\*(C`ev_default_fork ()\*(C'\fR or \f(CW\*(C`ev_loop_fork ()\*(C'\fR after a fork in the child, |
1221 | enable \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR, or resort to \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or |
1225 | enable \f(CW\*(C`EVFLAG_FORKCHECK\*(C'\fR, or resort to \f(CW\*(C`EVBACKEND_SELECT\*(C'\fR or |
1222 | \&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
1226 | \&\f(CW\*(C`EVBACKEND_POLL\*(C'\fR. |
1223 | .PP |
1227 | .PP |
|
|
1228 | \fIThe special problem of \s-1SIGPIPE\s0\fR |
|
|
1229 | .IX Subsection "The special problem of SIGPIPE" |
|
|
1230 | .PP |
|
|
1231 | While not really specific to libev, it is easy to forget about \s-1SIGPIPE:\s0 |
|
|
1232 | when reading from a pipe whose other end has been closed, your program |
|
|
1233 | gets send a \s-1SIGPIPE\s0, which, by default, aborts your program. For most |
|
|
1234 | programs this is sensible behaviour, for daemons, this is usually |
|
|
1235 | undesirable. |
|
|
1236 | .PP |
|
|
1237 | So when you encounter spurious, unexplained daemon exits, make sure you |
|
|
1238 | ignore \s-1SIGPIPE\s0 (and maybe make sure you log the exit status of your daemon |
|
|
1239 | somewhere, as that would have given you a big clue). |
|
|
1240 | .PP |
1224 | \fIWatcher-Specific Functions\fR |
1241 | \fIWatcher-Specific Functions\fR |
1225 | .IX Subsection "Watcher-Specific Functions" |
1242 | .IX Subsection "Watcher-Specific Functions" |
1226 | .IP "ev_io_init (ev_io *, callback, int fd, int events)" 4 |
1243 | .IP "ev_io_init (ev_io *, callback, int fd, int events)" 4 |
1227 | .IX Item "ev_io_init (ev_io *, callback, int fd, int events)" |
1244 | .IX Item "ev_io_init (ev_io *, callback, int fd, int events)" |
1228 | .PD 0 |
1245 | .PD 0 |
… | |
… | |
1736 | semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers, which means that libev sometimes needs |
1753 | semantics of \f(CW\*(C`ev_stat\*(C'\fR watchers, which means that libev sometimes needs |
1737 | to fall back to regular polling again even with inotify, but changes are |
1754 | to fall back to regular polling again even with inotify, but changes are |
1738 | usually detected immediately, and if the file exists there will be no |
1755 | usually detected immediately, and if the file exists there will be no |
1739 | polling. |
1756 | polling. |
1740 | .PP |
1757 | .PP |
|
|
1758 | \fI\s-1ABI\s0 Issues (Largefile Support)\fR |
|
|
1759 | .IX Subsection "ABI Issues (Largefile Support)" |
|
|
1760 | .PP |
|
|
1761 | Libev by default (unless the user overrides this) uses the default |
|
|
1762 | compilation environment, which means that on systems with optionally |
|
|
1763 | disabled large file support, you get the 32 bit version of the stat |
|
|
1764 | structure. When using the library from programs that change the \s-1ABI\s0 to |
|
|
1765 | use 64 bit file offsets the programs will fail. In that case you have to |
|
|
1766 | compile libev with the same flags to get binary compatibility. This is |
|
|
1767 | obviously the case with any flags that change the \s-1ABI\s0, but the problem is |
|
|
1768 | most noticably with ev_stat and largefile support. |
|
|
1769 | .PP |
1741 | \fIInotify\fR |
1770 | \fIInotify\fR |
1742 | .IX Subsection "Inotify" |
1771 | .IX Subsection "Inotify" |
1743 | .PP |
1772 | .PP |
1744 | When \f(CW\*(C`inotify (7)\*(C'\fR support has been compiled into libev (generally only |
1773 | When \f(CW\*(C`inotify (7)\*(C'\fR support has been compiled into libev (generally only |
1745 | available on Linux) and present at runtime, it will be used to speed up |
1774 | available on Linux) and present at runtime, it will be used to speed up |
… | |
… | |
2383 | section below on what exactly this means). |
2412 | section below on what exactly this means). |
2384 | .Sp |
2413 | .Sp |
2385 | This call incurs the overhead of a syscall only once per loop iteration, |
2414 | This call incurs the overhead of a syscall only once per loop iteration, |
2386 | so while the overhead might be noticable, it doesn't apply to repeated |
2415 | so while the overhead might be noticable, it doesn't apply to repeated |
2387 | calls to \f(CW\*(C`ev_async_send\*(C'\fR. |
2416 | calls to \f(CW\*(C`ev_async_send\*(C'\fR. |
|
|
2417 | .IP "bool = ev_async_pending (ev_async *)" 4 |
|
|
2418 | .IX Item "bool = ev_async_pending (ev_async *)" |
|
|
2419 | Returns a non-zero value when \f(CW\*(C`ev_async_send\*(C'\fR has been called on the |
|
|
2420 | watcher but the event has not yet been processed (or even noted) by the |
|
|
2421 | event loop. |
|
|
2422 | .Sp |
|
|
2423 | \&\f(CW\*(C`ev_async_send\*(C'\fR sets a flag in the watcher and wakes up the loop. When |
|
|
2424 | the loop iterates next and checks for the watcher to have become active, |
|
|
2425 | it will reset the flag again. \f(CW\*(C`ev_async_pending\*(C'\fR can be used to very |
|
|
2426 | quickly check wether invoking the loop might be a good idea. |
|
|
2427 | .Sp |
|
|
2428 | Not that this does \fInot\fR check wether the watcher itself is pending, only |
|
|
2429 | wether it has been requested to make this watcher pending. |
2388 | .SH "OTHER FUNCTIONS" |
2430 | .SH "OTHER FUNCTIONS" |
2389 | .IX Header "OTHER FUNCTIONS" |
2431 | .IX Header "OTHER FUNCTIONS" |
2390 | There are some other functions of possible interest. Described. Here. Now. |
2432 | There are some other functions of possible interest. Described. Here. Now. |
2391 | .IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 |
2433 | .IP "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" 4 |
2392 | .IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" |
2434 | .IX Item "ev_once (loop, int fd, int events, ev_tstamp timeout, callback)" |
… | |
… | |
2449 | it a private \s-1API\s0). |
2491 | it a private \s-1API\s0). |
2450 | .IP "\(bu" 4 |
2492 | .IP "\(bu" 4 |
2451 | Priorities are not currently supported. Initialising priorities |
2493 | Priorities are not currently supported. Initialising priorities |
2452 | will fail and all watchers will have the same priority, even though there |
2494 | will fail and all watchers will have the same priority, even though there |
2453 | is an ev_pri field. |
2495 | is an ev_pri field. |
|
|
2496 | .IP "\(bu" 4 |
|
|
2497 | In libevent, the last base created gets the signals, in libev, the |
|
|
2498 | first base created (== the default loop) gets the signals. |
2454 | .IP "\(bu" 4 |
2499 | .IP "\(bu" 4 |
2455 | Other members are not supported. |
2500 | Other members are not supported. |
2456 | .IP "\(bu" 4 |
2501 | .IP "\(bu" 4 |
2457 | The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need |
2502 | The libev emulation is \fInot\fR \s-1ABI\s0 compatible to libevent, you need |
2458 | to use the libev header file and library. |
2503 | to use the libev header file and library. |
… | |
… | |
2687 | .ie n .IP """EV_DEFAULT""\fR, \f(CW""EV_DEFAULT_""" 4 |
2732 | .ie n .IP """EV_DEFAULT""\fR, \f(CW""EV_DEFAULT_""" 4 |
2688 | .el .IP "\f(CWEV_DEFAULT\fR, \f(CWEV_DEFAULT_\fR" 4 |
2733 | .el .IP "\f(CWEV_DEFAULT\fR, \f(CWEV_DEFAULT_\fR" 4 |
2689 | .IX Item "EV_DEFAULT, EV_DEFAULT_" |
2734 | .IX Item "EV_DEFAULT, EV_DEFAULT_" |
2690 | Similar to the other two macros, this gives you the value of the default |
2735 | Similar to the other two macros, this gives you the value of the default |
2691 | loop, if multiple loops are supported (\*(L"ev loop default\*(R"). |
2736 | loop, if multiple loops are supported (\*(L"ev loop default\*(R"). |
|
|
2737 | .ie n .IP """EV_DEFAULT_UC""\fR, \f(CW""EV_DEFAULT_UC_""" 4 |
|
|
2738 | .el .IP "\f(CWEV_DEFAULT_UC\fR, \f(CWEV_DEFAULT_UC_\fR" 4 |
|
|
2739 | .IX Item "EV_DEFAULT_UC, EV_DEFAULT_UC_" |
|
|
2740 | Usage identical to \f(CW\*(C`EV_DEFAULT\*(C'\fR and \f(CW\*(C`EV_DEFAULT_\*(C'\fR, but requires that the |
|
|
2741 | default loop has been initialised (\f(CW\*(C`UC\*(C'\fR == unchecked). Their behaviour |
|
|
2742 | is undefined when the default loop has not been initialised by a previous |
|
|
2743 | execution of \f(CW\*(C`EV_DEFAULT\*(C'\fR, \f(CW\*(C`EV_DEFAULT_\*(C'\fR or \f(CW\*(C`ev_default_init (...)\*(C'\fR. |
|
|
2744 | .Sp |
|
|
2745 | It is often prudent to use \f(CW\*(C`EV_DEFAULT\*(C'\fR when initialising the first |
|
|
2746 | watcher in a function but use \f(CW\*(C`EV_DEFAULT_UC\*(C'\fR afterwards. |
2692 | .PP |
2747 | .PP |
2693 | Example: Declare and initialise a check watcher, utilising the above |
2748 | Example: Declare and initialise a check watcher, utilising the above |
2694 | macros so it will work regardless of whether multiple loops are supported |
2749 | macros so it will work regardless of whether multiple loops are supported |
2695 | or not. |
2750 | or not. |
2696 | .PP |
2751 | .PP |
… | |
… | |
2806 | .Vb 1 |
2861 | .Vb 1 |
2807 | \& libev.m4 |
2862 | \& libev.m4 |
2808 | .Ve |
2863 | .Ve |
2809 | .Sh "\s-1PREPROCESSOR\s0 \s-1SYMBOLS/MACROS\s0" |
2864 | .Sh "\s-1PREPROCESSOR\s0 \s-1SYMBOLS/MACROS\s0" |
2810 | .IX Subsection "PREPROCESSOR SYMBOLS/MACROS" |
2865 | .IX Subsection "PREPROCESSOR SYMBOLS/MACROS" |
2811 | Libev can be configured via a variety of preprocessor symbols you have to define |
2866 | Libev can be configured via a variety of preprocessor symbols you have to |
2812 | before including any of its files. The default is not to build for multiplicity |
2867 | define before including any of its files. The default in the absense of |
2813 | and only include the select backend. |
2868 | autoconf is noted for every option. |
2814 | .IP "\s-1EV_STANDALONE\s0" 4 |
2869 | .IP "\s-1EV_STANDALONE\s0" 4 |
2815 | .IX Item "EV_STANDALONE" |
2870 | .IX Item "EV_STANDALONE" |
2816 | Must always be \f(CW1\fR if you do not use autoconf configuration, which |
2871 | Must always be \f(CW1\fR if you do not use autoconf configuration, which |
2817 | keeps libev from including \fIconfig.h\fR, and it also defines dummy |
2872 | keeps libev from including \fIconfig.h\fR, and it also defines dummy |
2818 | implementations for some libevent functions (such as logging, which is not |
2873 | implementations for some libevent functions (such as logging, which is not |
… | |
… | |
2837 | note about libraries in the description of \f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, though. |
2892 | note about libraries in the description of \f(CW\*(C`EV_USE_MONOTONIC\*(C'\fR, though. |
2838 | .IP "\s-1EV_USE_NANOSLEEP\s0" 4 |
2893 | .IP "\s-1EV_USE_NANOSLEEP\s0" 4 |
2839 | .IX Item "EV_USE_NANOSLEEP" |
2894 | .IX Item "EV_USE_NANOSLEEP" |
2840 | If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available |
2895 | If defined to be \f(CW1\fR, libev will assume that \f(CW\*(C`nanosleep ()\*(C'\fR is available |
2841 | and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. |
2896 | and will use it for delays. Otherwise it will use \f(CW\*(C`select ()\*(C'\fR. |
|
|
2897 | .IP "\s-1EV_USE_EVENTFD\s0" 4 |
|
|
2898 | .IX Item "EV_USE_EVENTFD" |
|
|
2899 | If defined to be \f(CW1\fR, then libev will assume that \f(CW\*(C`eventfd ()\*(C'\fR is |
|
|
2900 | available and will probe for kernel support at runtime. This will improve |
|
|
2901 | \&\f(CW\*(C`ev_signal\*(C'\fR and \f(CW\*(C`ev_async\*(C'\fR performance and reduce resource consumption. |
|
|
2902 | If undefined, it will be enabled if the headers indicate GNU/Linux + Glibc |
|
|
2903 | 2.7 or newer, otherwise disabled. |
2842 | .IP "\s-1EV_USE_SELECT\s0" 4 |
2904 | .IP "\s-1EV_USE_SELECT\s0" 4 |
2843 | .IX Item "EV_USE_SELECT" |
2905 | .IX Item "EV_USE_SELECT" |
2844 | If undefined or defined to be \f(CW1\fR, libev will compile in support for the |
2906 | If undefined or defined to be \f(CW1\fR, libev will compile in support for the |
2845 | \&\f(CW\*(C`select\*(C'\fR(2) backend. No attempt at autodetection will be done: if no |
2907 | \&\f(CW\*(C`select\*(C'\fR(2) backend. No attempt at autodetection will be done: if no |
2846 | other method takes over, select will be it. Otherwise the select backend |
2908 | other method takes over, select will be it. Otherwise the select backend |
… | |
… | |
2877 | takes precedence over select. |
2939 | takes precedence over select. |
2878 | .IP "\s-1EV_USE_EPOLL\s0" 4 |
2940 | .IP "\s-1EV_USE_EPOLL\s0" 4 |
2879 | .IX Item "EV_USE_EPOLL" |
2941 | .IX Item "EV_USE_EPOLL" |
2880 | If defined to be \f(CW1\fR, libev will compile in support for the Linux |
2942 | If defined to be \f(CW1\fR, libev will compile in support for the Linux |
2881 | \&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime, |
2943 | \&\f(CW\*(C`epoll\*(C'\fR(7) backend. Its availability will be detected at runtime, |
2882 | otherwise another method will be used as fallback. This is the |
2944 | otherwise another method will be used as fallback. This is the preferred |
2883 | preferred backend for GNU/Linux systems. |
2945 | backend for GNU/Linux systems. If undefined, it will be enabled if the |
|
|
2946 | headers indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. |
2884 | .IP "\s-1EV_USE_KQUEUE\s0" 4 |
2947 | .IP "\s-1EV_USE_KQUEUE\s0" 4 |
2885 | .IX Item "EV_USE_KQUEUE" |
2948 | .IX Item "EV_USE_KQUEUE" |
2886 | If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style |
2949 | If defined to be \f(CW1\fR, libev will compile in support for the \s-1BSD\s0 style |
2887 | \&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime, |
2950 | \&\f(CW\*(C`kqueue\*(C'\fR(2) backend. Its actual availability will be detected at runtime, |
2888 | otherwise another method will be used as fallback. This is the preferred |
2951 | otherwise another method will be used as fallback. This is the preferred |
… | |
… | |
2903 | reserved for future expansion, works like the \s-1USE\s0 symbols above. |
2966 | reserved for future expansion, works like the \s-1USE\s0 symbols above. |
2904 | .IP "\s-1EV_USE_INOTIFY\s0" 4 |
2967 | .IP "\s-1EV_USE_INOTIFY\s0" 4 |
2905 | .IX Item "EV_USE_INOTIFY" |
2968 | .IX Item "EV_USE_INOTIFY" |
2906 | If defined to be \f(CW1\fR, libev will compile in support for the Linux inotify |
2969 | If defined to be \f(CW1\fR, libev will compile in support for the Linux inotify |
2907 | interface to speed up \f(CW\*(C`ev_stat\*(C'\fR watchers. Its actual availability will |
2970 | interface to speed up \f(CW\*(C`ev_stat\*(C'\fR watchers. Its actual availability will |
2908 | be detected at runtime. |
2971 | be detected at runtime. If undefined, it will be enabled if the headers |
|
|
2972 | indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. |
2909 | .IP "\s-1EV_ATOMIC_T\s0" 4 |
2973 | .IP "\s-1EV_ATOMIC_T\s0" 4 |
2910 | .IX Item "EV_ATOMIC_T" |
2974 | .IX Item "EV_ATOMIC_T" |
2911 | Libev requires an integer type (suitable for storing \f(CW0\fR or \f(CW1\fR) whose |
2975 | Libev requires an integer type (suitable for storing \f(CW0\fR or \f(CW1\fR) whose |
2912 | access is atomic with respect to other threads or signal contexts. No such |
2976 | access is atomic with respect to other threads or signal contexts. No such |
2913 | type is easily found in the C language, so you can provide your own type |
2977 | type is easily found in the C language, so you can provide your own type |
… | |
… | |
3094 | .PP |
3158 | .PP |
3095 | .Vb 2 |
3159 | .Vb 2 |
3096 | \& #include "ev_cpp.h" |
3160 | \& #include "ev_cpp.h" |
3097 | \& #include "ev.c" |
3161 | \& #include "ev.c" |
3098 | .Ve |
3162 | .Ve |
|
|
3163 | .SH "THREADS AND COROUTINES" |
|
|
3164 | .IX Header "THREADS AND COROUTINES" |
|
|
3165 | .Sh "\s-1THREADS\s0" |
|
|
3166 | .IX Subsection "THREADS" |
|
|
3167 | Libev itself is completely threadsafe, but it uses no locking. This |
|
|
3168 | means that you can use as many loops as you want in parallel, as long as |
|
|
3169 | only one thread ever calls into one libev function with the same loop |
|
|
3170 | parameter. |
|
|
3171 | .PP |
|
|
3172 | Or put differently: calls with different loop parameters can be done in |
|
|
3173 | parallel from multiple threads, calls with the same loop parameter must be |
|
|
3174 | done serially (but can be done from different threads, as long as only one |
|
|
3175 | thread ever is inside a call at any point in time, e.g. by using a mutex |
|
|
3176 | per loop). |
|
|
3177 | .PP |
|
|
3178 | If you want to know which design is best for your problem, then I cannot |
|
|
3179 | help you but by giving some generic advice: |
|
|
3180 | .IP "\(bu" 4 |
|
|
3181 | most applications have a main thread: use the default libev loop |
|
|
3182 | in that thread, or create a seperate thread running only the default loop. |
|
|
3183 | .Sp |
|
|
3184 | This helps integrating other libraries or software modules that use libev |
|
|
3185 | themselves and don't care/know about threading. |
|
|
3186 | .IP "\(bu" 4 |
|
|
3187 | one loop per thread is usually a good model. |
|
|
3188 | .Sp |
|
|
3189 | Doing this is almost never wrong, sometimes a better-performance model |
|
|
3190 | exists, but it is always a good start. |
|
|
3191 | .IP "\(bu" 4 |
|
|
3192 | other models exist, such as the leader/follower pattern, where one |
|
|
3193 | loop is handed through multiple threads in a kind of round-robbin fashion. |
|
|
3194 | .Sp |
|
|
3195 | Chosing a model is hard \- look around, learn, know that usually you cna do |
|
|
3196 | better than you currently do :\-) |
|
|
3197 | .IP "\(bu" 4 |
|
|
3198 | often you need to talk to some other thread which blocks in the |
|
|
3199 | event loop \- \f(CW\*(C`ev_async\*(C'\fR watchers can be used to wake them up from other |
|
|
3200 | threads safely (or from signal contexts...). |
|
|
3201 | .Sh "\s-1COROUTINES\s0" |
|
|
3202 | .IX Subsection "COROUTINES" |
|
|
3203 | Libev is much more accomodating to coroutines (\*(L"cooperative threads\*(R"): |
|
|
3204 | libev fully supports nesting calls to it's functions from different |
|
|
3205 | coroutines (e.g. you can call \f(CW\*(C`ev_loop\*(C'\fR on the same loop from two |
|
|
3206 | different coroutines and switch freely between both coroutines running the |
|
|
3207 | loop, as long as you don't confuse yourself). The only exception is that |
|
|
3208 | you must not do this from \f(CW\*(C`ev_periodic\*(C'\fR reschedule callbacks. |
|
|
3209 | .PP |
|
|
3210 | Care has been invested into making sure that libev does not keep local |
|
|
3211 | state inside \f(CW\*(C`ev_loop\*(C'\fR, and other calls do not usually allow coroutine |
|
|
3212 | switches. |
3099 | .SH "COMPLEXITIES" |
3213 | .SH "COMPLEXITIES" |
3100 | .IX Header "COMPLEXITIES" |
3214 | .IX Header "COMPLEXITIES" |
3101 | In this section the complexities of (many of) the algorithms used inside |
3215 | In this section the complexities of (many of) the algorithms used inside |
3102 | libev will be explained. For complexity discussions about backends see the |
3216 | libev will be explained. For complexity discussions about backends see the |
3103 | documentation for \f(CW\*(C`ev_default_init\*(C'\fR. |
3217 | documentation for \f(CW\*(C`ev_default_init\*(C'\fR. |
… | |
… | |
3223 | .IX Header "AUTHOR" |
3337 | .IX Header "AUTHOR" |
3224 | Marc Lehmann <libev@schmorp.de>. |
3338 | Marc Lehmann <libev@schmorp.de>. |
3225 | .SH "POD ERRORS" |
3339 | .SH "POD ERRORS" |
3226 | .IX Header "POD ERRORS" |
3340 | .IX Header "POD ERRORS" |
3227 | Hey! \fBThe above document had some coding errors, which are explained below:\fR |
3341 | Hey! \fBThe above document had some coding errors, which are explained below:\fR |
3228 | .IP "Around line 2951:" 4 |
3342 | .IP "Around line 3015:" 4 |
3229 | .IX Item "Around line 2951:" |
3343 | .IX Item "Around line 3015:" |
3230 | You forgot a '=back' before '=head2' |
3344 | You forgot a '=back' before '=head2' |