1 | /* |
1 | /* |
2 | * libev event processing core, watcher management |
2 | * libev event processing core, watcher management |
3 | * |
3 | * |
4 | * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * modification, are permitted provided that the following conditions are |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * met: |
9 | * |
|
|
10 | * 1. Redistributions of source code must retain the above copyright notice, |
|
|
11 | * this list of conditions and the following disclaimer. |
|
|
12 | * |
|
|
13 | * 2. Redistributions in binary form must reproduce the above copyright |
|
|
14 | * notice, this list of conditions and the following disclaimer in the |
|
|
15 | * documentation and/or other materials provided with the distribution. |
|
|
16 | * |
|
|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
|
18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- |
|
|
19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
|
20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- |
|
|
21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
|
22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
|
23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
|
24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
|
|
25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
|
|
26 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
10 | * |
27 | * |
11 | * * Redistributions of source code must retain the above copyright |
28 | * Alternatively, the contents of this file may be used under the terms of |
12 | * notice, this list of conditions and the following disclaimer. |
29 | * the GNU General Public License ("GPL") version 2 or any later version, |
13 | * |
30 | * in which case the provisions of the GPL are applicable instead of |
14 | * * Redistributions in binary form must reproduce the above |
31 | * the above. If you wish to allow the use of your version of this file |
15 | * copyright notice, this list of conditions and the following |
32 | * only under the terms of the GPL and not to allow others to use your |
16 | * disclaimer in the documentation and/or other materials provided |
33 | * version of this file under the BSD license, indicate your decision |
17 | * with the distribution. |
34 | * by deleting the provisions above and replace them with the notice |
18 | * |
35 | * and other provisions required by the GPL. If you do not delete the |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
36 | * provisions above, a recipient may use your version of this file under |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
37 | * either the BSD or the GPL. |
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
|
23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
|
24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
|
25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
|
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
|
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
|
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
|
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
30 | */ |
38 | */ |
31 | |
39 | |
32 | #ifdef __cplusplus |
40 | #ifdef __cplusplus |
33 | extern "C" { |
41 | extern "C" { |
34 | #endif |
42 | #endif |
35 | |
43 | |
|
|
44 | /* this big block deduces configuration from config.h */ |
36 | #ifndef EV_STANDALONE |
45 | #ifndef EV_STANDALONE |
37 | # ifdef EV_CONFIG_H |
46 | # ifdef EV_CONFIG_H |
38 | # include EV_CONFIG_H |
47 | # include EV_CONFIG_H |
39 | # else |
48 | # else |
40 | # include "config.h" |
49 | # include "config.h" |
… | |
… | |
51 | # ifndef EV_USE_MONOTONIC |
60 | # ifndef EV_USE_MONOTONIC |
52 | # define EV_USE_MONOTONIC 0 |
61 | # define EV_USE_MONOTONIC 0 |
53 | # endif |
62 | # endif |
54 | # ifndef EV_USE_REALTIME |
63 | # ifndef EV_USE_REALTIME |
55 | # define EV_USE_REALTIME 0 |
64 | # define EV_USE_REALTIME 0 |
|
|
65 | # endif |
|
|
66 | # endif |
|
|
67 | |
|
|
68 | # ifndef EV_USE_NANOSLEEP |
|
|
69 | # if HAVE_NANOSLEEP |
|
|
70 | # define EV_USE_NANOSLEEP 1 |
|
|
71 | # else |
|
|
72 | # define EV_USE_NANOSLEEP 0 |
56 | # endif |
73 | # endif |
57 | # endif |
74 | # endif |
58 | |
75 | |
59 | # ifndef EV_USE_SELECT |
76 | # ifndef EV_USE_SELECT |
60 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
77 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
… | |
… | |
102 | # else |
119 | # else |
103 | # define EV_USE_INOTIFY 0 |
120 | # define EV_USE_INOTIFY 0 |
104 | # endif |
121 | # endif |
105 | # endif |
122 | # endif |
106 | |
123 | |
|
|
124 | # ifndef EV_USE_EVENTFD |
|
|
125 | # if HAVE_EVENTFD |
|
|
126 | # define EV_USE_EVENTFD 1 |
|
|
127 | # else |
|
|
128 | # define EV_USE_EVENTFD 0 |
|
|
129 | # endif |
|
|
130 | # endif |
|
|
131 | |
107 | #endif |
132 | #endif |
108 | |
133 | |
109 | #include <math.h> |
134 | #include <math.h> |
110 | #include <stdlib.h> |
135 | #include <stdlib.h> |
111 | #include <fcntl.h> |
136 | #include <fcntl.h> |
… | |
… | |
136 | # ifndef EV_SELECT_IS_WINSOCKET |
161 | # ifndef EV_SELECT_IS_WINSOCKET |
137 | # define EV_SELECT_IS_WINSOCKET 1 |
162 | # define EV_SELECT_IS_WINSOCKET 1 |
138 | # endif |
163 | # endif |
139 | #endif |
164 | #endif |
140 | |
165 | |
141 | /**/ |
166 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
142 | |
167 | |
143 | #ifndef EV_USE_MONOTONIC |
168 | #ifndef EV_USE_MONOTONIC |
144 | # define EV_USE_MONOTONIC 0 |
169 | # define EV_USE_MONOTONIC 0 |
145 | #endif |
170 | #endif |
146 | |
171 | |
147 | #ifndef EV_USE_REALTIME |
172 | #ifndef EV_USE_REALTIME |
148 | # define EV_USE_REALTIME 0 |
173 | # define EV_USE_REALTIME 0 |
|
|
174 | #endif |
|
|
175 | |
|
|
176 | #ifndef EV_USE_NANOSLEEP |
|
|
177 | # define EV_USE_NANOSLEEP 0 |
149 | #endif |
178 | #endif |
150 | |
179 | |
151 | #ifndef EV_USE_SELECT |
180 | #ifndef EV_USE_SELECT |
152 | # define EV_USE_SELECT 1 |
181 | # define EV_USE_SELECT 1 |
153 | #endif |
182 | #endif |
… | |
… | |
159 | # define EV_USE_POLL 1 |
188 | # define EV_USE_POLL 1 |
160 | # endif |
189 | # endif |
161 | #endif |
190 | #endif |
162 | |
191 | |
163 | #ifndef EV_USE_EPOLL |
192 | #ifndef EV_USE_EPOLL |
|
|
193 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
|
|
194 | # define EV_USE_EPOLL 1 |
|
|
195 | # else |
164 | # define EV_USE_EPOLL 0 |
196 | # define EV_USE_EPOLL 0 |
|
|
197 | # endif |
165 | #endif |
198 | #endif |
166 | |
199 | |
167 | #ifndef EV_USE_KQUEUE |
200 | #ifndef EV_USE_KQUEUE |
168 | # define EV_USE_KQUEUE 0 |
201 | # define EV_USE_KQUEUE 0 |
169 | #endif |
202 | #endif |
… | |
… | |
171 | #ifndef EV_USE_PORT |
204 | #ifndef EV_USE_PORT |
172 | # define EV_USE_PORT 0 |
205 | # define EV_USE_PORT 0 |
173 | #endif |
206 | #endif |
174 | |
207 | |
175 | #ifndef EV_USE_INOTIFY |
208 | #ifndef EV_USE_INOTIFY |
|
|
209 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
|
|
210 | # define EV_USE_INOTIFY 1 |
|
|
211 | # else |
176 | # define EV_USE_INOTIFY 0 |
212 | # define EV_USE_INOTIFY 0 |
|
|
213 | # endif |
177 | #endif |
214 | #endif |
178 | |
215 | |
179 | #ifndef EV_PID_HASHSIZE |
216 | #ifndef EV_PID_HASHSIZE |
180 | # if EV_MINIMAL |
217 | # if EV_MINIMAL |
181 | # define EV_PID_HASHSIZE 1 |
218 | # define EV_PID_HASHSIZE 1 |
… | |
… | |
190 | # else |
227 | # else |
191 | # define EV_INOTIFY_HASHSIZE 16 |
228 | # define EV_INOTIFY_HASHSIZE 16 |
192 | # endif |
229 | # endif |
193 | #endif |
230 | #endif |
194 | |
231 | |
195 | /**/ |
232 | #ifndef EV_USE_EVENTFD |
|
|
233 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
|
|
234 | # define EV_USE_EVENTFD 1 |
|
|
235 | # else |
|
|
236 | # define EV_USE_EVENTFD 0 |
|
|
237 | # endif |
|
|
238 | #endif |
|
|
239 | |
|
|
240 | /* this block fixes any misconfiguration where we know we run into trouble otherwise */ |
196 | |
241 | |
197 | #ifndef CLOCK_MONOTONIC |
242 | #ifndef CLOCK_MONOTONIC |
198 | # undef EV_USE_MONOTONIC |
243 | # undef EV_USE_MONOTONIC |
199 | # define EV_USE_MONOTONIC 0 |
244 | # define EV_USE_MONOTONIC 0 |
200 | #endif |
245 | #endif |
… | |
… | |
207 | #if !EV_STAT_ENABLE |
252 | #if !EV_STAT_ENABLE |
208 | # undef EV_USE_INOTIFY |
253 | # undef EV_USE_INOTIFY |
209 | # define EV_USE_INOTIFY 0 |
254 | # define EV_USE_INOTIFY 0 |
210 | #endif |
255 | #endif |
211 | |
256 | |
|
|
257 | #if !EV_USE_NANOSLEEP |
|
|
258 | # ifndef _WIN32 |
|
|
259 | # include <sys/select.h> |
|
|
260 | # endif |
|
|
261 | #endif |
|
|
262 | |
212 | #if EV_USE_INOTIFY |
263 | #if EV_USE_INOTIFY |
213 | # include <sys/inotify.h> |
264 | # include <sys/inotify.h> |
214 | #endif |
265 | #endif |
215 | |
266 | |
216 | #if EV_SELECT_IS_WINSOCKET |
267 | #if EV_SELECT_IS_WINSOCKET |
217 | # include <winsock.h> |
268 | # include <winsock.h> |
|
|
269 | #endif |
|
|
270 | |
|
|
271 | #if EV_USE_EVENTFD |
|
|
272 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
|
|
273 | # include <stdint.h> |
|
|
274 | # ifdef __cplusplus |
|
|
275 | extern "C" { |
|
|
276 | # endif |
|
|
277 | int eventfd (unsigned int initval, int flags); |
|
|
278 | # ifdef __cplusplus |
|
|
279 | } |
|
|
280 | # endif |
218 | #endif |
281 | #endif |
219 | |
282 | |
220 | /**/ |
283 | /**/ |
221 | |
284 | |
222 | /* |
285 | /* |
… | |
… | |
237 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
300 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
238 | # define noinline __attribute__ ((noinline)) |
301 | # define noinline __attribute__ ((noinline)) |
239 | #else |
302 | #else |
240 | # define expect(expr,value) (expr) |
303 | # define expect(expr,value) (expr) |
241 | # define noinline |
304 | # define noinline |
242 | # if __STDC_VERSION__ < 199901L |
305 | # if __STDC_VERSION__ < 199901L && __GNUC__ < 2 |
243 | # define inline |
306 | # define inline |
244 | # endif |
307 | # endif |
245 | #endif |
308 | #endif |
246 | |
309 | |
247 | #define expect_false(expr) expect ((expr) != 0, 0) |
310 | #define expect_false(expr) expect ((expr) != 0, 0) |
… | |
… | |
262 | |
325 | |
263 | typedef ev_watcher *W; |
326 | typedef ev_watcher *W; |
264 | typedef ev_watcher_list *WL; |
327 | typedef ev_watcher_list *WL; |
265 | typedef ev_watcher_time *WT; |
328 | typedef ev_watcher_time *WT; |
266 | |
329 | |
|
|
330 | #define ev_active(w) ((W)(w))->active |
|
|
331 | #define ev_at(w) ((WT)(w))->at |
|
|
332 | |
|
|
333 | #if EV_USE_MONOTONIC |
|
|
334 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
|
|
335 | /* giving it a reasonably high chance of working on typical architetcures */ |
267 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
336 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
|
|
337 | #endif |
268 | |
338 | |
269 | #ifdef _WIN32 |
339 | #ifdef _WIN32 |
270 | # include "ev_win32.c" |
340 | # include "ev_win32.c" |
271 | #endif |
341 | #endif |
272 | |
342 | |
… | |
… | |
293 | perror (msg); |
363 | perror (msg); |
294 | abort (); |
364 | abort (); |
295 | } |
365 | } |
296 | } |
366 | } |
297 | |
367 | |
|
|
368 | static void * |
|
|
369 | ev_realloc_emul (void *ptr, long size) |
|
|
370 | { |
|
|
371 | /* some systems, notably openbsd and darwin, fail to properly |
|
|
372 | * implement realloc (x, 0) (as required by both ansi c-98 and |
|
|
373 | * the single unix specification, so work around them here. |
|
|
374 | */ |
|
|
375 | |
|
|
376 | if (size) |
|
|
377 | return realloc (ptr, size); |
|
|
378 | |
|
|
379 | free (ptr); |
|
|
380 | return 0; |
|
|
381 | } |
|
|
382 | |
298 | static void *(*alloc)(void *ptr, long size); |
383 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
299 | |
384 | |
300 | void |
385 | void |
301 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
386 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
302 | { |
387 | { |
303 | alloc = cb; |
388 | alloc = cb; |
304 | } |
389 | } |
305 | |
390 | |
306 | inline_speed void * |
391 | inline_speed void * |
307 | ev_realloc (void *ptr, long size) |
392 | ev_realloc (void *ptr, long size) |
308 | { |
393 | { |
309 | ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); |
394 | ptr = alloc (ptr, size); |
310 | |
395 | |
311 | if (!ptr && size) |
396 | if (!ptr && size) |
312 | { |
397 | { |
313 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
398 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
314 | abort (); |
399 | abort (); |
… | |
… | |
337 | W w; |
422 | W w; |
338 | int events; |
423 | int events; |
339 | } ANPENDING; |
424 | } ANPENDING; |
340 | |
425 | |
341 | #if EV_USE_INOTIFY |
426 | #if EV_USE_INOTIFY |
|
|
427 | /* hash table entry per inotify-id */ |
342 | typedef struct |
428 | typedef struct |
343 | { |
429 | { |
344 | WL head; |
430 | WL head; |
345 | } ANFS; |
431 | } ANFS; |
|
|
432 | #endif |
|
|
433 | |
|
|
434 | /* Heap Entry */ |
|
|
435 | #if EV_HEAP_CACHE_AT |
|
|
436 | typedef struct { |
|
|
437 | WT w; |
|
|
438 | ev_tstamp at; |
|
|
439 | } ANHE; |
|
|
440 | |
|
|
441 | #define ANHE_w(he) (he) /* access watcher, read-write */ |
|
|
442 | #define ANHE_at(he) (he)->at /* acces cahced at, read-only */ |
|
|
443 | #define ANHE_at_set(he) (he)->at = (he)->w->at /* update at from watcher */ |
|
|
444 | #else |
|
|
445 | typedef WT ANHE; |
|
|
446 | |
|
|
447 | #define ANHE_w(he) (he) |
|
|
448 | #define ANHE_at(he) (he)->at |
|
|
449 | #define ANHE_at_set(he) |
346 | #endif |
450 | #endif |
347 | |
451 | |
348 | #if EV_MULTIPLICITY |
452 | #if EV_MULTIPLICITY |
349 | |
453 | |
350 | struct ev_loop |
454 | struct ev_loop |
… | |
… | |
408 | { |
512 | { |
409 | return ev_rt_now; |
513 | return ev_rt_now; |
410 | } |
514 | } |
411 | #endif |
515 | #endif |
412 | |
516 | |
|
|
517 | void |
|
|
518 | ev_sleep (ev_tstamp delay) |
|
|
519 | { |
|
|
520 | if (delay > 0.) |
|
|
521 | { |
|
|
522 | #if EV_USE_NANOSLEEP |
|
|
523 | struct timespec ts; |
|
|
524 | |
|
|
525 | ts.tv_sec = (time_t)delay; |
|
|
526 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
|
|
527 | |
|
|
528 | nanosleep (&ts, 0); |
|
|
529 | #elif defined(_WIN32) |
|
|
530 | Sleep ((unsigned long)(delay * 1e3)); |
|
|
531 | #else |
|
|
532 | struct timeval tv; |
|
|
533 | |
|
|
534 | tv.tv_sec = (time_t)delay; |
|
|
535 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
|
|
536 | |
|
|
537 | select (0, 0, 0, 0, &tv); |
|
|
538 | #endif |
|
|
539 | } |
|
|
540 | } |
|
|
541 | |
|
|
542 | /*****************************************************************************/ |
|
|
543 | |
|
|
544 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
|
|
545 | |
413 | int inline_size |
546 | int inline_size |
414 | array_nextsize (int elem, int cur, int cnt) |
547 | array_nextsize (int elem, int cur, int cnt) |
415 | { |
548 | { |
416 | int ncur = cur + 1; |
549 | int ncur = cur + 1; |
417 | |
550 | |
418 | do |
551 | do |
419 | ncur <<= 1; |
552 | ncur <<= 1; |
420 | while (cnt > ncur); |
553 | while (cnt > ncur); |
421 | |
554 | |
422 | /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */ |
555 | /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */ |
423 | if (elem * ncur > 4096) |
556 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
424 | { |
557 | { |
425 | ncur *= elem; |
558 | ncur *= elem; |
426 | ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095; |
559 | ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); |
427 | ncur = ncur - sizeof (void *) * 4; |
560 | ncur = ncur - sizeof (void *) * 4; |
428 | ncur /= elem; |
561 | ncur /= elem; |
429 | } |
562 | } |
430 | |
563 | |
431 | return ncur; |
564 | return ncur; |
… | |
… | |
543 | |
676 | |
544 | #if EV_SELECT_IS_WINSOCKET |
677 | #if EV_SELECT_IS_WINSOCKET |
545 | if (events) |
678 | if (events) |
546 | { |
679 | { |
547 | unsigned long argp; |
680 | unsigned long argp; |
|
|
681 | #ifdef EV_FD_TO_WIN32_HANDLE |
|
|
682 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
|
|
683 | #else |
548 | anfd->handle = _get_osfhandle (fd); |
684 | anfd->handle = _get_osfhandle (fd); |
|
|
685 | #endif |
549 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
686 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
550 | } |
687 | } |
551 | #endif |
688 | #endif |
552 | |
689 | |
553 | { |
690 | { |
… | |
… | |
641 | } |
778 | } |
642 | } |
779 | } |
643 | |
780 | |
644 | /*****************************************************************************/ |
781 | /*****************************************************************************/ |
645 | |
782 | |
|
|
783 | /* |
|
|
784 | * the heap functions want a real array index. array index 0 uis guaranteed to not |
|
|
785 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
|
|
786 | * the branching factor of the d-tree. |
|
|
787 | */ |
|
|
788 | |
|
|
789 | /* |
|
|
790 | * at the moment we allow libev the luxury of two heaps, |
|
|
791 | * a small-code-size 2-heap one and a ~1.5kb larger 4-heap |
|
|
792 | * which is more cache-efficient. |
|
|
793 | * the difference is about 5% with 50000+ watchers. |
|
|
794 | */ |
|
|
795 | #define EV_USE_4HEAP !EV_MINIMAL |
|
|
796 | #if EV_USE_4HEAP |
|
|
797 | |
|
|
798 | #define DHEAP 4 |
|
|
799 | #define HEAP0 (DHEAP - 1) /* index of first element in heap */ |
|
|
800 | |
|
|
801 | /* towards the root */ |
646 | void inline_speed |
802 | void inline_speed |
647 | upheap (WT *heap, int k) |
803 | upheap (ANHE *heap, int k) |
648 | { |
804 | { |
649 | WT w = heap [k]; |
805 | ANHE he = heap [k]; |
650 | |
806 | |
651 | while (k) |
807 | for (;;) |
652 | { |
808 | { |
653 | int p = (k - 1) >> 1; |
809 | int p = ((k - HEAP0 - 1) / DHEAP) + HEAP0; |
654 | |
810 | |
655 | if (heap [p]->at <= w->at) |
811 | if (p == k || ANHE_at (heap [p]) <= ANHE_at (he)) |
656 | break; |
812 | break; |
657 | |
813 | |
658 | heap [k] = heap [p]; |
814 | heap [k] = heap [p]; |
659 | ((W)heap [k])->active = k + 1; |
815 | ev_active (ANHE_w (heap [k])) = k; |
660 | k = p; |
816 | k = p; |
661 | } |
817 | } |
662 | |
818 | |
|
|
819 | ev_active (ANHE_w (he)) = k; |
|
|
820 | heap [k] = he; |
|
|
821 | } |
|
|
822 | |
|
|
823 | /* away from the root */ |
|
|
824 | void inline_speed |
|
|
825 | downheap (ANHE *heap, int N, int k) |
|
|
826 | { |
|
|
827 | ANHE he = heap [k]; |
|
|
828 | ANHE *E = heap + N + HEAP0; |
|
|
829 | |
|
|
830 | for (;;) |
|
|
831 | { |
|
|
832 | ev_tstamp minat; |
|
|
833 | ANHE *minpos; |
|
|
834 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0; |
|
|
835 | |
|
|
836 | // find minimum child |
|
|
837 | if (expect_true (pos + DHEAP - 1 < E)) |
|
|
838 | { |
|
|
839 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
|
|
840 | if (ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
|
|
841 | if (ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
|
|
842 | if (ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
|
|
843 | } |
|
|
844 | else if (pos < E) |
|
|
845 | { |
|
|
846 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
|
|
847 | if (pos + 1 < E && ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
|
|
848 | if (pos + 2 < E && ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
|
|
849 | if (pos + 3 < E && ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
|
|
850 | } |
|
|
851 | else |
|
|
852 | break; |
|
|
853 | |
|
|
854 | if (ANHE_at (he) <= minat) |
|
|
855 | break; |
|
|
856 | |
|
|
857 | ev_active (ANHE_w (*minpos)) = k; |
|
|
858 | heap [k] = *minpos; |
|
|
859 | |
|
|
860 | k = minpos - heap; |
|
|
861 | } |
|
|
862 | |
|
|
863 | ev_active (ANHE_w (he)) = k; |
|
|
864 | heap [k] = he; |
|
|
865 | } |
|
|
866 | |
|
|
867 | #else // 4HEAP |
|
|
868 | |
|
|
869 | #define HEAP0 1 |
|
|
870 | |
|
|
871 | /* towards the root */ |
|
|
872 | void inline_speed |
|
|
873 | upheap (ANHE *heap, int k) |
|
|
874 | { |
|
|
875 | ANHE he = heap [k]; |
|
|
876 | |
|
|
877 | for (;;) |
|
|
878 | { |
|
|
879 | int p = k >> 1; |
|
|
880 | |
|
|
881 | /* maybe we could use a dummy element at heap [0]? */ |
|
|
882 | if (!p || ANHE_at (heap [p]) <= ANHE_at (he)) |
|
|
883 | break; |
|
|
884 | |
|
|
885 | heap [k] = heap [p]; |
|
|
886 | ev_active (ANHE_w (heap [k])) = k; |
|
|
887 | k = p; |
|
|
888 | } |
|
|
889 | |
663 | heap [k] = w; |
890 | heap [k] = w; |
664 | ((W)heap [k])->active = k + 1; |
891 | ev_active (ANHE_w (heap [k])) = k; |
665 | } |
892 | } |
666 | |
893 | |
|
|
894 | /* away from the root */ |
667 | void inline_speed |
895 | void inline_speed |
668 | downheap (WT *heap, int N, int k) |
896 | downheap (ANHE *heap, int N, int k) |
669 | { |
897 | { |
670 | WT w = heap [k]; |
898 | ANHE he = heap [k]; |
671 | |
899 | |
672 | for (;;) |
900 | for (;;) |
673 | { |
901 | { |
674 | int c = (k << 1) + 1; |
902 | int c = k << 1; |
675 | |
903 | |
676 | if (c >= N) |
904 | if (c > N) |
677 | break; |
905 | break; |
678 | |
906 | |
679 | c += c + 1 < N && heap [c]->at > heap [c + 1]->at |
907 | c += c + 1 < N && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
680 | ? 1 : 0; |
908 | ? 1 : 0; |
681 | |
909 | |
682 | if (w->at <= heap [c]->at) |
910 | if (w->at <= ANHE_at (heap [c])) |
683 | break; |
911 | break; |
684 | |
912 | |
685 | heap [k] = heap [c]; |
913 | heap [k] = heap [c]; |
686 | ((W)heap [k])->active = k + 1; |
914 | ev_active (ANHE_w (heap [k])) = k; |
687 | |
915 | |
688 | k = c; |
916 | k = c; |
689 | } |
917 | } |
690 | |
918 | |
691 | heap [k] = w; |
919 | heap [k] = he; |
692 | ((W)heap [k])->active = k + 1; |
920 | ev_active (ANHE_w (he)) = k; |
693 | } |
921 | } |
|
|
922 | #endif |
694 | |
923 | |
695 | void inline_size |
924 | void inline_size |
696 | adjustheap (WT *heap, int N, int k) |
925 | adjustheap (ANHE *heap, int N, int k) |
697 | { |
926 | { |
698 | upheap (heap, k); |
927 | upheap (heap, k); |
699 | downheap (heap, N, k); |
928 | downheap (heap, N, k); |
700 | } |
929 | } |
701 | |
930 | |
702 | /*****************************************************************************/ |
931 | /*****************************************************************************/ |
703 | |
932 | |
704 | typedef struct |
933 | typedef struct |
705 | { |
934 | { |
706 | WL head; |
935 | WL head; |
707 | sig_atomic_t volatile gotsig; |
936 | EV_ATOMIC_T gotsig; |
708 | } ANSIG; |
937 | } ANSIG; |
709 | |
938 | |
710 | static ANSIG *signals; |
939 | static ANSIG *signals; |
711 | static int signalmax; |
940 | static int signalmax; |
712 | |
941 | |
713 | static int sigpipe [2]; |
942 | static EV_ATOMIC_T gotsig; |
714 | static sig_atomic_t volatile gotsig; |
|
|
715 | static ev_io sigev; |
|
|
716 | |
943 | |
717 | void inline_size |
944 | void inline_size |
718 | signals_init (ANSIG *base, int count) |
945 | signals_init (ANSIG *base, int count) |
719 | { |
946 | { |
720 | while (count--) |
947 | while (count--) |
… | |
… | |
724 | |
951 | |
725 | ++base; |
952 | ++base; |
726 | } |
953 | } |
727 | } |
954 | } |
728 | |
955 | |
729 | static void |
956 | /*****************************************************************************/ |
730 | sighandler (int signum) |
|
|
731 | { |
|
|
732 | #if _WIN32 |
|
|
733 | signal (signum, sighandler); |
|
|
734 | #endif |
|
|
735 | |
|
|
736 | signals [signum - 1].gotsig = 1; |
|
|
737 | |
|
|
738 | if (!gotsig) |
|
|
739 | { |
|
|
740 | int old_errno = errno; |
|
|
741 | gotsig = 1; |
|
|
742 | write (sigpipe [1], &signum, 1); |
|
|
743 | errno = old_errno; |
|
|
744 | } |
|
|
745 | } |
|
|
746 | |
|
|
747 | void noinline |
|
|
748 | ev_feed_signal_event (EV_P_ int signum) |
|
|
749 | { |
|
|
750 | WL w; |
|
|
751 | |
|
|
752 | #if EV_MULTIPLICITY |
|
|
753 | assert (("feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr)); |
|
|
754 | #endif |
|
|
755 | |
|
|
756 | --signum; |
|
|
757 | |
|
|
758 | if (signum < 0 || signum >= signalmax) |
|
|
759 | return; |
|
|
760 | |
|
|
761 | signals [signum].gotsig = 0; |
|
|
762 | |
|
|
763 | for (w = signals [signum].head; w; w = w->next) |
|
|
764 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
|
|
765 | } |
|
|
766 | |
|
|
767 | static void |
|
|
768 | sigcb (EV_P_ ev_io *iow, int revents) |
|
|
769 | { |
|
|
770 | int signum; |
|
|
771 | |
|
|
772 | read (sigpipe [0], &revents, 1); |
|
|
773 | gotsig = 0; |
|
|
774 | |
|
|
775 | for (signum = signalmax; signum--; ) |
|
|
776 | if (signals [signum].gotsig) |
|
|
777 | ev_feed_signal_event (EV_A_ signum + 1); |
|
|
778 | } |
|
|
779 | |
957 | |
780 | void inline_speed |
958 | void inline_speed |
781 | fd_intern (int fd) |
959 | fd_intern (int fd) |
782 | { |
960 | { |
783 | #ifdef _WIN32 |
961 | #ifdef _WIN32 |
… | |
… | |
788 | fcntl (fd, F_SETFL, O_NONBLOCK); |
966 | fcntl (fd, F_SETFL, O_NONBLOCK); |
789 | #endif |
967 | #endif |
790 | } |
968 | } |
791 | |
969 | |
792 | static void noinline |
970 | static void noinline |
793 | siginit (EV_P) |
971 | evpipe_init (EV_P) |
794 | { |
972 | { |
|
|
973 | if (!ev_is_active (&pipeev)) |
|
|
974 | { |
|
|
975 | #if EV_USE_EVENTFD |
|
|
976 | if ((evfd = eventfd (0, 0)) >= 0) |
|
|
977 | { |
|
|
978 | evpipe [0] = -1; |
|
|
979 | fd_intern (evfd); |
|
|
980 | ev_io_set (&pipeev, evfd, EV_READ); |
|
|
981 | } |
|
|
982 | else |
|
|
983 | #endif |
|
|
984 | { |
|
|
985 | while (pipe (evpipe)) |
|
|
986 | syserr ("(libev) error creating signal/async pipe"); |
|
|
987 | |
795 | fd_intern (sigpipe [0]); |
988 | fd_intern (evpipe [0]); |
796 | fd_intern (sigpipe [1]); |
989 | fd_intern (evpipe [1]); |
|
|
990 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
|
|
991 | } |
797 | |
992 | |
798 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
|
|
799 | ev_io_start (EV_A_ &sigev); |
993 | ev_io_start (EV_A_ &pipeev); |
800 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
994 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
|
|
995 | } |
|
|
996 | } |
|
|
997 | |
|
|
998 | void inline_size |
|
|
999 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
|
|
1000 | { |
|
|
1001 | if (!*flag) |
|
|
1002 | { |
|
|
1003 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1004 | |
|
|
1005 | *flag = 1; |
|
|
1006 | |
|
|
1007 | #if EV_USE_EVENTFD |
|
|
1008 | if (evfd >= 0) |
|
|
1009 | { |
|
|
1010 | uint64_t counter = 1; |
|
|
1011 | write (evfd, &counter, sizeof (uint64_t)); |
|
|
1012 | } |
|
|
1013 | else |
|
|
1014 | #endif |
|
|
1015 | write (evpipe [1], &old_errno, 1); |
|
|
1016 | |
|
|
1017 | errno = old_errno; |
|
|
1018 | } |
|
|
1019 | } |
|
|
1020 | |
|
|
1021 | static void |
|
|
1022 | pipecb (EV_P_ ev_io *iow, int revents) |
|
|
1023 | { |
|
|
1024 | #if EV_USE_EVENTFD |
|
|
1025 | if (evfd >= 0) |
|
|
1026 | { |
|
|
1027 | uint64_t counter; |
|
|
1028 | read (evfd, &counter, sizeof (uint64_t)); |
|
|
1029 | } |
|
|
1030 | else |
|
|
1031 | #endif |
|
|
1032 | { |
|
|
1033 | char dummy; |
|
|
1034 | read (evpipe [0], &dummy, 1); |
|
|
1035 | } |
|
|
1036 | |
|
|
1037 | if (gotsig && ev_is_default_loop (EV_A)) |
|
|
1038 | { |
|
|
1039 | int signum; |
|
|
1040 | gotsig = 0; |
|
|
1041 | |
|
|
1042 | for (signum = signalmax; signum--; ) |
|
|
1043 | if (signals [signum].gotsig) |
|
|
1044 | ev_feed_signal_event (EV_A_ signum + 1); |
|
|
1045 | } |
|
|
1046 | |
|
|
1047 | #if EV_ASYNC_ENABLE |
|
|
1048 | if (gotasync) |
|
|
1049 | { |
|
|
1050 | int i; |
|
|
1051 | gotasync = 0; |
|
|
1052 | |
|
|
1053 | for (i = asynccnt; i--; ) |
|
|
1054 | if (asyncs [i]->sent) |
|
|
1055 | { |
|
|
1056 | asyncs [i]->sent = 0; |
|
|
1057 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
|
|
1058 | } |
|
|
1059 | } |
|
|
1060 | #endif |
801 | } |
1061 | } |
802 | |
1062 | |
803 | /*****************************************************************************/ |
1063 | /*****************************************************************************/ |
804 | |
1064 | |
|
|
1065 | static void |
|
|
1066 | ev_sighandler (int signum) |
|
|
1067 | { |
|
|
1068 | #if EV_MULTIPLICITY |
|
|
1069 | struct ev_loop *loop = &default_loop_struct; |
|
|
1070 | #endif |
|
|
1071 | |
|
|
1072 | #if _WIN32 |
|
|
1073 | signal (signum, ev_sighandler); |
|
|
1074 | #endif |
|
|
1075 | |
|
|
1076 | signals [signum - 1].gotsig = 1; |
|
|
1077 | evpipe_write (EV_A_ &gotsig); |
|
|
1078 | } |
|
|
1079 | |
|
|
1080 | void noinline |
|
|
1081 | ev_feed_signal_event (EV_P_ int signum) |
|
|
1082 | { |
|
|
1083 | WL w; |
|
|
1084 | |
|
|
1085 | #if EV_MULTIPLICITY |
|
|
1086 | assert (("feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr)); |
|
|
1087 | #endif |
|
|
1088 | |
|
|
1089 | --signum; |
|
|
1090 | |
|
|
1091 | if (signum < 0 || signum >= signalmax) |
|
|
1092 | return; |
|
|
1093 | |
|
|
1094 | signals [signum].gotsig = 0; |
|
|
1095 | |
|
|
1096 | for (w = signals [signum].head; w; w = w->next) |
|
|
1097 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
|
|
1098 | } |
|
|
1099 | |
|
|
1100 | /*****************************************************************************/ |
|
|
1101 | |
805 | static WL childs [EV_PID_HASHSIZE]; |
1102 | static WL childs [EV_PID_HASHSIZE]; |
806 | |
1103 | |
807 | #ifndef _WIN32 |
1104 | #ifndef _WIN32 |
808 | |
1105 | |
809 | static ev_signal childev; |
1106 | static ev_signal childev; |
810 | |
1107 | |
|
|
1108 | #ifndef WIFCONTINUED |
|
|
1109 | # define WIFCONTINUED(status) 0 |
|
|
1110 | #endif |
|
|
1111 | |
811 | void inline_speed |
1112 | void inline_speed |
812 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
1113 | child_reap (EV_P_ int chain, int pid, int status) |
813 | { |
1114 | { |
814 | ev_child *w; |
1115 | ev_child *w; |
|
|
1116 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
815 | |
1117 | |
816 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1118 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
|
|
1119 | { |
817 | if (w->pid == pid || !w->pid) |
1120 | if ((w->pid == pid || !w->pid) |
|
|
1121 | && (!traced || (w->flags & 1))) |
818 | { |
1122 | { |
819 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
1123 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
820 | w->rpid = pid; |
1124 | w->rpid = pid; |
821 | w->rstatus = status; |
1125 | w->rstatus = status; |
822 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
1126 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
823 | } |
1127 | } |
|
|
1128 | } |
824 | } |
1129 | } |
825 | |
1130 | |
826 | #ifndef WCONTINUED |
1131 | #ifndef WCONTINUED |
827 | # define WCONTINUED 0 |
1132 | # define WCONTINUED 0 |
828 | #endif |
1133 | #endif |
… | |
… | |
837 | if (!WCONTINUED |
1142 | if (!WCONTINUED |
838 | || errno != EINVAL |
1143 | || errno != EINVAL |
839 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
1144 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
840 | return; |
1145 | return; |
841 | |
1146 | |
842 | /* make sure we are called again until all childs have been reaped */ |
1147 | /* make sure we are called again until all children have been reaped */ |
843 | /* we need to do it this way so that the callback gets called before we continue */ |
1148 | /* we need to do it this way so that the callback gets called before we continue */ |
844 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1149 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
845 | |
1150 | |
846 | child_reap (EV_A_ sw, pid, pid, status); |
1151 | child_reap (EV_A_ pid, pid, status); |
847 | if (EV_PID_HASHSIZE > 1) |
1152 | if (EV_PID_HASHSIZE > 1) |
848 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1153 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
849 | } |
1154 | } |
850 | |
1155 | |
851 | #endif |
1156 | #endif |
852 | |
1157 | |
853 | /*****************************************************************************/ |
1158 | /*****************************************************************************/ |
… | |
… | |
925 | } |
1230 | } |
926 | |
1231 | |
927 | unsigned int |
1232 | unsigned int |
928 | ev_embeddable_backends (void) |
1233 | ev_embeddable_backends (void) |
929 | { |
1234 | { |
|
|
1235 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
|
|
1236 | |
930 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
1237 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
931 | return EVBACKEND_KQUEUE |
1238 | /* please fix it and tell me how to detect the fix */ |
932 | | EVBACKEND_PORT; |
1239 | flags &= ~EVBACKEND_EPOLL; |
|
|
1240 | |
|
|
1241 | return flags; |
933 | } |
1242 | } |
934 | |
1243 | |
935 | unsigned int |
1244 | unsigned int |
936 | ev_backend (EV_P) |
1245 | ev_backend (EV_P) |
937 | { |
1246 | { |
… | |
… | |
940 | |
1249 | |
941 | unsigned int |
1250 | unsigned int |
942 | ev_loop_count (EV_P) |
1251 | ev_loop_count (EV_P) |
943 | { |
1252 | { |
944 | return loop_count; |
1253 | return loop_count; |
|
|
1254 | } |
|
|
1255 | |
|
|
1256 | void |
|
|
1257 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
|
|
1258 | { |
|
|
1259 | io_blocktime = interval; |
|
|
1260 | } |
|
|
1261 | |
|
|
1262 | void |
|
|
1263 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
|
|
1264 | { |
|
|
1265 | timeout_blocktime = interval; |
945 | } |
1266 | } |
946 | |
1267 | |
947 | static void noinline |
1268 | static void noinline |
948 | loop_init (EV_P_ unsigned int flags) |
1269 | loop_init (EV_P_ unsigned int flags) |
949 | { |
1270 | { |
… | |
… | |
955 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1276 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
956 | have_monotonic = 1; |
1277 | have_monotonic = 1; |
957 | } |
1278 | } |
958 | #endif |
1279 | #endif |
959 | |
1280 | |
960 | ev_rt_now = ev_time (); |
1281 | ev_rt_now = ev_time (); |
961 | mn_now = get_clock (); |
1282 | mn_now = get_clock (); |
962 | now_floor = mn_now; |
1283 | now_floor = mn_now; |
963 | rtmn_diff = ev_rt_now - mn_now; |
1284 | rtmn_diff = ev_rt_now - mn_now; |
|
|
1285 | |
|
|
1286 | io_blocktime = 0.; |
|
|
1287 | timeout_blocktime = 0.; |
|
|
1288 | backend = 0; |
|
|
1289 | backend_fd = -1; |
|
|
1290 | gotasync = 0; |
|
|
1291 | #if EV_USE_INOTIFY |
|
|
1292 | fs_fd = -2; |
|
|
1293 | #endif |
964 | |
1294 | |
965 | /* pid check not overridable via env */ |
1295 | /* pid check not overridable via env */ |
966 | #ifndef _WIN32 |
1296 | #ifndef _WIN32 |
967 | if (flags & EVFLAG_FORKCHECK) |
1297 | if (flags & EVFLAG_FORKCHECK) |
968 | curpid = getpid (); |
1298 | curpid = getpid (); |
… | |
… | |
971 | if (!(flags & EVFLAG_NOENV) |
1301 | if (!(flags & EVFLAG_NOENV) |
972 | && !enable_secure () |
1302 | && !enable_secure () |
973 | && getenv ("LIBEV_FLAGS")) |
1303 | && getenv ("LIBEV_FLAGS")) |
974 | flags = atoi (getenv ("LIBEV_FLAGS")); |
1304 | flags = atoi (getenv ("LIBEV_FLAGS")); |
975 | |
1305 | |
976 | if (!(flags & 0x0000ffffUL)) |
1306 | if (!(flags & 0x0000ffffU)) |
977 | flags |= ev_recommended_backends (); |
1307 | flags |= ev_recommended_backends (); |
978 | |
|
|
979 | backend = 0; |
|
|
980 | backend_fd = -1; |
|
|
981 | #if EV_USE_INOTIFY |
|
|
982 | fs_fd = -2; |
|
|
983 | #endif |
|
|
984 | |
1308 | |
985 | #if EV_USE_PORT |
1309 | #if EV_USE_PORT |
986 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1310 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
987 | #endif |
1311 | #endif |
988 | #if EV_USE_KQUEUE |
1312 | #if EV_USE_KQUEUE |
… | |
… | |
996 | #endif |
1320 | #endif |
997 | #if EV_USE_SELECT |
1321 | #if EV_USE_SELECT |
998 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1322 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
999 | #endif |
1323 | #endif |
1000 | |
1324 | |
1001 | ev_init (&sigev, sigcb); |
1325 | ev_init (&pipeev, pipecb); |
1002 | ev_set_priority (&sigev, EV_MAXPRI); |
1326 | ev_set_priority (&pipeev, EV_MAXPRI); |
1003 | } |
1327 | } |
1004 | } |
1328 | } |
1005 | |
1329 | |
1006 | static void noinline |
1330 | static void noinline |
1007 | loop_destroy (EV_P) |
1331 | loop_destroy (EV_P) |
1008 | { |
1332 | { |
1009 | int i; |
1333 | int i; |
|
|
1334 | |
|
|
1335 | if (ev_is_active (&pipeev)) |
|
|
1336 | { |
|
|
1337 | ev_ref (EV_A); /* signal watcher */ |
|
|
1338 | ev_io_stop (EV_A_ &pipeev); |
|
|
1339 | |
|
|
1340 | #if EV_USE_EVENTFD |
|
|
1341 | if (evfd >= 0) |
|
|
1342 | close (evfd); |
|
|
1343 | #endif |
|
|
1344 | |
|
|
1345 | if (evpipe [0] >= 0) |
|
|
1346 | { |
|
|
1347 | close (evpipe [0]); |
|
|
1348 | close (evpipe [1]); |
|
|
1349 | } |
|
|
1350 | } |
1010 | |
1351 | |
1011 | #if EV_USE_INOTIFY |
1352 | #if EV_USE_INOTIFY |
1012 | if (fs_fd >= 0) |
1353 | if (fs_fd >= 0) |
1013 | close (fs_fd); |
1354 | close (fs_fd); |
1014 | #endif |
1355 | #endif |
… | |
… | |
1051 | #if EV_FORK_ENABLE |
1392 | #if EV_FORK_ENABLE |
1052 | array_free (fork, EMPTY); |
1393 | array_free (fork, EMPTY); |
1053 | #endif |
1394 | #endif |
1054 | array_free (prepare, EMPTY); |
1395 | array_free (prepare, EMPTY); |
1055 | array_free (check, EMPTY); |
1396 | array_free (check, EMPTY); |
|
|
1397 | #if EV_ASYNC_ENABLE |
|
|
1398 | array_free (async, EMPTY); |
|
|
1399 | #endif |
1056 | |
1400 | |
1057 | backend = 0; |
1401 | backend = 0; |
1058 | } |
1402 | } |
1059 | |
1403 | |
|
|
1404 | #if EV_USE_INOTIFY |
1060 | void inline_size infy_fork (EV_P); |
1405 | void inline_size infy_fork (EV_P); |
|
|
1406 | #endif |
1061 | |
1407 | |
1062 | void inline_size |
1408 | void inline_size |
1063 | loop_fork (EV_P) |
1409 | loop_fork (EV_P) |
1064 | { |
1410 | { |
1065 | #if EV_USE_PORT |
1411 | #if EV_USE_PORT |
… | |
… | |
1073 | #endif |
1419 | #endif |
1074 | #if EV_USE_INOTIFY |
1420 | #if EV_USE_INOTIFY |
1075 | infy_fork (EV_A); |
1421 | infy_fork (EV_A); |
1076 | #endif |
1422 | #endif |
1077 | |
1423 | |
1078 | if (ev_is_active (&sigev)) |
1424 | if (ev_is_active (&pipeev)) |
1079 | { |
1425 | { |
1080 | /* default loop */ |
1426 | /* this "locks" the handlers against writing to the pipe */ |
|
|
1427 | /* while we modify the fd vars */ |
|
|
1428 | gotsig = 1; |
|
|
1429 | #if EV_ASYNC_ENABLE |
|
|
1430 | gotasync = 1; |
|
|
1431 | #endif |
1081 | |
1432 | |
1082 | ev_ref (EV_A); |
1433 | ev_ref (EV_A); |
1083 | ev_io_stop (EV_A_ &sigev); |
1434 | ev_io_stop (EV_A_ &pipeev); |
|
|
1435 | |
|
|
1436 | #if EV_USE_EVENTFD |
|
|
1437 | if (evfd >= 0) |
|
|
1438 | close (evfd); |
|
|
1439 | #endif |
|
|
1440 | |
|
|
1441 | if (evpipe [0] >= 0) |
|
|
1442 | { |
1084 | close (sigpipe [0]); |
1443 | close (evpipe [0]); |
1085 | close (sigpipe [1]); |
1444 | close (evpipe [1]); |
|
|
1445 | } |
1086 | |
1446 | |
1087 | while (pipe (sigpipe)) |
|
|
1088 | syserr ("(libev) error creating pipe"); |
|
|
1089 | |
|
|
1090 | siginit (EV_A); |
1447 | evpipe_init (EV_A); |
|
|
1448 | /* now iterate over everything, in case we missed something */ |
|
|
1449 | pipecb (EV_A_ &pipeev, EV_READ); |
1091 | } |
1450 | } |
1092 | |
1451 | |
1093 | postfork = 0; |
1452 | postfork = 0; |
1094 | } |
1453 | } |
1095 | |
1454 | |
… | |
… | |
1117 | } |
1476 | } |
1118 | |
1477 | |
1119 | void |
1478 | void |
1120 | ev_loop_fork (EV_P) |
1479 | ev_loop_fork (EV_P) |
1121 | { |
1480 | { |
1122 | postfork = 1; |
1481 | postfork = 1; /* must be in line with ev_default_fork */ |
1123 | } |
1482 | } |
1124 | |
|
|
1125 | #endif |
1483 | #endif |
1126 | |
1484 | |
1127 | #if EV_MULTIPLICITY |
1485 | #if EV_MULTIPLICITY |
1128 | struct ev_loop * |
1486 | struct ev_loop * |
1129 | ev_default_loop_init (unsigned int flags) |
1487 | ev_default_loop_init (unsigned int flags) |
1130 | #else |
1488 | #else |
1131 | int |
1489 | int |
1132 | ev_default_loop (unsigned int flags) |
1490 | ev_default_loop (unsigned int flags) |
1133 | #endif |
1491 | #endif |
1134 | { |
1492 | { |
1135 | if (sigpipe [0] == sigpipe [1]) |
|
|
1136 | if (pipe (sigpipe)) |
|
|
1137 | return 0; |
|
|
1138 | |
|
|
1139 | if (!ev_default_loop_ptr) |
1493 | if (!ev_default_loop_ptr) |
1140 | { |
1494 | { |
1141 | #if EV_MULTIPLICITY |
1495 | #if EV_MULTIPLICITY |
1142 | struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; |
1496 | struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; |
1143 | #else |
1497 | #else |
… | |
… | |
1146 | |
1500 | |
1147 | loop_init (EV_A_ flags); |
1501 | loop_init (EV_A_ flags); |
1148 | |
1502 | |
1149 | if (ev_backend (EV_A)) |
1503 | if (ev_backend (EV_A)) |
1150 | { |
1504 | { |
1151 | siginit (EV_A); |
|
|
1152 | |
|
|
1153 | #ifndef _WIN32 |
1505 | #ifndef _WIN32 |
1154 | ev_signal_init (&childev, childcb, SIGCHLD); |
1506 | ev_signal_init (&childev, childcb, SIGCHLD); |
1155 | ev_set_priority (&childev, EV_MAXPRI); |
1507 | ev_set_priority (&childev, EV_MAXPRI); |
1156 | ev_signal_start (EV_A_ &childev); |
1508 | ev_signal_start (EV_A_ &childev); |
1157 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1509 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
… | |
… | |
1174 | #ifndef _WIN32 |
1526 | #ifndef _WIN32 |
1175 | ev_ref (EV_A); /* child watcher */ |
1527 | ev_ref (EV_A); /* child watcher */ |
1176 | ev_signal_stop (EV_A_ &childev); |
1528 | ev_signal_stop (EV_A_ &childev); |
1177 | #endif |
1529 | #endif |
1178 | |
1530 | |
1179 | ev_ref (EV_A); /* signal watcher */ |
|
|
1180 | ev_io_stop (EV_A_ &sigev); |
|
|
1181 | |
|
|
1182 | close (sigpipe [0]); sigpipe [0] = 0; |
|
|
1183 | close (sigpipe [1]); sigpipe [1] = 0; |
|
|
1184 | |
|
|
1185 | loop_destroy (EV_A); |
1531 | loop_destroy (EV_A); |
1186 | } |
1532 | } |
1187 | |
1533 | |
1188 | void |
1534 | void |
1189 | ev_default_fork (void) |
1535 | ev_default_fork (void) |
… | |
… | |
1191 | #if EV_MULTIPLICITY |
1537 | #if EV_MULTIPLICITY |
1192 | struct ev_loop *loop = ev_default_loop_ptr; |
1538 | struct ev_loop *loop = ev_default_loop_ptr; |
1193 | #endif |
1539 | #endif |
1194 | |
1540 | |
1195 | if (backend) |
1541 | if (backend) |
1196 | postfork = 1; |
1542 | postfork = 1; /* must be in line with ev_loop_fork */ |
1197 | } |
1543 | } |
1198 | |
1544 | |
1199 | /*****************************************************************************/ |
1545 | /*****************************************************************************/ |
1200 | |
1546 | |
1201 | void |
1547 | void |
… | |
… | |
1221 | p->w->pending = 0; |
1567 | p->w->pending = 0; |
1222 | EV_CB_INVOKE (p->w, p->events); |
1568 | EV_CB_INVOKE (p->w, p->events); |
1223 | } |
1569 | } |
1224 | } |
1570 | } |
1225 | } |
1571 | } |
1226 | |
|
|
1227 | void inline_size |
|
|
1228 | timers_reify (EV_P) |
|
|
1229 | { |
|
|
1230 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
|
|
1231 | { |
|
|
1232 | ev_timer *w = (ev_timer *)timers [0]; |
|
|
1233 | |
|
|
1234 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
|
|
1235 | |
|
|
1236 | /* first reschedule or stop timer */ |
|
|
1237 | if (w->repeat) |
|
|
1238 | { |
|
|
1239 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
|
|
1240 | |
|
|
1241 | ((WT)w)->at += w->repeat; |
|
|
1242 | if (((WT)w)->at < mn_now) |
|
|
1243 | ((WT)w)->at = mn_now; |
|
|
1244 | |
|
|
1245 | downheap (timers, timercnt, 0); |
|
|
1246 | } |
|
|
1247 | else |
|
|
1248 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
|
|
1249 | |
|
|
1250 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
|
|
1251 | } |
|
|
1252 | } |
|
|
1253 | |
|
|
1254 | #if EV_PERIODIC_ENABLE |
|
|
1255 | void inline_size |
|
|
1256 | periodics_reify (EV_P) |
|
|
1257 | { |
|
|
1258 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
|
|
1259 | { |
|
|
1260 | ev_periodic *w = (ev_periodic *)periodics [0]; |
|
|
1261 | |
|
|
1262 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
|
|
1263 | |
|
|
1264 | /* first reschedule or stop timer */ |
|
|
1265 | if (w->reschedule_cb) |
|
|
1266 | { |
|
|
1267 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
|
|
1268 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
|
|
1269 | downheap (periodics, periodiccnt, 0); |
|
|
1270 | } |
|
|
1271 | else if (w->interval) |
|
|
1272 | { |
|
|
1273 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
1274 | if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval; |
|
|
1275 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
|
|
1276 | downheap (periodics, periodiccnt, 0); |
|
|
1277 | } |
|
|
1278 | else |
|
|
1279 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
|
|
1280 | |
|
|
1281 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
|
|
1282 | } |
|
|
1283 | } |
|
|
1284 | |
|
|
1285 | static void noinline |
|
|
1286 | periodics_reschedule (EV_P) |
|
|
1287 | { |
|
|
1288 | int i; |
|
|
1289 | |
|
|
1290 | /* adjust periodics after time jump */ |
|
|
1291 | for (i = 0; i < periodiccnt; ++i) |
|
|
1292 | { |
|
|
1293 | ev_periodic *w = (ev_periodic *)periodics [i]; |
|
|
1294 | |
|
|
1295 | if (w->reschedule_cb) |
|
|
1296 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
|
|
1297 | else if (w->interval) |
|
|
1298 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
1299 | } |
|
|
1300 | |
|
|
1301 | /* now rebuild the heap */ |
|
|
1302 | for (i = periodiccnt >> 1; i--; ) |
|
|
1303 | downheap (periodics, periodiccnt, i); |
|
|
1304 | } |
|
|
1305 | #endif |
|
|
1306 | |
1572 | |
1307 | #if EV_IDLE_ENABLE |
1573 | #if EV_IDLE_ENABLE |
1308 | void inline_size |
1574 | void inline_size |
1309 | idle_reify (EV_P) |
1575 | idle_reify (EV_P) |
1310 | { |
1576 | { |
… | |
… | |
1322 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
1588 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
1323 | break; |
1589 | break; |
1324 | } |
1590 | } |
1325 | } |
1591 | } |
1326 | } |
1592 | } |
|
|
1593 | } |
|
|
1594 | #endif |
|
|
1595 | |
|
|
1596 | void inline_size |
|
|
1597 | timers_reify (EV_P) |
|
|
1598 | { |
|
|
1599 | while (timercnt && ANHE_at (timers [HEAP0]) <= mn_now) |
|
|
1600 | { |
|
|
1601 | ev_timer *w = (ev_timer *)ANHE_w (timers [HEAP0]); |
|
|
1602 | |
|
|
1603 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
|
|
1604 | |
|
|
1605 | /* first reschedule or stop timer */ |
|
|
1606 | if (w->repeat) |
|
|
1607 | { |
|
|
1608 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
|
|
1609 | |
|
|
1610 | ev_at (w) += w->repeat; |
|
|
1611 | if (ev_at (w) < mn_now) |
|
|
1612 | ev_at (w) = mn_now; |
|
|
1613 | |
|
|
1614 | downheap (timers, timercnt, HEAP0); |
|
|
1615 | } |
|
|
1616 | else |
|
|
1617 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
|
|
1618 | |
|
|
1619 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
|
|
1620 | } |
|
|
1621 | } |
|
|
1622 | |
|
|
1623 | #if EV_PERIODIC_ENABLE |
|
|
1624 | void inline_size |
|
|
1625 | periodics_reify (EV_P) |
|
|
1626 | { |
|
|
1627 | while (periodiccnt && ANHE_at (periodics [HEAP0]) <= ev_rt_now) |
|
|
1628 | { |
|
|
1629 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
|
|
1630 | |
|
|
1631 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
|
|
1632 | |
|
|
1633 | /* first reschedule or stop timer */ |
|
|
1634 | if (w->reschedule_cb) |
|
|
1635 | { |
|
|
1636 | ev_at (w) = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
|
|
1637 | assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) > ev_rt_now)); |
|
|
1638 | downheap (periodics, periodiccnt, 1); |
|
|
1639 | } |
|
|
1640 | else if (w->interval) |
|
|
1641 | { |
|
|
1642 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
1643 | if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval; |
|
|
1644 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now)); |
|
|
1645 | downheap (periodics, periodiccnt, HEAP0); |
|
|
1646 | } |
|
|
1647 | else |
|
|
1648 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
|
|
1649 | |
|
|
1650 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
|
|
1651 | } |
|
|
1652 | } |
|
|
1653 | |
|
|
1654 | static void noinline |
|
|
1655 | periodics_reschedule (EV_P) |
|
|
1656 | { |
|
|
1657 | int i; |
|
|
1658 | |
|
|
1659 | /* adjust periodics after time jump */ |
|
|
1660 | for (i = HEAP0; i < periodiccnt + HEAP0; ++i) |
|
|
1661 | { |
|
|
1662 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [i]); |
|
|
1663 | |
|
|
1664 | if (w->reschedule_cb) |
|
|
1665 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
|
|
1666 | else if (w->interval) |
|
|
1667 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
1668 | } |
|
|
1669 | |
|
|
1670 | /* now rebuild the heap, this for the 2-heap, inefficient for the 4-heap, but correct */ |
|
|
1671 | for (i = periodiccnt >> 1; --i; ) |
|
|
1672 | downheap (periodics, periodiccnt, i + HEAP0); |
1327 | } |
1673 | } |
1328 | #endif |
1674 | #endif |
1329 | |
1675 | |
1330 | void inline_speed |
1676 | void inline_speed |
1331 | time_update (EV_P_ ev_tstamp max_block) |
1677 | time_update (EV_P_ ev_tstamp max_block) |
… | |
… | |
1360 | */ |
1706 | */ |
1361 | for (i = 4; --i; ) |
1707 | for (i = 4; --i; ) |
1362 | { |
1708 | { |
1363 | rtmn_diff = ev_rt_now - mn_now; |
1709 | rtmn_diff = ev_rt_now - mn_now; |
1364 | |
1710 | |
1365 | if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) |
1711 | if (expect_true (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP)) |
1366 | return; /* all is well */ |
1712 | return; /* all is well */ |
1367 | |
1713 | |
1368 | ev_rt_now = ev_time (); |
1714 | ev_rt_now = ev_time (); |
1369 | mn_now = get_clock (); |
1715 | mn_now = get_clock (); |
1370 | now_floor = mn_now; |
1716 | now_floor = mn_now; |
… | |
… | |
1386 | #if EV_PERIODIC_ENABLE |
1732 | #if EV_PERIODIC_ENABLE |
1387 | periodics_reschedule (EV_A); |
1733 | periodics_reschedule (EV_A); |
1388 | #endif |
1734 | #endif |
1389 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1735 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1390 | for (i = 0; i < timercnt; ++i) |
1736 | for (i = 0; i < timercnt; ++i) |
|
|
1737 | { |
|
|
1738 | ANHE *he = timers + i + HEAP0; |
1391 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1739 | ANHE_w (*he)->at += ev_rt_now - mn_now; |
|
|
1740 | ANHE_at_set (*he); |
|
|
1741 | } |
1392 | } |
1742 | } |
1393 | |
1743 | |
1394 | mn_now = ev_rt_now; |
1744 | mn_now = ev_rt_now; |
1395 | } |
1745 | } |
1396 | } |
1746 | } |
… | |
… | |
1410 | static int loop_done; |
1760 | static int loop_done; |
1411 | |
1761 | |
1412 | void |
1762 | void |
1413 | ev_loop (EV_P_ int flags) |
1763 | ev_loop (EV_P_ int flags) |
1414 | { |
1764 | { |
1415 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1765 | loop_done = EVUNLOOP_CANCEL; |
1416 | ? EVUNLOOP_ONE |
|
|
1417 | : EVUNLOOP_CANCEL; |
|
|
1418 | |
1766 | |
1419 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1767 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1420 | |
1768 | |
1421 | do |
1769 | do |
1422 | { |
1770 | { |
… | |
… | |
1456 | /* update fd-related kernel structures */ |
1804 | /* update fd-related kernel structures */ |
1457 | fd_reify (EV_A); |
1805 | fd_reify (EV_A); |
1458 | |
1806 | |
1459 | /* calculate blocking time */ |
1807 | /* calculate blocking time */ |
1460 | { |
1808 | { |
1461 | ev_tstamp block; |
1809 | ev_tstamp waittime = 0.; |
|
|
1810 | ev_tstamp sleeptime = 0.; |
1462 | |
1811 | |
1463 | if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) |
1812 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
1464 | block = 0.; /* do not block at all */ |
|
|
1465 | else |
|
|
1466 | { |
1813 | { |
1467 | /* update time to cancel out callback processing overhead */ |
1814 | /* update time to cancel out callback processing overhead */ |
1468 | time_update (EV_A_ 1e100); |
1815 | time_update (EV_A_ 1e100); |
1469 | |
1816 | |
1470 | block = MAX_BLOCKTIME; |
1817 | waittime = MAX_BLOCKTIME; |
1471 | |
1818 | |
1472 | if (timercnt) |
1819 | if (timercnt) |
1473 | { |
1820 | { |
1474 | ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; |
1821 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
1475 | if (block > to) block = to; |
1822 | if (waittime > to) waittime = to; |
1476 | } |
1823 | } |
1477 | |
1824 | |
1478 | #if EV_PERIODIC_ENABLE |
1825 | #if EV_PERIODIC_ENABLE |
1479 | if (periodiccnt) |
1826 | if (periodiccnt) |
1480 | { |
1827 | { |
1481 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; |
1828 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
1482 | if (block > to) block = to; |
1829 | if (waittime > to) waittime = to; |
1483 | } |
1830 | } |
1484 | #endif |
1831 | #endif |
1485 | |
1832 | |
1486 | if (expect_false (block < 0.)) block = 0.; |
1833 | if (expect_false (waittime < timeout_blocktime)) |
|
|
1834 | waittime = timeout_blocktime; |
|
|
1835 | |
|
|
1836 | sleeptime = waittime - backend_fudge; |
|
|
1837 | |
|
|
1838 | if (expect_true (sleeptime > io_blocktime)) |
|
|
1839 | sleeptime = io_blocktime; |
|
|
1840 | |
|
|
1841 | if (sleeptime) |
|
|
1842 | { |
|
|
1843 | ev_sleep (sleeptime); |
|
|
1844 | waittime -= sleeptime; |
|
|
1845 | } |
1487 | } |
1846 | } |
1488 | |
1847 | |
1489 | ++loop_count; |
1848 | ++loop_count; |
1490 | backend_poll (EV_A_ block); |
1849 | backend_poll (EV_A_ waittime); |
1491 | |
1850 | |
1492 | /* update ev_rt_now, do magic */ |
1851 | /* update ev_rt_now, do magic */ |
1493 | time_update (EV_A_ block); |
1852 | time_update (EV_A_ waittime + sleeptime); |
1494 | } |
1853 | } |
1495 | |
1854 | |
1496 | /* queue pending timers and reschedule them */ |
1855 | /* queue pending timers and reschedule them */ |
1497 | timers_reify (EV_A); /* relative timers called last */ |
1856 | timers_reify (EV_A); /* relative timers called last */ |
1498 | #if EV_PERIODIC_ENABLE |
1857 | #if EV_PERIODIC_ENABLE |
… | |
… | |
1507 | /* queue check watchers, to be executed first */ |
1866 | /* queue check watchers, to be executed first */ |
1508 | if (expect_false (checkcnt)) |
1867 | if (expect_false (checkcnt)) |
1509 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1868 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1510 | |
1869 | |
1511 | call_pending (EV_A); |
1870 | call_pending (EV_A); |
1512 | |
|
|
1513 | } |
1871 | } |
1514 | while (expect_true (activecnt && !loop_done)); |
1872 | while (expect_true ( |
|
|
1873 | activecnt |
|
|
1874 | && !loop_done |
|
|
1875 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
|
|
1876 | )); |
1515 | |
1877 | |
1516 | if (loop_done == EVUNLOOP_ONE) |
1878 | if (loop_done == EVUNLOOP_ONE) |
1517 | loop_done = EVUNLOOP_CANCEL; |
1879 | loop_done = EVUNLOOP_CANCEL; |
1518 | } |
1880 | } |
1519 | |
1881 | |
… | |
… | |
1637 | ev_timer_start (EV_P_ ev_timer *w) |
1999 | ev_timer_start (EV_P_ ev_timer *w) |
1638 | { |
2000 | { |
1639 | if (expect_false (ev_is_active (w))) |
2001 | if (expect_false (ev_is_active (w))) |
1640 | return; |
2002 | return; |
1641 | |
2003 | |
1642 | ((WT)w)->at += mn_now; |
2004 | ev_at (w) += mn_now; |
1643 | |
2005 | |
1644 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
2006 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1645 | |
2007 | |
1646 | ev_start (EV_A_ (W)w, ++timercnt); |
2008 | ev_start (EV_A_ (W)w, ++timercnt + HEAP0 - 1); |
1647 | array_needsize (WT, timers, timermax, timercnt, EMPTY2); |
2009 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
1648 | timers [timercnt - 1] = (WT)w; |
2010 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
1649 | upheap (timers, timercnt - 1); |
2011 | ANHE_at_set (timers [ev_active (w)]); |
|
|
2012 | upheap (timers, ev_active (w)); |
1650 | |
2013 | |
1651 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
2014 | /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/ |
1652 | } |
2015 | } |
1653 | |
2016 | |
1654 | void noinline |
2017 | void noinline |
1655 | ev_timer_stop (EV_P_ ev_timer *w) |
2018 | ev_timer_stop (EV_P_ ev_timer *w) |
1656 | { |
2019 | { |
1657 | clear_pending (EV_A_ (W)w); |
2020 | clear_pending (EV_A_ (W)w); |
1658 | if (expect_false (!ev_is_active (w))) |
2021 | if (expect_false (!ev_is_active (w))) |
1659 | return; |
2022 | return; |
1660 | |
2023 | |
1661 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w)); |
|
|
1662 | |
|
|
1663 | { |
2024 | { |
1664 | int active = ((W)w)->active; |
2025 | int active = ev_active (w); |
1665 | |
2026 | |
|
|
2027 | assert (("internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
|
|
2028 | |
1666 | if (expect_true (--active < --timercnt)) |
2029 | if (expect_true (active < timercnt + HEAP0 - 1)) |
1667 | { |
2030 | { |
1668 | timers [active] = timers [timercnt]; |
2031 | timers [active] = timers [timercnt + HEAP0 - 1]; |
1669 | adjustheap (timers, timercnt, active); |
2032 | adjustheap (timers, timercnt, active); |
1670 | } |
2033 | } |
|
|
2034 | |
|
|
2035 | --timercnt; |
1671 | } |
2036 | } |
1672 | |
2037 | |
1673 | ((WT)w)->at -= mn_now; |
2038 | ev_at (w) -= mn_now; |
1674 | |
2039 | |
1675 | ev_stop (EV_A_ (W)w); |
2040 | ev_stop (EV_A_ (W)w); |
1676 | } |
2041 | } |
1677 | |
2042 | |
1678 | void noinline |
2043 | void noinline |
… | |
… | |
1680 | { |
2045 | { |
1681 | if (ev_is_active (w)) |
2046 | if (ev_is_active (w)) |
1682 | { |
2047 | { |
1683 | if (w->repeat) |
2048 | if (w->repeat) |
1684 | { |
2049 | { |
1685 | ((WT)w)->at = mn_now + w->repeat; |
2050 | ev_at (w) = mn_now + w->repeat; |
|
|
2051 | ANHE_at_set (timers [ev_active (w)]); |
1686 | adjustheap (timers, timercnt, ((W)w)->active - 1); |
2052 | adjustheap (timers, timercnt, ev_active (w)); |
1687 | } |
2053 | } |
1688 | else |
2054 | else |
1689 | ev_timer_stop (EV_A_ w); |
2055 | ev_timer_stop (EV_A_ w); |
1690 | } |
2056 | } |
1691 | else if (w->repeat) |
2057 | else if (w->repeat) |
1692 | { |
2058 | { |
1693 | w->at = w->repeat; |
2059 | ev_at (w) = w->repeat; |
1694 | ev_timer_start (EV_A_ w); |
2060 | ev_timer_start (EV_A_ w); |
1695 | } |
2061 | } |
1696 | } |
2062 | } |
1697 | |
2063 | |
1698 | #if EV_PERIODIC_ENABLE |
2064 | #if EV_PERIODIC_ENABLE |
… | |
… | |
1701 | { |
2067 | { |
1702 | if (expect_false (ev_is_active (w))) |
2068 | if (expect_false (ev_is_active (w))) |
1703 | return; |
2069 | return; |
1704 | |
2070 | |
1705 | if (w->reschedule_cb) |
2071 | if (w->reschedule_cb) |
1706 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
2072 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1707 | else if (w->interval) |
2073 | else if (w->interval) |
1708 | { |
2074 | { |
1709 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
2075 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1710 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
2076 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1711 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2077 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1712 | } |
2078 | } |
1713 | else |
2079 | else |
1714 | ((WT)w)->at = w->offset; |
2080 | ev_at (w) = w->offset; |
1715 | |
2081 | |
1716 | ev_start (EV_A_ (W)w, ++periodiccnt); |
2082 | ev_start (EV_A_ (W)w, ++periodiccnt + HEAP0 - 1); |
1717 | array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2); |
2083 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
1718 | periodics [periodiccnt - 1] = (WT)w; |
2084 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
1719 | upheap (periodics, periodiccnt - 1); |
2085 | upheap (periodics, ev_active (w)); |
1720 | |
2086 | |
1721 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
2087 | /*assert (("internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
1722 | } |
2088 | } |
1723 | |
2089 | |
1724 | void noinline |
2090 | void noinline |
1725 | ev_periodic_stop (EV_P_ ev_periodic *w) |
2091 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1726 | { |
2092 | { |
1727 | clear_pending (EV_A_ (W)w); |
2093 | clear_pending (EV_A_ (W)w); |
1728 | if (expect_false (!ev_is_active (w))) |
2094 | if (expect_false (!ev_is_active (w))) |
1729 | return; |
2095 | return; |
1730 | |
2096 | |
1731 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w)); |
|
|
1732 | |
|
|
1733 | { |
2097 | { |
1734 | int active = ((W)w)->active; |
2098 | int active = ev_active (w); |
1735 | |
2099 | |
|
|
2100 | assert (("internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
|
|
2101 | |
1736 | if (expect_true (--active < --periodiccnt)) |
2102 | if (expect_true (active < periodiccnt + HEAP0 - 1)) |
1737 | { |
2103 | { |
1738 | periodics [active] = periodics [periodiccnt]; |
2104 | periodics [active] = periodics [periodiccnt + HEAP0 - 1]; |
1739 | adjustheap (periodics, periodiccnt, active); |
2105 | adjustheap (periodics, periodiccnt, active); |
1740 | } |
2106 | } |
|
|
2107 | |
|
|
2108 | --periodiccnt; |
1741 | } |
2109 | } |
1742 | |
2110 | |
1743 | ev_stop (EV_A_ (W)w); |
2111 | ev_stop (EV_A_ (W)w); |
1744 | } |
2112 | } |
1745 | |
2113 | |
… | |
… | |
1764 | #endif |
2132 | #endif |
1765 | if (expect_false (ev_is_active (w))) |
2133 | if (expect_false (ev_is_active (w))) |
1766 | return; |
2134 | return; |
1767 | |
2135 | |
1768 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
2136 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
|
|
2137 | |
|
|
2138 | evpipe_init (EV_A); |
1769 | |
2139 | |
1770 | { |
2140 | { |
1771 | #ifndef _WIN32 |
2141 | #ifndef _WIN32 |
1772 | sigset_t full, prev; |
2142 | sigset_t full, prev; |
1773 | sigfillset (&full); |
2143 | sigfillset (&full); |
… | |
… | |
1785 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
2155 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
1786 | |
2156 | |
1787 | if (!((WL)w)->next) |
2157 | if (!((WL)w)->next) |
1788 | { |
2158 | { |
1789 | #if _WIN32 |
2159 | #if _WIN32 |
1790 | signal (w->signum, sighandler); |
2160 | signal (w->signum, ev_sighandler); |
1791 | #else |
2161 | #else |
1792 | struct sigaction sa; |
2162 | struct sigaction sa; |
1793 | sa.sa_handler = sighandler; |
2163 | sa.sa_handler = ev_sighandler; |
1794 | sigfillset (&sa.sa_mask); |
2164 | sigfillset (&sa.sa_mask); |
1795 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2165 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1796 | sigaction (w->signum, &sa, 0); |
2166 | sigaction (w->signum, &sa, 0); |
1797 | #endif |
2167 | #endif |
1798 | } |
2168 | } |
… | |
… | |
1859 | if (w->wd < 0) |
2229 | if (w->wd < 0) |
1860 | { |
2230 | { |
1861 | ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
2231 | ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
1862 | |
2232 | |
1863 | /* monitor some parent directory for speedup hints */ |
2233 | /* monitor some parent directory for speedup hints */ |
|
|
2234 | /* note that exceeding the hardcoded limit is not a correctness issue, */ |
|
|
2235 | /* but an efficiency issue only */ |
1864 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2236 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
1865 | { |
2237 | { |
1866 | char path [4096]; |
2238 | char path [4096]; |
1867 | strcpy (path, w->path); |
2239 | strcpy (path, w->path); |
1868 | |
2240 | |
… | |
… | |
2113 | clear_pending (EV_A_ (W)w); |
2485 | clear_pending (EV_A_ (W)w); |
2114 | if (expect_false (!ev_is_active (w))) |
2486 | if (expect_false (!ev_is_active (w))) |
2115 | return; |
2487 | return; |
2116 | |
2488 | |
2117 | { |
2489 | { |
2118 | int active = ((W)w)->active; |
2490 | int active = ev_active (w); |
2119 | |
2491 | |
2120 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2492 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2121 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
2493 | ev_active (idles [ABSPRI (w)][active - 1]) = active; |
2122 | |
2494 | |
2123 | ev_stop (EV_A_ (W)w); |
2495 | ev_stop (EV_A_ (W)w); |
2124 | --idleall; |
2496 | --idleall; |
2125 | } |
2497 | } |
2126 | } |
2498 | } |
… | |
… | |
2143 | clear_pending (EV_A_ (W)w); |
2515 | clear_pending (EV_A_ (W)w); |
2144 | if (expect_false (!ev_is_active (w))) |
2516 | if (expect_false (!ev_is_active (w))) |
2145 | return; |
2517 | return; |
2146 | |
2518 | |
2147 | { |
2519 | { |
2148 | int active = ((W)w)->active; |
2520 | int active = ev_active (w); |
|
|
2521 | |
2149 | prepares [active - 1] = prepares [--preparecnt]; |
2522 | prepares [active - 1] = prepares [--preparecnt]; |
2150 | ((W)prepares [active - 1])->active = active; |
2523 | ev_active (prepares [active - 1]) = active; |
2151 | } |
2524 | } |
2152 | |
2525 | |
2153 | ev_stop (EV_A_ (W)w); |
2526 | ev_stop (EV_A_ (W)w); |
2154 | } |
2527 | } |
2155 | |
2528 | |
… | |
… | |
2170 | clear_pending (EV_A_ (W)w); |
2543 | clear_pending (EV_A_ (W)w); |
2171 | if (expect_false (!ev_is_active (w))) |
2544 | if (expect_false (!ev_is_active (w))) |
2172 | return; |
2545 | return; |
2173 | |
2546 | |
2174 | { |
2547 | { |
2175 | int active = ((W)w)->active; |
2548 | int active = ev_active (w); |
|
|
2549 | |
2176 | checks [active - 1] = checks [--checkcnt]; |
2550 | checks [active - 1] = checks [--checkcnt]; |
2177 | ((W)checks [active - 1])->active = active; |
2551 | ev_active (checks [active - 1]) = active; |
2178 | } |
2552 | } |
2179 | |
2553 | |
2180 | ev_stop (EV_A_ (W)w); |
2554 | ev_stop (EV_A_ (W)w); |
2181 | } |
2555 | } |
2182 | |
2556 | |
… | |
… | |
2193 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
2567 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
2194 | |
2568 | |
2195 | if (ev_cb (w)) |
2569 | if (ev_cb (w)) |
2196 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
2570 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
2197 | else |
2571 | else |
2198 | ev_embed_sweep (loop, w); |
2572 | ev_loop (w->other, EVLOOP_NONBLOCK); |
2199 | } |
2573 | } |
2200 | |
2574 | |
2201 | static void |
2575 | static void |
2202 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
2576 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
2203 | { |
2577 | { |
2204 | ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); |
2578 | ev_embed *w = (ev_embed *)(((char *)prepare) - offsetof (ev_embed, prepare)); |
2205 | |
2579 | |
2206 | fd_reify (w->other); |
2580 | { |
|
|
2581 | struct ev_loop *loop = w->other; |
|
|
2582 | |
|
|
2583 | while (fdchangecnt) |
|
|
2584 | { |
|
|
2585 | fd_reify (EV_A); |
|
|
2586 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
|
|
2587 | } |
|
|
2588 | } |
2207 | } |
2589 | } |
|
|
2590 | |
|
|
2591 | #if 0 |
|
|
2592 | static void |
|
|
2593 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
|
|
2594 | { |
|
|
2595 | ev_idle_stop (EV_A_ idle); |
|
|
2596 | } |
|
|
2597 | #endif |
2208 | |
2598 | |
2209 | void |
2599 | void |
2210 | ev_embed_start (EV_P_ ev_embed *w) |
2600 | ev_embed_start (EV_P_ ev_embed *w) |
2211 | { |
2601 | { |
2212 | if (expect_false (ev_is_active (w))) |
2602 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2223 | |
2613 | |
2224 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2614 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2225 | ev_set_priority (&w->prepare, EV_MINPRI); |
2615 | ev_set_priority (&w->prepare, EV_MINPRI); |
2226 | ev_prepare_start (EV_A_ &w->prepare); |
2616 | ev_prepare_start (EV_A_ &w->prepare); |
2227 | |
2617 | |
|
|
2618 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
|
|
2619 | |
2228 | ev_start (EV_A_ (W)w, 1); |
2620 | ev_start (EV_A_ (W)w, 1); |
2229 | } |
2621 | } |
2230 | |
2622 | |
2231 | void |
2623 | void |
2232 | ev_embed_stop (EV_P_ ev_embed *w) |
2624 | ev_embed_stop (EV_P_ ev_embed *w) |
… | |
… | |
2260 | clear_pending (EV_A_ (W)w); |
2652 | clear_pending (EV_A_ (W)w); |
2261 | if (expect_false (!ev_is_active (w))) |
2653 | if (expect_false (!ev_is_active (w))) |
2262 | return; |
2654 | return; |
2263 | |
2655 | |
2264 | { |
2656 | { |
2265 | int active = ((W)w)->active; |
2657 | int active = ev_active (w); |
|
|
2658 | |
2266 | forks [active - 1] = forks [--forkcnt]; |
2659 | forks [active - 1] = forks [--forkcnt]; |
2267 | ((W)forks [active - 1])->active = active; |
2660 | ev_active (forks [active - 1]) = active; |
2268 | } |
2661 | } |
2269 | |
2662 | |
2270 | ev_stop (EV_A_ (W)w); |
2663 | ev_stop (EV_A_ (W)w); |
|
|
2664 | } |
|
|
2665 | #endif |
|
|
2666 | |
|
|
2667 | #if EV_ASYNC_ENABLE |
|
|
2668 | void |
|
|
2669 | ev_async_start (EV_P_ ev_async *w) |
|
|
2670 | { |
|
|
2671 | if (expect_false (ev_is_active (w))) |
|
|
2672 | return; |
|
|
2673 | |
|
|
2674 | evpipe_init (EV_A); |
|
|
2675 | |
|
|
2676 | ev_start (EV_A_ (W)w, ++asynccnt); |
|
|
2677 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
|
|
2678 | asyncs [asynccnt - 1] = w; |
|
|
2679 | } |
|
|
2680 | |
|
|
2681 | void |
|
|
2682 | ev_async_stop (EV_P_ ev_async *w) |
|
|
2683 | { |
|
|
2684 | clear_pending (EV_A_ (W)w); |
|
|
2685 | if (expect_false (!ev_is_active (w))) |
|
|
2686 | return; |
|
|
2687 | |
|
|
2688 | { |
|
|
2689 | int active = ev_active (w); |
|
|
2690 | |
|
|
2691 | asyncs [active - 1] = asyncs [--asynccnt]; |
|
|
2692 | ev_active (asyncs [active - 1]) = active; |
|
|
2693 | } |
|
|
2694 | |
|
|
2695 | ev_stop (EV_A_ (W)w); |
|
|
2696 | } |
|
|
2697 | |
|
|
2698 | void |
|
|
2699 | ev_async_send (EV_P_ ev_async *w) |
|
|
2700 | { |
|
|
2701 | w->sent = 1; |
|
|
2702 | evpipe_write (EV_A_ &gotasync); |
2271 | } |
2703 | } |
2272 | #endif |
2704 | #endif |
2273 | |
2705 | |
2274 | /*****************************************************************************/ |
2706 | /*****************************************************************************/ |
2275 | |
2707 | |