… | |
… | |
47 | |
47 | |
48 | return 0; |
48 | return 0; |
49 | } |
49 | } |
50 | |
50 | |
51 | =head1 DESCRIPTION |
51 | =head1 DESCRIPTION |
|
|
52 | |
|
|
53 | The newest version of this document is also available as a html-formatted |
|
|
54 | web page you might find easier to navigate when reading it for the first |
|
|
55 | time: L<http://cvs.schmorp.de/libev/ev.html>. |
52 | |
56 | |
53 | Libev is an event loop: you register interest in certain events (such as a |
57 | Libev is an event loop: you register interest in certain events (such as a |
54 | file descriptor being readable or a timeout occuring), and it will manage |
58 | file descriptor being readable or a timeout occuring), and it will manage |
55 | these event sources and provide your program with events. |
59 | these event sources and provide your program with events. |
56 | |
60 | |
… | |
… | |
2123 | will have the C<struct ev_loop *> as first argument, and you can create |
2127 | will have the C<struct ev_loop *> as first argument, and you can create |
2124 | additional independent event loops. Otherwise there will be no support |
2128 | additional independent event loops. Otherwise there will be no support |
2125 | for multiple event loops and there is no first event loop pointer |
2129 | for multiple event loops and there is no first event loop pointer |
2126 | argument. Instead, all functions act on the single default loop. |
2130 | argument. Instead, all functions act on the single default loop. |
2127 | |
2131 | |
|
|
2132 | =item EV_MINPRI |
|
|
2133 | |
|
|
2134 | =item EV_MAXPRI |
|
|
2135 | |
|
|
2136 | The range of allowed priorities. C<EV_MINPRI> must be smaller or equal to |
|
|
2137 | C<EV_MAXPRI>, but otherwise there are no non-obvious limitations. You can |
|
|
2138 | provide for more priorities by overriding those symbols (usually defined |
|
|
2139 | to be C<-2> and C<2>, respectively). |
|
|
2140 | |
|
|
2141 | When doing priority-based operations, libev usually has to linearly search |
|
|
2142 | all the priorities, so having many of them (hundreds) uses a lot of space |
|
|
2143 | and time, so using the defaults of five priorities (-2 .. +2) is usually |
|
|
2144 | fine. |
|
|
2145 | |
|
|
2146 | If your embedding app does not need any priorities, defining these both to |
|
|
2147 | C<0> will save some memory and cpu. |
|
|
2148 | |
2128 | =item EV_PERIODIC_ENABLE |
2149 | =item EV_PERIODIC_ENABLE |
2129 | |
2150 | |
2130 | If undefined or defined to be C<1>, then periodic timers are supported. If |
2151 | If undefined or defined to be C<1>, then periodic timers are supported. If |
2131 | defined to be C<0>, then they are not. Disabling them saves a few kB of |
2152 | defined to be C<0>, then they are not. Disabling them saves a few kB of |
2132 | code. |
2153 | code. |
… | |
… | |
2238 | |
2259 | |
2239 | =over 4 |
2260 | =over 4 |
2240 | |
2261 | |
2241 | =item Starting and stopping timer/periodic watchers: O(log skipped_other_timers) |
2262 | =item Starting and stopping timer/periodic watchers: O(log skipped_other_timers) |
2242 | |
2263 | |
|
|
2264 | This means that, when you have a watcher that triggers in one hour and |
|
|
2265 | there are 100 watchers that would trigger before that then inserting will |
|
|
2266 | have to skip those 100 watchers. |
|
|
2267 | |
2243 | =item Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers) |
2268 | =item Changing timer/periodic watchers (by autorepeat, again): O(log skipped_other_timers) |
2244 | |
2269 | |
|
|
2270 | That means that for changing a timer costs less than removing/adding them |
|
|
2271 | as only the relative motion in the event queue has to be paid for. |
|
|
2272 | |
2245 | =item Starting io/check/prepare/idle/signal/child watchers: O(1) |
2273 | =item Starting io/check/prepare/idle/signal/child watchers: O(1) |
2246 | |
2274 | |
|
|
2275 | These just add the watcher into an array or at the head of a list. If |
|
|
2276 | the array needs to be extended libev needs to realloc and move the whole |
|
|
2277 | array, but this happen asymptotically less and less with more watchers, |
|
|
2278 | thus amortised O(1). |
|
|
2279 | |
2247 | =item Stopping check/prepare/idle watchers: O(1) |
2280 | =item Stopping check/prepare/idle watchers: O(1) |
2248 | |
2281 | |
2249 | =item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE)) |
2282 | =item Stopping an io/signal/child watcher: O(number_of_watchers_for_this_(fd/signal/pid % EV_PID_HASHSIZE)) |
2250 | |
2283 | |
|
|
2284 | These watchers are stored in lists then need to be walked to find the |
|
|
2285 | correct watcher to remove. The lists are usually short (you don't usually |
|
|
2286 | have many watchers waiting for the same fd or signal). |
|
|
2287 | |
2251 | =item Finding the next timer per loop iteration: O(1) |
2288 | =item Finding the next timer per loop iteration: O(1) |
2252 | |
2289 | |
2253 | =item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd) |
2290 | =item Each change on a file descriptor per loop iteration: O(number_of_watchers_for_this_fd) |
2254 | |
2291 | |
|
|
2292 | A change means an I/O watcher gets started or stopped, which requires |
|
|
2293 | libev to recalculate its status (and possibly tell the kernel). |
|
|
2294 | |
2255 | =item Activating one watcher: O(1) |
2295 | =item Activating one watcher: O(1) |
2256 | |
2296 | |
|
|
2297 | =item Priority handling: O(number_of_priorities) |
|
|
2298 | |
|
|
2299 | Priorities are implemented by allocating some space for each |
|
|
2300 | priority. When doing priority-based operations, libev usually has to |
|
|
2301 | linearly search all the priorities. |
|
|
2302 | |
2257 | =back |
2303 | =back |
2258 | |
2304 | |
2259 | |
2305 | |
2260 | =head1 AUTHOR |
2306 | =head1 AUTHOR |
2261 | |
2307 | |