… | |
… | |
126 | # define EV_USE_EVENTFD 1 |
126 | # define EV_USE_EVENTFD 1 |
127 | # else |
127 | # else |
128 | # define EV_USE_EVENTFD 0 |
128 | # define EV_USE_EVENTFD 0 |
129 | # endif |
129 | # endif |
130 | # endif |
130 | # endif |
131 | |
131 | |
132 | #endif |
132 | #endif |
133 | |
133 | |
134 | #include <math.h> |
134 | #include <math.h> |
135 | #include <stdlib.h> |
135 | #include <stdlib.h> |
136 | #include <fcntl.h> |
136 | #include <fcntl.h> |
… | |
… | |
154 | #ifndef _WIN32 |
154 | #ifndef _WIN32 |
155 | # include <sys/time.h> |
155 | # include <sys/time.h> |
156 | # include <sys/wait.h> |
156 | # include <sys/wait.h> |
157 | # include <unistd.h> |
157 | # include <unistd.h> |
158 | #else |
158 | #else |
|
|
159 | # include <io.h> |
159 | # define WIN32_LEAN_AND_MEAN |
160 | # define WIN32_LEAN_AND_MEAN |
160 | # include <windows.h> |
161 | # include <windows.h> |
161 | # ifndef EV_SELECT_IS_WINSOCKET |
162 | # ifndef EV_SELECT_IS_WINSOCKET |
162 | # define EV_SELECT_IS_WINSOCKET 1 |
163 | # define EV_SELECT_IS_WINSOCKET 1 |
163 | # endif |
164 | # endif |
164 | #endif |
165 | #endif |
165 | |
166 | |
166 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
167 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
167 | |
168 | |
168 | #ifndef EV_USE_MONOTONIC |
169 | #ifndef EV_USE_MONOTONIC |
|
|
170 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
|
|
171 | # define EV_USE_MONOTONIC 1 |
|
|
172 | # else |
169 | # define EV_USE_MONOTONIC 0 |
173 | # define EV_USE_MONOTONIC 0 |
|
|
174 | # endif |
170 | #endif |
175 | #endif |
171 | |
176 | |
172 | #ifndef EV_USE_REALTIME |
177 | #ifndef EV_USE_REALTIME |
173 | # define EV_USE_REALTIME 0 |
178 | # define EV_USE_REALTIME 0 |
174 | #endif |
179 | #endif |
175 | |
180 | |
176 | #ifndef EV_USE_NANOSLEEP |
181 | #ifndef EV_USE_NANOSLEEP |
|
|
182 | # if _POSIX_C_SOURCE >= 199309L |
|
|
183 | # define EV_USE_NANOSLEEP 1 |
|
|
184 | # else |
177 | # define EV_USE_NANOSLEEP 0 |
185 | # define EV_USE_NANOSLEEP 0 |
|
|
186 | # endif |
178 | #endif |
187 | #endif |
179 | |
188 | |
180 | #ifndef EV_USE_SELECT |
189 | #ifndef EV_USE_SELECT |
181 | # define EV_USE_SELECT 1 |
190 | # define EV_USE_SELECT 1 |
182 | #endif |
191 | #endif |
… | |
… | |
235 | # else |
244 | # else |
236 | # define EV_USE_EVENTFD 0 |
245 | # define EV_USE_EVENTFD 0 |
237 | # endif |
246 | # endif |
238 | #endif |
247 | #endif |
239 | |
248 | |
|
|
249 | #if 0 /* debugging */ |
|
|
250 | # define EV_VERIFY 3 |
|
|
251 | # define EV_USE_4HEAP 1 |
|
|
252 | # define EV_HEAP_CACHE_AT 1 |
|
|
253 | #endif |
|
|
254 | |
|
|
255 | #ifndef EV_VERIFY |
|
|
256 | # define EV_VERIFY !EV_MINIMAL |
|
|
257 | #endif |
|
|
258 | |
|
|
259 | #ifndef EV_USE_4HEAP |
|
|
260 | # define EV_USE_4HEAP !EV_MINIMAL |
|
|
261 | #endif |
|
|
262 | |
|
|
263 | #ifndef EV_HEAP_CACHE_AT |
|
|
264 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
|
|
265 | #endif |
|
|
266 | |
240 | /* this block fixes any misconfiguration where we know we run into trouble otherwise */ |
267 | /* this block fixes any misconfiguration where we know we run into trouble otherwise */ |
241 | |
268 | |
242 | #ifndef CLOCK_MONOTONIC |
269 | #ifndef CLOCK_MONOTONIC |
243 | # undef EV_USE_MONOTONIC |
270 | # undef EV_USE_MONOTONIC |
244 | # define EV_USE_MONOTONIC 0 |
271 | # define EV_USE_MONOTONIC 0 |
… | |
… | |
259 | # include <sys/select.h> |
286 | # include <sys/select.h> |
260 | # endif |
287 | # endif |
261 | #endif |
288 | #endif |
262 | |
289 | |
263 | #if EV_USE_INOTIFY |
290 | #if EV_USE_INOTIFY |
|
|
291 | # include <sys/utsname.h> |
|
|
292 | # include <sys/statfs.h> |
264 | # include <sys/inotify.h> |
293 | # include <sys/inotify.h> |
|
|
294 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
|
|
295 | # ifndef IN_DONT_FOLLOW |
|
|
296 | # undef EV_USE_INOTIFY |
|
|
297 | # define EV_USE_INOTIFY 0 |
|
|
298 | # endif |
265 | #endif |
299 | #endif |
266 | |
300 | |
267 | #if EV_SELECT_IS_WINSOCKET |
301 | #if EV_SELECT_IS_WINSOCKET |
268 | # include <winsock.h> |
302 | # include <winsock.h> |
269 | #endif |
303 | #endif |
… | |
… | |
279 | } |
313 | } |
280 | # endif |
314 | # endif |
281 | #endif |
315 | #endif |
282 | |
316 | |
283 | /**/ |
317 | /**/ |
|
|
318 | |
|
|
319 | #if EV_VERIFY >= 3 |
|
|
320 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
|
|
321 | #else |
|
|
322 | # define EV_FREQUENT_CHECK do { } while (0) |
|
|
323 | #endif |
284 | |
324 | |
285 | /* |
325 | /* |
286 | * This is used to avoid floating point rounding problems. |
326 | * This is used to avoid floating point rounding problems. |
287 | * It is added to ev_rt_now when scheduling periodics |
327 | * It is added to ev_rt_now when scheduling periodics |
288 | * to ensure progress, time-wise, even when rounding |
328 | * to ensure progress, time-wise, even when rounding |
… | |
… | |
349 | { |
389 | { |
350 | syserr_cb = cb; |
390 | syserr_cb = cb; |
351 | } |
391 | } |
352 | |
392 | |
353 | static void noinline |
393 | static void noinline |
354 | syserr (const char *msg) |
394 | ev_syserr (const char *msg) |
355 | { |
395 | { |
356 | if (!msg) |
396 | if (!msg) |
357 | msg = "(libev) system error"; |
397 | msg = "(libev) system error"; |
358 | |
398 | |
359 | if (syserr_cb) |
399 | if (syserr_cb) |
… | |
… | |
410 | typedef struct |
450 | typedef struct |
411 | { |
451 | { |
412 | WL head; |
452 | WL head; |
413 | unsigned char events; |
453 | unsigned char events; |
414 | unsigned char reify; |
454 | unsigned char reify; |
|
|
455 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
|
|
456 | unsigned char unused; |
|
|
457 | #if EV_USE_EPOLL |
|
|
458 | unsigned int egen; /* generation counter to counter epoll bugs */ |
|
|
459 | #endif |
415 | #if EV_SELECT_IS_WINSOCKET |
460 | #if EV_SELECT_IS_WINSOCKET |
416 | SOCKET handle; |
461 | SOCKET handle; |
417 | #endif |
462 | #endif |
418 | } ANFD; |
463 | } ANFD; |
419 | |
464 | |
… | |
… | |
432 | #endif |
477 | #endif |
433 | |
478 | |
434 | /* Heap Entry */ |
479 | /* Heap Entry */ |
435 | #if EV_HEAP_CACHE_AT |
480 | #if EV_HEAP_CACHE_AT |
436 | typedef struct { |
481 | typedef struct { |
|
|
482 | ev_tstamp at; |
437 | WT w; |
483 | WT w; |
438 | ev_tstamp at; |
|
|
439 | } ANHE; |
484 | } ANHE; |
440 | |
485 | |
441 | #define ANHE_w(he) (he) /* access watcher, read-write */ |
486 | #define ANHE_w(he) (he).w /* access watcher, read-write */ |
442 | #define ANHE_at(he) (he)->at /* acces cahced at, read-only */ |
487 | #define ANHE_at(he) (he).at /* access cached at, read-only */ |
443 | #define ANHE_at_set(he) (he)->at = (he)->w->at /* update at from watcher */ |
488 | #define ANHE_at_cache(he) (he).at = (he).w->at /* update at from watcher */ |
444 | #else |
489 | #else |
445 | typedef WT ANHE; |
490 | typedef WT ANHE; |
446 | |
491 | |
447 | #define ANHE_w(he) (he) |
492 | #define ANHE_w(he) (he) |
448 | #define ANHE_at(he) (he)->at |
493 | #define ANHE_at(he) (he)->at |
449 | #define ANHE_at_set(he) |
494 | #define ANHE_at_cache(he) |
450 | #endif |
495 | #endif |
451 | |
496 | |
452 | #if EV_MULTIPLICITY |
497 | #if EV_MULTIPLICITY |
453 | |
498 | |
454 | struct ev_loop |
499 | struct ev_loop |
… | |
… | |
532 | struct timeval tv; |
577 | struct timeval tv; |
533 | |
578 | |
534 | tv.tv_sec = (time_t)delay; |
579 | tv.tv_sec = (time_t)delay; |
535 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
580 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
536 | |
581 | |
|
|
582 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
|
|
583 | /* somehting nto guaranteed by newer posix versions, but guaranteed */ |
|
|
584 | /* by older ones */ |
537 | select (0, 0, 0, 0, &tv); |
585 | select (0, 0, 0, 0, &tv); |
538 | #endif |
586 | #endif |
539 | } |
587 | } |
540 | } |
588 | } |
541 | |
589 | |
… | |
… | |
568 | array_realloc (int elem, void *base, int *cur, int cnt) |
616 | array_realloc (int elem, void *base, int *cur, int cnt) |
569 | { |
617 | { |
570 | *cur = array_nextsize (elem, *cur, cnt); |
618 | *cur = array_nextsize (elem, *cur, cnt); |
571 | return ev_realloc (base, elem * *cur); |
619 | return ev_realloc (base, elem * *cur); |
572 | } |
620 | } |
|
|
621 | |
|
|
622 | #define array_init_zero(base,count) \ |
|
|
623 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
573 | |
624 | |
574 | #define array_needsize(type,base,cur,cnt,init) \ |
625 | #define array_needsize(type,base,cur,cnt,init) \ |
575 | if (expect_false ((cnt) > (cur))) \ |
626 | if (expect_false ((cnt) > (cur))) \ |
576 | { \ |
627 | { \ |
577 | int ocur_ = (cur); \ |
628 | int ocur_ = (cur); \ |
… | |
… | |
621 | ev_feed_event (EV_A_ events [i], type); |
672 | ev_feed_event (EV_A_ events [i], type); |
622 | } |
673 | } |
623 | |
674 | |
624 | /*****************************************************************************/ |
675 | /*****************************************************************************/ |
625 | |
676 | |
626 | void inline_size |
|
|
627 | anfds_init (ANFD *base, int count) |
|
|
628 | { |
|
|
629 | while (count--) |
|
|
630 | { |
|
|
631 | base->head = 0; |
|
|
632 | base->events = EV_NONE; |
|
|
633 | base->reify = 0; |
|
|
634 | |
|
|
635 | ++base; |
|
|
636 | } |
|
|
637 | } |
|
|
638 | |
|
|
639 | void inline_speed |
677 | void inline_speed |
640 | fd_event (EV_P_ int fd, int revents) |
678 | fd_event (EV_P_ int fd, int revents) |
641 | { |
679 | { |
642 | ANFD *anfd = anfds + fd; |
680 | ANFD *anfd = anfds + fd; |
643 | ev_io *w; |
681 | ev_io *w; |
… | |
… | |
675 | events |= (unsigned char)w->events; |
713 | events |= (unsigned char)w->events; |
676 | |
714 | |
677 | #if EV_SELECT_IS_WINSOCKET |
715 | #if EV_SELECT_IS_WINSOCKET |
678 | if (events) |
716 | if (events) |
679 | { |
717 | { |
680 | unsigned long argp; |
718 | unsigned long arg; |
681 | #ifdef EV_FD_TO_WIN32_HANDLE |
719 | #ifdef EV_FD_TO_WIN32_HANDLE |
682 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
720 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
683 | #else |
721 | #else |
684 | anfd->handle = _get_osfhandle (fd); |
722 | anfd->handle = _get_osfhandle (fd); |
685 | #endif |
723 | #endif |
686 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &argp) == 0)); |
724 | assert (("libev only supports socket fds in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
687 | } |
725 | } |
688 | #endif |
726 | #endif |
689 | |
727 | |
690 | { |
728 | { |
691 | unsigned char o_events = anfd->events; |
729 | unsigned char o_events = anfd->events; |
… | |
… | |
744 | { |
782 | { |
745 | int fd; |
783 | int fd; |
746 | |
784 | |
747 | for (fd = 0; fd < anfdmax; ++fd) |
785 | for (fd = 0; fd < anfdmax; ++fd) |
748 | if (anfds [fd].events) |
786 | if (anfds [fd].events) |
749 | if (!fd_valid (fd) == -1 && errno == EBADF) |
787 | if (!fd_valid (fd) && errno == EBADF) |
750 | fd_kill (EV_A_ fd); |
788 | fd_kill (EV_A_ fd); |
751 | } |
789 | } |
752 | |
790 | |
753 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
791 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
754 | static void noinline |
792 | static void noinline |
… | |
… | |
772 | |
810 | |
773 | for (fd = 0; fd < anfdmax; ++fd) |
811 | for (fd = 0; fd < anfdmax; ++fd) |
774 | if (anfds [fd].events) |
812 | if (anfds [fd].events) |
775 | { |
813 | { |
776 | anfds [fd].events = 0; |
814 | anfds [fd].events = 0; |
|
|
815 | anfds [fd].emask = 0; |
777 | fd_change (EV_A_ fd, EV_IOFDSET | 1); |
816 | fd_change (EV_A_ fd, EV_IOFDSET | 1); |
778 | } |
817 | } |
779 | } |
818 | } |
780 | |
819 | |
781 | /*****************************************************************************/ |
820 | /*****************************************************************************/ |
… | |
… | |
790 | * at the moment we allow libev the luxury of two heaps, |
829 | * 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 |
830 | * a small-code-size 2-heap one and a ~1.5kb larger 4-heap |
792 | * which is more cache-efficient. |
831 | * which is more cache-efficient. |
793 | * the difference is about 5% with 50000+ watchers. |
832 | * the difference is about 5% with 50000+ watchers. |
794 | */ |
833 | */ |
795 | #define EV_USE_4HEAP !EV_MINIMAL |
|
|
796 | #if EV_USE_4HEAP |
834 | #if EV_USE_4HEAP |
797 | |
835 | |
798 | #define DHEAP 4 |
836 | #define DHEAP 4 |
799 | #define HEAP0 (DHEAP - 1) /* index of first element in heap */ |
837 | #define HEAP0 (DHEAP - 1) /* index of first element in heap */ |
800 | |
838 | #define HPARENT(k) ((((k) - HEAP0 - 1) / DHEAP) + HEAP0) |
801 | /* towards the root */ |
839 | #define UPHEAP_DONE(p,k) ((p) == (k)) |
802 | void inline_speed |
|
|
803 | upheap (ANHE *heap, int k) |
|
|
804 | { |
|
|
805 | ANHE he = heap [k]; |
|
|
806 | |
|
|
807 | for (;;) |
|
|
808 | { |
|
|
809 | int p = ((k - HEAP0 - 1) / DHEAP) + HEAP0; |
|
|
810 | |
|
|
811 | if (p == k || ANHE_at (heap [p]) <= ANHE_at (he)) |
|
|
812 | break; |
|
|
813 | |
|
|
814 | heap [k] = heap [p]; |
|
|
815 | ev_active (ANHE_w (heap [k])) = k; |
|
|
816 | k = p; |
|
|
817 | } |
|
|
818 | |
|
|
819 | ev_active (ANHE_w (he)) = k; |
|
|
820 | heap [k] = he; |
|
|
821 | } |
|
|
822 | |
840 | |
823 | /* away from the root */ |
841 | /* away from the root */ |
824 | void inline_speed |
842 | void inline_speed |
825 | downheap (ANHE *heap, int N, int k) |
843 | downheap (ANHE *heap, int N, int k) |
826 | { |
844 | { |
… | |
… | |
829 | |
847 | |
830 | for (;;) |
848 | for (;;) |
831 | { |
849 | { |
832 | ev_tstamp minat; |
850 | ev_tstamp minat; |
833 | ANHE *minpos; |
851 | ANHE *minpos; |
834 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0; |
852 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; |
835 | |
853 | |
836 | // find minimum child |
854 | /* find minimum child */ |
837 | if (expect_true (pos + DHEAP - 1 < E)) |
855 | if (expect_true (pos + DHEAP - 1 < E)) |
838 | { |
856 | { |
839 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
857 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
840 | if (ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
858 | 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)); |
859 | 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)); |
860 | if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
843 | } |
861 | } |
844 | else if (pos < E) |
862 | else if (pos < E) |
845 | { |
863 | { |
846 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
864 | /* 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)); |
865 | if (pos + 1 < E && ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
… | |
… | |
852 | break; |
870 | break; |
853 | |
871 | |
854 | if (ANHE_at (he) <= minat) |
872 | if (ANHE_at (he) <= minat) |
855 | break; |
873 | break; |
856 | |
874 | |
|
|
875 | heap [k] = *minpos; |
857 | ev_active (ANHE_w (*minpos)) = k; |
876 | ev_active (ANHE_w (*minpos)) = k; |
858 | heap [k] = *minpos; |
|
|
859 | |
877 | |
860 | k = minpos - heap; |
878 | k = minpos - heap; |
861 | } |
879 | } |
862 | |
880 | |
|
|
881 | heap [k] = he; |
863 | ev_active (ANHE_w (he)) = k; |
882 | ev_active (ANHE_w (he)) = k; |
864 | heap [k] = he; |
|
|
865 | } |
883 | } |
866 | |
884 | |
867 | #else // 4HEAP |
885 | #else /* 4HEAP */ |
868 | |
886 | |
869 | #define HEAP0 1 |
887 | #define HEAP0 1 |
870 | |
888 | #define HPARENT(k) ((k) >> 1) |
871 | /* towards the root */ |
889 | #define UPHEAP_DONE(p,k) (!(p)) |
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 | |
|
|
890 | heap [k] = w; |
|
|
891 | ev_active (ANHE_w (heap [k])) = k; |
|
|
892 | } |
|
|
893 | |
890 | |
894 | /* away from the root */ |
891 | /* away from the root */ |
895 | void inline_speed |
892 | void inline_speed |
896 | downheap (ANHE *heap, int N, int k) |
893 | downheap (ANHE *heap, int N, int k) |
897 | { |
894 | { |
… | |
… | |
899 | |
896 | |
900 | for (;;) |
897 | for (;;) |
901 | { |
898 | { |
902 | int c = k << 1; |
899 | int c = k << 1; |
903 | |
900 | |
904 | if (c > N) |
901 | if (c > N + HEAP0 - 1) |
905 | break; |
902 | break; |
906 | |
903 | |
907 | c += c + 1 < N && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
904 | c += c + 1 < N + HEAP0 && ANHE_at (heap [c]) > ANHE_at (heap [c + 1]) |
908 | ? 1 : 0; |
905 | ? 1 : 0; |
909 | |
906 | |
910 | if (w->at <= ANHE_at (heap [c])) |
907 | if (ANHE_at (he) <= ANHE_at (heap [c])) |
911 | break; |
908 | break; |
912 | |
909 | |
913 | heap [k] = heap [c]; |
910 | heap [k] = heap [c]; |
914 | ev_active (ANHE_w (heap [k])) = k; |
911 | ev_active (ANHE_w (heap [k])) = k; |
915 | |
912 | |
… | |
… | |
919 | heap [k] = he; |
916 | heap [k] = he; |
920 | ev_active (ANHE_w (he)) = k; |
917 | ev_active (ANHE_w (he)) = k; |
921 | } |
918 | } |
922 | #endif |
919 | #endif |
923 | |
920 | |
|
|
921 | /* towards the root */ |
|
|
922 | void inline_speed |
|
|
923 | upheap (ANHE *heap, int k) |
|
|
924 | { |
|
|
925 | ANHE he = heap [k]; |
|
|
926 | |
|
|
927 | for (;;) |
|
|
928 | { |
|
|
929 | int p = HPARENT (k); |
|
|
930 | |
|
|
931 | if (UPHEAP_DONE (p, k) || ANHE_at (heap [p]) <= ANHE_at (he)) |
|
|
932 | break; |
|
|
933 | |
|
|
934 | heap [k] = heap [p]; |
|
|
935 | ev_active (ANHE_w (heap [k])) = k; |
|
|
936 | k = p; |
|
|
937 | } |
|
|
938 | |
|
|
939 | heap [k] = he; |
|
|
940 | ev_active (ANHE_w (he)) = k; |
|
|
941 | } |
|
|
942 | |
924 | void inline_size |
943 | void inline_size |
925 | adjustheap (ANHE *heap, int N, int k) |
944 | adjustheap (ANHE *heap, int N, int k) |
926 | { |
945 | { |
|
|
946 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
927 | upheap (heap, k); |
947 | upheap (heap, k); |
|
|
948 | else |
928 | downheap (heap, N, k); |
949 | downheap (heap, N, k); |
|
|
950 | } |
|
|
951 | |
|
|
952 | /* rebuild the heap: this function is used only once and executed rarely */ |
|
|
953 | void inline_size |
|
|
954 | reheap (ANHE *heap, int N) |
|
|
955 | { |
|
|
956 | int i; |
|
|
957 | |
|
|
958 | /* we don't use floyds algorithm, upheap is simpler and is more cache-efficient */ |
|
|
959 | /* also, this is easy to implement and correct for both 2-heaps and 4-heaps */ |
|
|
960 | for (i = 0; i < N; ++i) |
|
|
961 | upheap (heap, i + HEAP0); |
929 | } |
962 | } |
930 | |
963 | |
931 | /*****************************************************************************/ |
964 | /*****************************************************************************/ |
932 | |
965 | |
933 | typedef struct |
966 | typedef struct |
… | |
… | |
939 | static ANSIG *signals; |
972 | static ANSIG *signals; |
940 | static int signalmax; |
973 | static int signalmax; |
941 | |
974 | |
942 | static EV_ATOMIC_T gotsig; |
975 | static EV_ATOMIC_T gotsig; |
943 | |
976 | |
944 | void inline_size |
|
|
945 | signals_init (ANSIG *base, int count) |
|
|
946 | { |
|
|
947 | while (count--) |
|
|
948 | { |
|
|
949 | base->head = 0; |
|
|
950 | base->gotsig = 0; |
|
|
951 | |
|
|
952 | ++base; |
|
|
953 | } |
|
|
954 | } |
|
|
955 | |
|
|
956 | /*****************************************************************************/ |
977 | /*****************************************************************************/ |
957 | |
978 | |
958 | void inline_speed |
979 | void inline_speed |
959 | fd_intern (int fd) |
980 | fd_intern (int fd) |
960 | { |
981 | { |
961 | #ifdef _WIN32 |
982 | #ifdef _WIN32 |
962 | int arg = 1; |
983 | unsigned long arg = 1; |
963 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
984 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
964 | #else |
985 | #else |
965 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
986 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
966 | fcntl (fd, F_SETFL, O_NONBLOCK); |
987 | fcntl (fd, F_SETFL, O_NONBLOCK); |
967 | #endif |
988 | #endif |
… | |
… | |
981 | } |
1002 | } |
982 | else |
1003 | else |
983 | #endif |
1004 | #endif |
984 | { |
1005 | { |
985 | while (pipe (evpipe)) |
1006 | while (pipe (evpipe)) |
986 | syserr ("(libev) error creating signal/async pipe"); |
1007 | ev_syserr ("(libev) error creating signal/async pipe"); |
987 | |
1008 | |
988 | fd_intern (evpipe [0]); |
1009 | fd_intern (evpipe [0]); |
989 | fd_intern (evpipe [1]); |
1010 | fd_intern (evpipe [1]); |
990 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
1011 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
991 | } |
1012 | } |
… | |
… | |
1451 | |
1472 | |
1452 | postfork = 0; |
1473 | postfork = 0; |
1453 | } |
1474 | } |
1454 | |
1475 | |
1455 | #if EV_MULTIPLICITY |
1476 | #if EV_MULTIPLICITY |
|
|
1477 | |
1456 | struct ev_loop * |
1478 | struct ev_loop * |
1457 | ev_loop_new (unsigned int flags) |
1479 | ev_loop_new (unsigned int flags) |
1458 | { |
1480 | { |
1459 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1481 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
1460 | |
1482 | |
… | |
… | |
1478 | void |
1500 | void |
1479 | ev_loop_fork (EV_P) |
1501 | ev_loop_fork (EV_P) |
1480 | { |
1502 | { |
1481 | postfork = 1; /* must be in line with ev_default_fork */ |
1503 | postfork = 1; /* must be in line with ev_default_fork */ |
1482 | } |
1504 | } |
|
|
1505 | |
|
|
1506 | #if EV_VERIFY |
|
|
1507 | static void noinline |
|
|
1508 | verify_watcher (EV_P_ W w) |
|
|
1509 | { |
|
|
1510 | assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
|
|
1511 | |
|
|
1512 | if (w->pending) |
|
|
1513 | assert (("pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
|
|
1514 | } |
|
|
1515 | |
|
|
1516 | static void noinline |
|
|
1517 | verify_heap (EV_P_ ANHE *heap, int N) |
|
|
1518 | { |
|
|
1519 | int i; |
|
|
1520 | |
|
|
1521 | for (i = HEAP0; i < N + HEAP0; ++i) |
|
|
1522 | { |
|
|
1523 | assert (("active index mismatch in heap", ev_active (ANHE_w (heap [i])) == i)); |
|
|
1524 | assert (("heap condition violated", i == HEAP0 || ANHE_at (heap [HPARENT (i)]) <= ANHE_at (heap [i]))); |
|
|
1525 | assert (("heap at cache mismatch", ANHE_at (heap [i]) == ev_at (ANHE_w (heap [i])))); |
|
|
1526 | |
|
|
1527 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
|
|
1528 | } |
|
|
1529 | } |
|
|
1530 | |
|
|
1531 | static void noinline |
|
|
1532 | array_verify (EV_P_ W *ws, int cnt) |
|
|
1533 | { |
|
|
1534 | while (cnt--) |
|
|
1535 | { |
|
|
1536 | assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
|
|
1537 | verify_watcher (EV_A_ ws [cnt]); |
|
|
1538 | } |
|
|
1539 | } |
|
|
1540 | #endif |
|
|
1541 | |
|
|
1542 | void |
|
|
1543 | ev_loop_verify (EV_P) |
|
|
1544 | { |
|
|
1545 | #if EV_VERIFY |
|
|
1546 | int i; |
|
|
1547 | WL w; |
|
|
1548 | |
|
|
1549 | assert (activecnt >= -1); |
|
|
1550 | |
|
|
1551 | assert (fdchangemax >= fdchangecnt); |
|
|
1552 | for (i = 0; i < fdchangecnt; ++i) |
|
|
1553 | assert (("negative fd in fdchanges", fdchanges [i] >= 0)); |
|
|
1554 | |
|
|
1555 | assert (anfdmax >= 0); |
|
|
1556 | for (i = 0; i < anfdmax; ++i) |
|
|
1557 | for (w = anfds [i].head; w; w = w->next) |
|
|
1558 | { |
|
|
1559 | verify_watcher (EV_A_ (W)w); |
|
|
1560 | assert (("inactive fd watcher on anfd list", ev_active (w) == 1)); |
|
|
1561 | assert (("fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
|
|
1562 | } |
|
|
1563 | |
|
|
1564 | assert (timermax >= timercnt); |
|
|
1565 | verify_heap (EV_A_ timers, timercnt); |
|
|
1566 | |
|
|
1567 | #if EV_PERIODIC_ENABLE |
|
|
1568 | assert (periodicmax >= periodiccnt); |
|
|
1569 | verify_heap (EV_A_ periodics, periodiccnt); |
|
|
1570 | #endif |
|
|
1571 | |
|
|
1572 | for (i = NUMPRI; i--; ) |
|
|
1573 | { |
|
|
1574 | assert (pendingmax [i] >= pendingcnt [i]); |
|
|
1575 | #if EV_IDLE_ENABLE |
|
|
1576 | assert (idleall >= 0); |
|
|
1577 | assert (idlemax [i] >= idlecnt [i]); |
|
|
1578 | array_verify (EV_A_ (W *)idles [i], idlecnt [i]); |
|
|
1579 | #endif |
|
|
1580 | } |
|
|
1581 | |
|
|
1582 | #if EV_FORK_ENABLE |
|
|
1583 | assert (forkmax >= forkcnt); |
|
|
1584 | array_verify (EV_A_ (W *)forks, forkcnt); |
|
|
1585 | #endif |
|
|
1586 | |
|
|
1587 | #if EV_ASYNC_ENABLE |
|
|
1588 | assert (asyncmax >= asynccnt); |
|
|
1589 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
|
|
1590 | #endif |
|
|
1591 | |
|
|
1592 | assert (preparemax >= preparecnt); |
|
|
1593 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1594 | |
|
|
1595 | assert (checkmax >= checkcnt); |
|
|
1596 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1597 | |
|
|
1598 | # if 0 |
|
|
1599 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
|
|
1600 | for (signum = signalmax; signum--; ) if (signals [signum].gotsig) |
1483 | #endif |
1601 | # endif |
|
|
1602 | #endif |
|
|
1603 | } |
|
|
1604 | |
|
|
1605 | #endif /* multiplicity */ |
1484 | |
1606 | |
1485 | #if EV_MULTIPLICITY |
1607 | #if EV_MULTIPLICITY |
1486 | struct ev_loop * |
1608 | struct ev_loop * |
1487 | ev_default_loop_init (unsigned int flags) |
1609 | ev_default_loop_init (unsigned int flags) |
1488 | #else |
1610 | #else |
… | |
… | |
1521 | { |
1643 | { |
1522 | #if EV_MULTIPLICITY |
1644 | #if EV_MULTIPLICITY |
1523 | struct ev_loop *loop = ev_default_loop_ptr; |
1645 | struct ev_loop *loop = ev_default_loop_ptr; |
1524 | #endif |
1646 | #endif |
1525 | |
1647 | |
|
|
1648 | ev_default_loop_ptr = 0; |
|
|
1649 | |
1526 | #ifndef _WIN32 |
1650 | #ifndef _WIN32 |
1527 | ev_ref (EV_A); /* child watcher */ |
1651 | ev_ref (EV_A); /* child watcher */ |
1528 | ev_signal_stop (EV_A_ &childev); |
1652 | ev_signal_stop (EV_A_ &childev); |
1529 | #endif |
1653 | #endif |
1530 | |
1654 | |
… | |
… | |
1536 | { |
1660 | { |
1537 | #if EV_MULTIPLICITY |
1661 | #if EV_MULTIPLICITY |
1538 | struct ev_loop *loop = ev_default_loop_ptr; |
1662 | struct ev_loop *loop = ev_default_loop_ptr; |
1539 | #endif |
1663 | #endif |
1540 | |
1664 | |
1541 | if (backend) |
|
|
1542 | postfork = 1; /* must be in line with ev_loop_fork */ |
1665 | postfork = 1; /* must be in line with ev_loop_fork */ |
1543 | } |
1666 | } |
1544 | |
1667 | |
1545 | /*****************************************************************************/ |
1668 | /*****************************************************************************/ |
1546 | |
1669 | |
1547 | void |
1670 | void |
… | |
… | |
1564 | { |
1687 | { |
1565 | /*assert (("non-pending watcher on pending list", p->w->pending));*/ |
1688 | /*assert (("non-pending watcher on pending list", p->w->pending));*/ |
1566 | |
1689 | |
1567 | p->w->pending = 0; |
1690 | p->w->pending = 0; |
1568 | EV_CB_INVOKE (p->w, p->events); |
1691 | EV_CB_INVOKE (p->w, p->events); |
|
|
1692 | EV_FREQUENT_CHECK; |
1569 | } |
1693 | } |
1570 | } |
1694 | } |
1571 | } |
1695 | } |
1572 | |
1696 | |
1573 | #if EV_IDLE_ENABLE |
1697 | #if EV_IDLE_ENABLE |
… | |
… | |
1594 | #endif |
1718 | #endif |
1595 | |
1719 | |
1596 | void inline_size |
1720 | void inline_size |
1597 | timers_reify (EV_P) |
1721 | timers_reify (EV_P) |
1598 | { |
1722 | { |
|
|
1723 | EV_FREQUENT_CHECK; |
|
|
1724 | |
1599 | while (timercnt && ANHE_at (timers [HEAP0]) <= mn_now) |
1725 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now) |
1600 | { |
1726 | { |
1601 | ev_timer *w = (ev_timer *)ANHE_w (timers [HEAP0]); |
1727 | ev_timer *w = (ev_timer *)ANHE_w (timers [HEAP0]); |
1602 | |
1728 | |
1603 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1729 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1604 | |
1730 | |
1605 | /* first reschedule or stop timer */ |
1731 | /* first reschedule or stop timer */ |
1606 | if (w->repeat) |
1732 | if (w->repeat) |
1607 | { |
1733 | { |
1608 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
|
|
1609 | |
|
|
1610 | ev_at (w) += w->repeat; |
1734 | ev_at (w) += w->repeat; |
1611 | if (ev_at (w) < mn_now) |
1735 | if (ev_at (w) < mn_now) |
1612 | ev_at (w) = mn_now; |
1736 | ev_at (w) = mn_now; |
1613 | |
1737 | |
|
|
1738 | assert (("negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
|
|
1739 | |
|
|
1740 | ANHE_at_cache (timers [HEAP0]); |
1614 | downheap (timers, timercnt, HEAP0); |
1741 | downheap (timers, timercnt, HEAP0); |
1615 | } |
1742 | } |
1616 | else |
1743 | else |
1617 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1744 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1618 | |
1745 | |
|
|
1746 | EV_FREQUENT_CHECK; |
1619 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1747 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1620 | } |
1748 | } |
1621 | } |
1749 | } |
1622 | |
1750 | |
1623 | #if EV_PERIODIC_ENABLE |
1751 | #if EV_PERIODIC_ENABLE |
1624 | void inline_size |
1752 | void inline_size |
1625 | periodics_reify (EV_P) |
1753 | periodics_reify (EV_P) |
1626 | { |
1754 | { |
|
|
1755 | EV_FREQUENT_CHECK; |
|
|
1756 | |
1627 | while (periodiccnt && ANHE_at (periodics [HEAP0]) <= ev_rt_now) |
1757 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
1628 | { |
1758 | { |
1629 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
1759 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
1630 | |
1760 | |
1631 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1761 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1632 | |
1762 | |
1633 | /* first reschedule or stop timer */ |
1763 | /* first reschedule or stop timer */ |
1634 | if (w->reschedule_cb) |
1764 | if (w->reschedule_cb) |
1635 | { |
1765 | { |
1636 | ev_at (w) = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
1766 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
|
|
1767 | |
1637 | assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) > ev_rt_now)); |
1768 | assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now)); |
|
|
1769 | |
|
|
1770 | ANHE_at_cache (periodics [HEAP0]); |
1638 | downheap (periodics, periodiccnt, 1); |
1771 | downheap (periodics, periodiccnt, HEAP0); |
1639 | } |
1772 | } |
1640 | else if (w->interval) |
1773 | else if (w->interval) |
1641 | { |
1774 | { |
1642 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1775 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
|
|
1776 | /* if next trigger time is not sufficiently in the future, put it there */ |
|
|
1777 | /* this might happen because of floating point inexactness */ |
1643 | if (ev_at (w) - ev_rt_now <= TIME_EPSILON) ev_at (w) += w->interval; |
1778 | if (ev_at (w) - ev_rt_now < TIME_EPSILON) |
1644 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ev_at (w) > ev_rt_now)); |
1779 | { |
|
|
1780 | ev_at (w) += w->interval; |
|
|
1781 | |
|
|
1782 | /* if interval is unreasonably low we might still have a time in the past */ |
|
|
1783 | /* so correct this. this will make the periodic very inexact, but the user */ |
|
|
1784 | /* has effectively asked to get triggered more often than possible */ |
|
|
1785 | if (ev_at (w) < ev_rt_now) |
|
|
1786 | ev_at (w) = ev_rt_now; |
|
|
1787 | } |
|
|
1788 | |
|
|
1789 | ANHE_at_cache (periodics [HEAP0]); |
1645 | downheap (periodics, periodiccnt, HEAP0); |
1790 | downheap (periodics, periodiccnt, HEAP0); |
1646 | } |
1791 | } |
1647 | else |
1792 | else |
1648 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1793 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1649 | |
1794 | |
|
|
1795 | EV_FREQUENT_CHECK; |
1650 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
1796 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
1651 | } |
1797 | } |
1652 | } |
1798 | } |
1653 | |
1799 | |
1654 | static void noinline |
1800 | static void noinline |
… | |
… | |
1663 | |
1809 | |
1664 | if (w->reschedule_cb) |
1810 | if (w->reschedule_cb) |
1665 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1811 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
1666 | else if (w->interval) |
1812 | else if (w->interval) |
1667 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1813 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1668 | } |
|
|
1669 | |
1814 | |
1670 | /* now rebuild the heap, this for the 2-heap, inefficient for the 4-heap, but correct */ |
1815 | ANHE_at_cache (periodics [i]); |
1671 | for (i = periodiccnt >> 1; --i; ) |
1816 | } |
|
|
1817 | |
1672 | downheap (periodics, periodiccnt, i + HEAP0); |
1818 | reheap (periodics, periodiccnt); |
1673 | } |
1819 | } |
1674 | #endif |
1820 | #endif |
1675 | |
1821 | |
1676 | void inline_speed |
1822 | void inline_speed |
1677 | time_update (EV_P_ ev_tstamp max_block) |
1823 | time_update (EV_P_ ev_tstamp max_block) |
… | |
… | |
1735 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1881 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
1736 | for (i = 0; i < timercnt; ++i) |
1882 | for (i = 0; i < timercnt; ++i) |
1737 | { |
1883 | { |
1738 | ANHE *he = timers + i + HEAP0; |
1884 | ANHE *he = timers + i + HEAP0; |
1739 | ANHE_w (*he)->at += ev_rt_now - mn_now; |
1885 | ANHE_w (*he)->at += ev_rt_now - mn_now; |
1740 | ANHE_at_set (*he); |
1886 | ANHE_at_cache (*he); |
1741 | } |
1887 | } |
1742 | } |
1888 | } |
1743 | |
1889 | |
1744 | mn_now = ev_rt_now; |
1890 | mn_now = ev_rt_now; |
1745 | } |
1891 | } |
… | |
… | |
1755 | ev_unref (EV_P) |
1901 | ev_unref (EV_P) |
1756 | { |
1902 | { |
1757 | --activecnt; |
1903 | --activecnt; |
1758 | } |
1904 | } |
1759 | |
1905 | |
|
|
1906 | void |
|
|
1907 | ev_now_update (EV_P) |
|
|
1908 | { |
|
|
1909 | time_update (EV_A_ 1e100); |
|
|
1910 | } |
|
|
1911 | |
1760 | static int loop_done; |
1912 | static int loop_done; |
1761 | |
1913 | |
1762 | void |
1914 | void |
1763 | ev_loop (EV_P_ int flags) |
1915 | ev_loop (EV_P_ int flags) |
1764 | { |
1916 | { |
… | |
… | |
1766 | |
1918 | |
1767 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1919 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1768 | |
1920 | |
1769 | do |
1921 | do |
1770 | { |
1922 | { |
|
|
1923 | #if EV_VERIFY >= 2 |
|
|
1924 | ev_loop_verify (EV_A); |
|
|
1925 | #endif |
|
|
1926 | |
1771 | #ifndef _WIN32 |
1927 | #ifndef _WIN32 |
1772 | if (expect_false (curpid)) /* penalise the forking check even more */ |
1928 | if (expect_false (curpid)) /* penalise the forking check even more */ |
1773 | if (expect_false (getpid () != curpid)) |
1929 | if (expect_false (getpid () != curpid)) |
1774 | { |
1930 | { |
1775 | curpid = getpid (); |
1931 | curpid = getpid (); |
… | |
… | |
1969 | |
2125 | |
1970 | if (expect_false (ev_is_active (w))) |
2126 | if (expect_false (ev_is_active (w))) |
1971 | return; |
2127 | return; |
1972 | |
2128 | |
1973 | assert (("ev_io_start called with negative fd", fd >= 0)); |
2129 | assert (("ev_io_start called with negative fd", fd >= 0)); |
|
|
2130 | assert (("ev_io start called with illegal event mask", !(w->events & ~(EV_IOFDSET | EV_READ | EV_WRITE)))); |
|
|
2131 | |
|
|
2132 | EV_FREQUENT_CHECK; |
1974 | |
2133 | |
1975 | ev_start (EV_A_ (W)w, 1); |
2134 | ev_start (EV_A_ (W)w, 1); |
1976 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
2135 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
1977 | wlist_add (&anfds[fd].head, (WL)w); |
2136 | wlist_add (&anfds[fd].head, (WL)w); |
1978 | |
2137 | |
1979 | fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); |
2138 | fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); |
1980 | w->events &= ~EV_IOFDSET; |
2139 | w->events &= ~EV_IOFDSET; |
|
|
2140 | |
|
|
2141 | EV_FREQUENT_CHECK; |
1981 | } |
2142 | } |
1982 | |
2143 | |
1983 | void noinline |
2144 | void noinline |
1984 | ev_io_stop (EV_P_ ev_io *w) |
2145 | ev_io_stop (EV_P_ ev_io *w) |
1985 | { |
2146 | { |
1986 | clear_pending (EV_A_ (W)w); |
2147 | clear_pending (EV_A_ (W)w); |
1987 | if (expect_false (!ev_is_active (w))) |
2148 | if (expect_false (!ev_is_active (w))) |
1988 | return; |
2149 | return; |
1989 | |
2150 | |
1990 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
2151 | assert (("ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
|
|
2152 | |
|
|
2153 | EV_FREQUENT_CHECK; |
1991 | |
2154 | |
1992 | wlist_del (&anfds[w->fd].head, (WL)w); |
2155 | wlist_del (&anfds[w->fd].head, (WL)w); |
1993 | ev_stop (EV_A_ (W)w); |
2156 | ev_stop (EV_A_ (W)w); |
1994 | |
2157 | |
1995 | fd_change (EV_A_ w->fd, 1); |
2158 | fd_change (EV_A_ w->fd, 1); |
|
|
2159 | |
|
|
2160 | EV_FREQUENT_CHECK; |
1996 | } |
2161 | } |
1997 | |
2162 | |
1998 | void noinline |
2163 | void noinline |
1999 | ev_timer_start (EV_P_ ev_timer *w) |
2164 | ev_timer_start (EV_P_ ev_timer *w) |
2000 | { |
2165 | { |
… | |
… | |
2003 | |
2168 | |
2004 | ev_at (w) += mn_now; |
2169 | ev_at (w) += mn_now; |
2005 | |
2170 | |
2006 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
2171 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
2007 | |
2172 | |
|
|
2173 | EV_FREQUENT_CHECK; |
|
|
2174 | |
|
|
2175 | ++timercnt; |
2008 | ev_start (EV_A_ (W)w, ++timercnt + HEAP0 - 1); |
2176 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
2009 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
2177 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
2010 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
2178 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
2011 | ANHE_at_set (timers [ev_active (w)]); |
2179 | ANHE_at_cache (timers [ev_active (w)]); |
2012 | upheap (timers, ev_active (w)); |
2180 | upheap (timers, ev_active (w)); |
2013 | |
2181 | |
|
|
2182 | EV_FREQUENT_CHECK; |
|
|
2183 | |
2014 | /*assert (("internal timer heap corruption", timers [ev_active (w)] == w));*/ |
2184 | /*assert (("internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
2015 | } |
2185 | } |
2016 | |
2186 | |
2017 | void noinline |
2187 | void noinline |
2018 | ev_timer_stop (EV_P_ ev_timer *w) |
2188 | ev_timer_stop (EV_P_ ev_timer *w) |
2019 | { |
2189 | { |
2020 | clear_pending (EV_A_ (W)w); |
2190 | clear_pending (EV_A_ (W)w); |
2021 | if (expect_false (!ev_is_active (w))) |
2191 | if (expect_false (!ev_is_active (w))) |
2022 | return; |
2192 | return; |
2023 | |
2193 | |
|
|
2194 | EV_FREQUENT_CHECK; |
|
|
2195 | |
2024 | { |
2196 | { |
2025 | int active = ev_active (w); |
2197 | int active = ev_active (w); |
2026 | |
2198 | |
2027 | assert (("internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
2199 | assert (("internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
2028 | |
2200 | |
|
|
2201 | --timercnt; |
|
|
2202 | |
2029 | if (expect_true (active < timercnt + HEAP0 - 1)) |
2203 | if (expect_true (active < timercnt + HEAP0)) |
2030 | { |
2204 | { |
2031 | timers [active] = timers [timercnt + HEAP0 - 1]; |
2205 | timers [active] = timers [timercnt + HEAP0]; |
2032 | adjustheap (timers, timercnt, active); |
2206 | adjustheap (timers, timercnt, active); |
2033 | } |
2207 | } |
2034 | |
|
|
2035 | --timercnt; |
|
|
2036 | } |
2208 | } |
|
|
2209 | |
|
|
2210 | EV_FREQUENT_CHECK; |
2037 | |
2211 | |
2038 | ev_at (w) -= mn_now; |
2212 | ev_at (w) -= mn_now; |
2039 | |
2213 | |
2040 | ev_stop (EV_A_ (W)w); |
2214 | ev_stop (EV_A_ (W)w); |
2041 | } |
2215 | } |
2042 | |
2216 | |
2043 | void noinline |
2217 | void noinline |
2044 | ev_timer_again (EV_P_ ev_timer *w) |
2218 | ev_timer_again (EV_P_ ev_timer *w) |
2045 | { |
2219 | { |
|
|
2220 | EV_FREQUENT_CHECK; |
|
|
2221 | |
2046 | if (ev_is_active (w)) |
2222 | if (ev_is_active (w)) |
2047 | { |
2223 | { |
2048 | if (w->repeat) |
2224 | if (w->repeat) |
2049 | { |
2225 | { |
2050 | ev_at (w) = mn_now + w->repeat; |
2226 | ev_at (w) = mn_now + w->repeat; |
2051 | ANHE_at_set (timers [ev_active (w)]); |
2227 | ANHE_at_cache (timers [ev_active (w)]); |
2052 | adjustheap (timers, timercnt, ev_active (w)); |
2228 | adjustheap (timers, timercnt, ev_active (w)); |
2053 | } |
2229 | } |
2054 | else |
2230 | else |
2055 | ev_timer_stop (EV_A_ w); |
2231 | ev_timer_stop (EV_A_ w); |
2056 | } |
2232 | } |
2057 | else if (w->repeat) |
2233 | else if (w->repeat) |
2058 | { |
2234 | { |
2059 | ev_at (w) = w->repeat; |
2235 | ev_at (w) = w->repeat; |
2060 | ev_timer_start (EV_A_ w); |
2236 | ev_timer_start (EV_A_ w); |
2061 | } |
2237 | } |
|
|
2238 | |
|
|
2239 | EV_FREQUENT_CHECK; |
2062 | } |
2240 | } |
2063 | |
2241 | |
2064 | #if EV_PERIODIC_ENABLE |
2242 | #if EV_PERIODIC_ENABLE |
2065 | void noinline |
2243 | void noinline |
2066 | ev_periodic_start (EV_P_ ev_periodic *w) |
2244 | ev_periodic_start (EV_P_ ev_periodic *w) |
… | |
… | |
2077 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2255 | ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
2078 | } |
2256 | } |
2079 | else |
2257 | else |
2080 | ev_at (w) = w->offset; |
2258 | ev_at (w) = w->offset; |
2081 | |
2259 | |
|
|
2260 | EV_FREQUENT_CHECK; |
|
|
2261 | |
|
|
2262 | ++periodiccnt; |
2082 | ev_start (EV_A_ (W)w, ++periodiccnt + HEAP0 - 1); |
2263 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
2083 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
2264 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
2084 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
2265 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
|
|
2266 | ANHE_at_cache (periodics [ev_active (w)]); |
2085 | upheap (periodics, ev_active (w)); |
2267 | upheap (periodics, ev_active (w)); |
|
|
2268 | |
|
|
2269 | EV_FREQUENT_CHECK; |
2086 | |
2270 | |
2087 | /*assert (("internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
2271 | /*assert (("internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
2088 | } |
2272 | } |
2089 | |
2273 | |
2090 | void noinline |
2274 | void noinline |
… | |
… | |
2092 | { |
2276 | { |
2093 | clear_pending (EV_A_ (W)w); |
2277 | clear_pending (EV_A_ (W)w); |
2094 | if (expect_false (!ev_is_active (w))) |
2278 | if (expect_false (!ev_is_active (w))) |
2095 | return; |
2279 | return; |
2096 | |
2280 | |
|
|
2281 | EV_FREQUENT_CHECK; |
|
|
2282 | |
2097 | { |
2283 | { |
2098 | int active = ev_active (w); |
2284 | int active = ev_active (w); |
2099 | |
2285 | |
2100 | assert (("internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
2286 | assert (("internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
2101 | |
2287 | |
|
|
2288 | --periodiccnt; |
|
|
2289 | |
2102 | if (expect_true (active < periodiccnt + HEAP0 - 1)) |
2290 | if (expect_true (active < periodiccnt + HEAP0)) |
2103 | { |
2291 | { |
2104 | periodics [active] = periodics [periodiccnt + HEAP0 - 1]; |
2292 | periodics [active] = periodics [periodiccnt + HEAP0]; |
2105 | adjustheap (periodics, periodiccnt, active); |
2293 | adjustheap (periodics, periodiccnt, active); |
2106 | } |
2294 | } |
2107 | |
|
|
2108 | --periodiccnt; |
|
|
2109 | } |
2295 | } |
|
|
2296 | |
|
|
2297 | EV_FREQUENT_CHECK; |
2110 | |
2298 | |
2111 | ev_stop (EV_A_ (W)w); |
2299 | ev_stop (EV_A_ (W)w); |
2112 | } |
2300 | } |
2113 | |
2301 | |
2114 | void noinline |
2302 | void noinline |
… | |
… | |
2134 | return; |
2322 | return; |
2135 | |
2323 | |
2136 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
2324 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
2137 | |
2325 | |
2138 | evpipe_init (EV_A); |
2326 | evpipe_init (EV_A); |
|
|
2327 | |
|
|
2328 | EV_FREQUENT_CHECK; |
2139 | |
2329 | |
2140 | { |
2330 | { |
2141 | #ifndef _WIN32 |
2331 | #ifndef _WIN32 |
2142 | sigset_t full, prev; |
2332 | sigset_t full, prev; |
2143 | sigfillset (&full); |
2333 | sigfillset (&full); |
2144 | sigprocmask (SIG_SETMASK, &full, &prev); |
2334 | sigprocmask (SIG_SETMASK, &full, &prev); |
2145 | #endif |
2335 | #endif |
2146 | |
2336 | |
2147 | array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); |
2337 | array_needsize (ANSIG, signals, signalmax, w->signum, array_init_zero); |
2148 | |
2338 | |
2149 | #ifndef _WIN32 |
2339 | #ifndef _WIN32 |
2150 | sigprocmask (SIG_SETMASK, &prev, 0); |
2340 | sigprocmask (SIG_SETMASK, &prev, 0); |
2151 | #endif |
2341 | #endif |
2152 | } |
2342 | } |
… | |
… | |
2164 | sigfillset (&sa.sa_mask); |
2354 | sigfillset (&sa.sa_mask); |
2165 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2355 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2166 | sigaction (w->signum, &sa, 0); |
2356 | sigaction (w->signum, &sa, 0); |
2167 | #endif |
2357 | #endif |
2168 | } |
2358 | } |
|
|
2359 | |
|
|
2360 | EV_FREQUENT_CHECK; |
2169 | } |
2361 | } |
2170 | |
2362 | |
2171 | void noinline |
2363 | void noinline |
2172 | ev_signal_stop (EV_P_ ev_signal *w) |
2364 | ev_signal_stop (EV_P_ ev_signal *w) |
2173 | { |
2365 | { |
2174 | clear_pending (EV_A_ (W)w); |
2366 | clear_pending (EV_A_ (W)w); |
2175 | if (expect_false (!ev_is_active (w))) |
2367 | if (expect_false (!ev_is_active (w))) |
2176 | return; |
2368 | return; |
2177 | |
2369 | |
|
|
2370 | EV_FREQUENT_CHECK; |
|
|
2371 | |
2178 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2372 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
2179 | ev_stop (EV_A_ (W)w); |
2373 | ev_stop (EV_A_ (W)w); |
2180 | |
2374 | |
2181 | if (!signals [w->signum - 1].head) |
2375 | if (!signals [w->signum - 1].head) |
2182 | signal (w->signum, SIG_DFL); |
2376 | signal (w->signum, SIG_DFL); |
|
|
2377 | |
|
|
2378 | EV_FREQUENT_CHECK; |
2183 | } |
2379 | } |
2184 | |
2380 | |
2185 | void |
2381 | void |
2186 | ev_child_start (EV_P_ ev_child *w) |
2382 | ev_child_start (EV_P_ ev_child *w) |
2187 | { |
2383 | { |
… | |
… | |
2189 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2385 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2190 | #endif |
2386 | #endif |
2191 | if (expect_false (ev_is_active (w))) |
2387 | if (expect_false (ev_is_active (w))) |
2192 | return; |
2388 | return; |
2193 | |
2389 | |
|
|
2390 | EV_FREQUENT_CHECK; |
|
|
2391 | |
2194 | ev_start (EV_A_ (W)w, 1); |
2392 | ev_start (EV_A_ (W)w, 1); |
2195 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2393 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
|
|
2394 | |
|
|
2395 | EV_FREQUENT_CHECK; |
2196 | } |
2396 | } |
2197 | |
2397 | |
2198 | void |
2398 | void |
2199 | ev_child_stop (EV_P_ ev_child *w) |
2399 | ev_child_stop (EV_P_ ev_child *w) |
2200 | { |
2400 | { |
2201 | clear_pending (EV_A_ (W)w); |
2401 | clear_pending (EV_A_ (W)w); |
2202 | if (expect_false (!ev_is_active (w))) |
2402 | if (expect_false (!ev_is_active (w))) |
2203 | return; |
2403 | return; |
2204 | |
2404 | |
|
|
2405 | EV_FREQUENT_CHECK; |
|
|
2406 | |
2205 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2407 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2206 | ev_stop (EV_A_ (W)w); |
2408 | ev_stop (EV_A_ (W)w); |
|
|
2409 | |
|
|
2410 | EV_FREQUENT_CHECK; |
2207 | } |
2411 | } |
2208 | |
2412 | |
2209 | #if EV_STAT_ENABLE |
2413 | #if EV_STAT_ENABLE |
2210 | |
2414 | |
2211 | # ifdef _WIN32 |
2415 | # ifdef _WIN32 |
2212 | # undef lstat |
2416 | # undef lstat |
2213 | # define lstat(a,b) _stati64 (a,b) |
2417 | # define lstat(a,b) _stati64 (a,b) |
2214 | # endif |
2418 | # endif |
2215 | |
2419 | |
2216 | #define DEF_STAT_INTERVAL 5.0074891 |
2420 | #define DEF_STAT_INTERVAL 5.0074891 |
|
|
2421 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
2217 | #define MIN_STAT_INTERVAL 0.1074891 |
2422 | #define MIN_STAT_INTERVAL 0.1074891 |
2218 | |
2423 | |
2219 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
2424 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
2220 | |
2425 | |
2221 | #if EV_USE_INOTIFY |
2426 | #if EV_USE_INOTIFY |
2222 | # define EV_INOTIFY_BUFSIZE 8192 |
2427 | # define EV_INOTIFY_BUFSIZE 8192 |
… | |
… | |
2226 | { |
2431 | { |
2227 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
2432 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
2228 | |
2433 | |
2229 | if (w->wd < 0) |
2434 | if (w->wd < 0) |
2230 | { |
2435 | { |
|
|
2436 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
2231 | ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
2437 | ev_timer_again (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
2232 | |
2438 | |
2233 | /* monitor some parent directory for speedup hints */ |
2439 | /* monitor some parent directory for speedup hints */ |
2234 | /* note that exceeding the hardcoded limit is not a correctness issue, */ |
2440 | /* note that exceeding the hardcoded path limit is not a correctness issue, */ |
2235 | /* but an efficiency issue only */ |
2441 | /* but an efficiency issue only */ |
2236 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2442 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2237 | { |
2443 | { |
2238 | char path [4096]; |
2444 | char path [4096]; |
2239 | strcpy (path, w->path); |
2445 | strcpy (path, w->path); |
… | |
… | |
2253 | } |
2459 | } |
2254 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2460 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2255 | } |
2461 | } |
2256 | } |
2462 | } |
2257 | else |
2463 | else |
2258 | ev_timer_stop (EV_A_ &w->timer); /* we can watch this in a race-free way */ |
2464 | { |
2259 | |
|
|
2260 | if (w->wd >= 0) |
|
|
2261 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2465 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
|
|
2466 | |
|
|
2467 | /* now local changes will be tracked by inotify, but remote changes won't */ |
|
|
2468 | /* unless the filesystem it known to be local, we therefore still poll */ |
|
|
2469 | /* also do poll on <2.6.25, but with normal frequency */ |
|
|
2470 | struct statfs sfs; |
|
|
2471 | |
|
|
2472 | if (fs_2625 && !statfs (w->path, &sfs)) |
|
|
2473 | if (sfs.f_type == 0x1373 /* devfs */ |
|
|
2474 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
|
|
2475 | || sfs.f_type == 0x3153464a /* jfs */ |
|
|
2476 | || sfs.f_type == 0x52654973 /* reiser3 */ |
|
|
2477 | || sfs.f_type == 0x01021994 /* tempfs */ |
|
|
2478 | || sfs.f_type == 0x58465342 /* xfs */) |
|
|
2479 | return; |
|
|
2480 | |
|
|
2481 | w->timer.repeat = w->interval ? w->interval : fs_2625 ? NFS_STAT_INTERVAL : DEF_STAT_INTERVAL; |
|
|
2482 | ev_timer_again (EV_A_ &w->timer); |
|
|
2483 | } |
2262 | } |
2484 | } |
2263 | |
2485 | |
2264 | static void noinline |
2486 | static void noinline |
2265 | infy_del (EV_P_ ev_stat *w) |
2487 | infy_del (EV_P_ ev_stat *w) |
2266 | { |
2488 | { |
… | |
… | |
2280 | |
2502 | |
2281 | static void noinline |
2503 | static void noinline |
2282 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2504 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2283 | { |
2505 | { |
2284 | if (slot < 0) |
2506 | if (slot < 0) |
2285 | /* overflow, need to check for all hahs slots */ |
2507 | /* overflow, need to check for all hash slots */ |
2286 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
2508 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
2287 | infy_wd (EV_A_ slot, wd, ev); |
2509 | infy_wd (EV_A_ slot, wd, ev); |
2288 | else |
2510 | else |
2289 | { |
2511 | { |
2290 | WL w_; |
2512 | WL w_; |
… | |
… | |
2319 | for (ofs = 0; ofs < len; ofs += sizeof (struct inotify_event) + ev->len) |
2541 | for (ofs = 0; ofs < len; ofs += sizeof (struct inotify_event) + ev->len) |
2320 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
2542 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
2321 | } |
2543 | } |
2322 | |
2544 | |
2323 | void inline_size |
2545 | void inline_size |
|
|
2546 | check_2625 (EV_P) |
|
|
2547 | { |
|
|
2548 | /* kernels < 2.6.25 are borked |
|
|
2549 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
|
|
2550 | */ |
|
|
2551 | struct utsname buf; |
|
|
2552 | int major, minor, micro; |
|
|
2553 | |
|
|
2554 | if (uname (&buf)) |
|
|
2555 | return; |
|
|
2556 | |
|
|
2557 | if (sscanf (buf.release, "%d.%d.%d", &major, &minor, µ) != 3) |
|
|
2558 | return; |
|
|
2559 | |
|
|
2560 | if (major < 2 |
|
|
2561 | || (major == 2 && minor < 6) |
|
|
2562 | || (major == 2 && minor == 6 && micro < 25)) |
|
|
2563 | return; |
|
|
2564 | |
|
|
2565 | fs_2625 = 1; |
|
|
2566 | } |
|
|
2567 | |
|
|
2568 | void inline_size |
2324 | infy_init (EV_P) |
2569 | infy_init (EV_P) |
2325 | { |
2570 | { |
2326 | if (fs_fd != -2) |
2571 | if (fs_fd != -2) |
2327 | return; |
2572 | return; |
|
|
2573 | |
|
|
2574 | fs_fd = -1; |
|
|
2575 | |
|
|
2576 | check_2625 (EV_A); |
2328 | |
2577 | |
2329 | fs_fd = inotify_init (); |
2578 | fs_fd = inotify_init (); |
2330 | |
2579 | |
2331 | if (fs_fd >= 0) |
2580 | if (fs_fd >= 0) |
2332 | { |
2581 | { |
… | |
… | |
2360 | w->wd = -1; |
2609 | w->wd = -1; |
2361 | |
2610 | |
2362 | if (fs_fd >= 0) |
2611 | if (fs_fd >= 0) |
2363 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2612 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2364 | else |
2613 | else |
2365 | ev_timer_start (EV_A_ &w->timer); |
2614 | ev_timer_again (EV_A_ &w->timer); |
2366 | } |
2615 | } |
2367 | |
|
|
2368 | } |
2616 | } |
2369 | } |
2617 | } |
2370 | |
2618 | |
|
|
2619 | #endif |
|
|
2620 | |
|
|
2621 | #ifdef _WIN32 |
|
|
2622 | # define EV_LSTAT(p,b) _stati64 (p, b) |
|
|
2623 | #else |
|
|
2624 | # define EV_LSTAT(p,b) lstat (p, b) |
2371 | #endif |
2625 | #endif |
2372 | |
2626 | |
2373 | void |
2627 | void |
2374 | ev_stat_stat (EV_P_ ev_stat *w) |
2628 | ev_stat_stat (EV_P_ ev_stat *w) |
2375 | { |
2629 | { |
… | |
… | |
2402 | || w->prev.st_atime != w->attr.st_atime |
2656 | || w->prev.st_atime != w->attr.st_atime |
2403 | || w->prev.st_mtime != w->attr.st_mtime |
2657 | || w->prev.st_mtime != w->attr.st_mtime |
2404 | || w->prev.st_ctime != w->attr.st_ctime |
2658 | || w->prev.st_ctime != w->attr.st_ctime |
2405 | ) { |
2659 | ) { |
2406 | #if EV_USE_INOTIFY |
2660 | #if EV_USE_INOTIFY |
|
|
2661 | if (fs_fd >= 0) |
|
|
2662 | { |
2407 | infy_del (EV_A_ w); |
2663 | infy_del (EV_A_ w); |
2408 | infy_add (EV_A_ w); |
2664 | infy_add (EV_A_ w); |
2409 | ev_stat_stat (EV_A_ w); /* avoid race... */ |
2665 | ev_stat_stat (EV_A_ w); /* avoid race... */ |
|
|
2666 | } |
2410 | #endif |
2667 | #endif |
2411 | |
2668 | |
2412 | ev_feed_event (EV_A_ w, EV_STAT); |
2669 | ev_feed_event (EV_A_ w, EV_STAT); |
2413 | } |
2670 | } |
2414 | } |
2671 | } |
… | |
… | |
2417 | ev_stat_start (EV_P_ ev_stat *w) |
2674 | ev_stat_start (EV_P_ ev_stat *w) |
2418 | { |
2675 | { |
2419 | if (expect_false (ev_is_active (w))) |
2676 | if (expect_false (ev_is_active (w))) |
2420 | return; |
2677 | return; |
2421 | |
2678 | |
2422 | /* since we use memcmp, we need to clear any padding data etc. */ |
|
|
2423 | memset (&w->prev, 0, sizeof (ev_statdata)); |
|
|
2424 | memset (&w->attr, 0, sizeof (ev_statdata)); |
|
|
2425 | |
|
|
2426 | ev_stat_stat (EV_A_ w); |
2679 | ev_stat_stat (EV_A_ w); |
2427 | |
2680 | |
|
|
2681 | if (w->interval < MIN_STAT_INTERVAL && w->interval) |
2428 | if (w->interval < MIN_STAT_INTERVAL) |
2682 | w->interval = MIN_STAT_INTERVAL; |
2429 | w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL; |
|
|
2430 | |
2683 | |
2431 | ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); |
2684 | ev_timer_init (&w->timer, stat_timer_cb, 0., w->interval ? w->interval : DEF_STAT_INTERVAL); |
2432 | ev_set_priority (&w->timer, ev_priority (w)); |
2685 | ev_set_priority (&w->timer, ev_priority (w)); |
2433 | |
2686 | |
2434 | #if EV_USE_INOTIFY |
2687 | #if EV_USE_INOTIFY |
2435 | infy_init (EV_A); |
2688 | infy_init (EV_A); |
2436 | |
2689 | |
2437 | if (fs_fd >= 0) |
2690 | if (fs_fd >= 0) |
2438 | infy_add (EV_A_ w); |
2691 | infy_add (EV_A_ w); |
2439 | else |
2692 | else |
2440 | #endif |
2693 | #endif |
2441 | ev_timer_start (EV_A_ &w->timer); |
2694 | ev_timer_again (EV_A_ &w->timer); |
2442 | |
2695 | |
2443 | ev_start (EV_A_ (W)w, 1); |
2696 | ev_start (EV_A_ (W)w, 1); |
|
|
2697 | |
|
|
2698 | EV_FREQUENT_CHECK; |
2444 | } |
2699 | } |
2445 | |
2700 | |
2446 | void |
2701 | void |
2447 | ev_stat_stop (EV_P_ ev_stat *w) |
2702 | ev_stat_stop (EV_P_ ev_stat *w) |
2448 | { |
2703 | { |
2449 | clear_pending (EV_A_ (W)w); |
2704 | clear_pending (EV_A_ (W)w); |
2450 | if (expect_false (!ev_is_active (w))) |
2705 | if (expect_false (!ev_is_active (w))) |
2451 | return; |
2706 | return; |
2452 | |
2707 | |
|
|
2708 | EV_FREQUENT_CHECK; |
|
|
2709 | |
2453 | #if EV_USE_INOTIFY |
2710 | #if EV_USE_INOTIFY |
2454 | infy_del (EV_A_ w); |
2711 | infy_del (EV_A_ w); |
2455 | #endif |
2712 | #endif |
2456 | ev_timer_stop (EV_A_ &w->timer); |
2713 | ev_timer_stop (EV_A_ &w->timer); |
2457 | |
2714 | |
2458 | ev_stop (EV_A_ (W)w); |
2715 | ev_stop (EV_A_ (W)w); |
|
|
2716 | |
|
|
2717 | EV_FREQUENT_CHECK; |
2459 | } |
2718 | } |
2460 | #endif |
2719 | #endif |
2461 | |
2720 | |
2462 | #if EV_IDLE_ENABLE |
2721 | #if EV_IDLE_ENABLE |
2463 | void |
2722 | void |
… | |
… | |
2465 | { |
2724 | { |
2466 | if (expect_false (ev_is_active (w))) |
2725 | if (expect_false (ev_is_active (w))) |
2467 | return; |
2726 | return; |
2468 | |
2727 | |
2469 | pri_adjust (EV_A_ (W)w); |
2728 | pri_adjust (EV_A_ (W)w); |
|
|
2729 | |
|
|
2730 | EV_FREQUENT_CHECK; |
2470 | |
2731 | |
2471 | { |
2732 | { |
2472 | int active = ++idlecnt [ABSPRI (w)]; |
2733 | int active = ++idlecnt [ABSPRI (w)]; |
2473 | |
2734 | |
2474 | ++idleall; |
2735 | ++idleall; |
2475 | ev_start (EV_A_ (W)w, active); |
2736 | ev_start (EV_A_ (W)w, active); |
2476 | |
2737 | |
2477 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2738 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2478 | idles [ABSPRI (w)][active - 1] = w; |
2739 | idles [ABSPRI (w)][active - 1] = w; |
2479 | } |
2740 | } |
|
|
2741 | |
|
|
2742 | EV_FREQUENT_CHECK; |
2480 | } |
2743 | } |
2481 | |
2744 | |
2482 | void |
2745 | void |
2483 | ev_idle_stop (EV_P_ ev_idle *w) |
2746 | ev_idle_stop (EV_P_ ev_idle *w) |
2484 | { |
2747 | { |
2485 | clear_pending (EV_A_ (W)w); |
2748 | clear_pending (EV_A_ (W)w); |
2486 | if (expect_false (!ev_is_active (w))) |
2749 | if (expect_false (!ev_is_active (w))) |
2487 | return; |
2750 | return; |
2488 | |
2751 | |
|
|
2752 | EV_FREQUENT_CHECK; |
|
|
2753 | |
2489 | { |
2754 | { |
2490 | int active = ev_active (w); |
2755 | int active = ev_active (w); |
2491 | |
2756 | |
2492 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2757 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2493 | ev_active (idles [ABSPRI (w)][active - 1]) = active; |
2758 | ev_active (idles [ABSPRI (w)][active - 1]) = active; |
2494 | |
2759 | |
2495 | ev_stop (EV_A_ (W)w); |
2760 | ev_stop (EV_A_ (W)w); |
2496 | --idleall; |
2761 | --idleall; |
2497 | } |
2762 | } |
|
|
2763 | |
|
|
2764 | EV_FREQUENT_CHECK; |
2498 | } |
2765 | } |
2499 | #endif |
2766 | #endif |
2500 | |
2767 | |
2501 | void |
2768 | void |
2502 | ev_prepare_start (EV_P_ ev_prepare *w) |
2769 | ev_prepare_start (EV_P_ ev_prepare *w) |
2503 | { |
2770 | { |
2504 | if (expect_false (ev_is_active (w))) |
2771 | if (expect_false (ev_is_active (w))) |
2505 | return; |
2772 | return; |
|
|
2773 | |
|
|
2774 | EV_FREQUENT_CHECK; |
2506 | |
2775 | |
2507 | ev_start (EV_A_ (W)w, ++preparecnt); |
2776 | ev_start (EV_A_ (W)w, ++preparecnt); |
2508 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
2777 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
2509 | prepares [preparecnt - 1] = w; |
2778 | prepares [preparecnt - 1] = w; |
|
|
2779 | |
|
|
2780 | EV_FREQUENT_CHECK; |
2510 | } |
2781 | } |
2511 | |
2782 | |
2512 | void |
2783 | void |
2513 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2784 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2514 | { |
2785 | { |
2515 | clear_pending (EV_A_ (W)w); |
2786 | clear_pending (EV_A_ (W)w); |
2516 | if (expect_false (!ev_is_active (w))) |
2787 | if (expect_false (!ev_is_active (w))) |
2517 | return; |
2788 | return; |
2518 | |
2789 | |
|
|
2790 | EV_FREQUENT_CHECK; |
|
|
2791 | |
2519 | { |
2792 | { |
2520 | int active = ev_active (w); |
2793 | int active = ev_active (w); |
2521 | |
2794 | |
2522 | prepares [active - 1] = prepares [--preparecnt]; |
2795 | prepares [active - 1] = prepares [--preparecnt]; |
2523 | ev_active (prepares [active - 1]) = active; |
2796 | ev_active (prepares [active - 1]) = active; |
2524 | } |
2797 | } |
2525 | |
2798 | |
2526 | ev_stop (EV_A_ (W)w); |
2799 | ev_stop (EV_A_ (W)w); |
|
|
2800 | |
|
|
2801 | EV_FREQUENT_CHECK; |
2527 | } |
2802 | } |
2528 | |
2803 | |
2529 | void |
2804 | void |
2530 | ev_check_start (EV_P_ ev_check *w) |
2805 | ev_check_start (EV_P_ ev_check *w) |
2531 | { |
2806 | { |
2532 | if (expect_false (ev_is_active (w))) |
2807 | if (expect_false (ev_is_active (w))) |
2533 | return; |
2808 | return; |
|
|
2809 | |
|
|
2810 | EV_FREQUENT_CHECK; |
2534 | |
2811 | |
2535 | ev_start (EV_A_ (W)w, ++checkcnt); |
2812 | ev_start (EV_A_ (W)w, ++checkcnt); |
2536 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
2813 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
2537 | checks [checkcnt - 1] = w; |
2814 | checks [checkcnt - 1] = w; |
|
|
2815 | |
|
|
2816 | EV_FREQUENT_CHECK; |
2538 | } |
2817 | } |
2539 | |
2818 | |
2540 | void |
2819 | void |
2541 | ev_check_stop (EV_P_ ev_check *w) |
2820 | ev_check_stop (EV_P_ ev_check *w) |
2542 | { |
2821 | { |
2543 | clear_pending (EV_A_ (W)w); |
2822 | clear_pending (EV_A_ (W)w); |
2544 | if (expect_false (!ev_is_active (w))) |
2823 | if (expect_false (!ev_is_active (w))) |
2545 | return; |
2824 | return; |
2546 | |
2825 | |
|
|
2826 | EV_FREQUENT_CHECK; |
|
|
2827 | |
2547 | { |
2828 | { |
2548 | int active = ev_active (w); |
2829 | int active = ev_active (w); |
2549 | |
2830 | |
2550 | checks [active - 1] = checks [--checkcnt]; |
2831 | checks [active - 1] = checks [--checkcnt]; |
2551 | ev_active (checks [active - 1]) = active; |
2832 | ev_active (checks [active - 1]) = active; |
2552 | } |
2833 | } |
2553 | |
2834 | |
2554 | ev_stop (EV_A_ (W)w); |
2835 | ev_stop (EV_A_ (W)w); |
|
|
2836 | |
|
|
2837 | EV_FREQUENT_CHECK; |
2555 | } |
2838 | } |
2556 | |
2839 | |
2557 | #if EV_EMBED_ENABLE |
2840 | #if EV_EMBED_ENABLE |
2558 | void noinline |
2841 | void noinline |
2559 | ev_embed_sweep (EV_P_ ev_embed *w) |
2842 | ev_embed_sweep (EV_P_ ev_embed *w) |
… | |
… | |
2586 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
2869 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
2587 | } |
2870 | } |
2588 | } |
2871 | } |
2589 | } |
2872 | } |
2590 | |
2873 | |
|
|
2874 | static void |
|
|
2875 | embed_fork_cb (EV_P_ ev_fork *fork_w, int revents) |
|
|
2876 | { |
|
|
2877 | ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); |
|
|
2878 | |
|
|
2879 | { |
|
|
2880 | struct ev_loop *loop = w->other; |
|
|
2881 | |
|
|
2882 | ev_loop_fork (EV_A); |
|
|
2883 | } |
|
|
2884 | } |
|
|
2885 | |
2591 | #if 0 |
2886 | #if 0 |
2592 | static void |
2887 | static void |
2593 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
2888 | embed_idle_cb (EV_P_ ev_idle *idle, int revents) |
2594 | { |
2889 | { |
2595 | ev_idle_stop (EV_A_ idle); |
2890 | ev_idle_stop (EV_A_ idle); |
… | |
… | |
2606 | struct ev_loop *loop = w->other; |
2901 | struct ev_loop *loop = w->other; |
2607 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
2902 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
2608 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); |
2903 | ev_io_init (&w->io, embed_io_cb, backend_fd, EV_READ); |
2609 | } |
2904 | } |
2610 | |
2905 | |
|
|
2906 | EV_FREQUENT_CHECK; |
|
|
2907 | |
2611 | ev_set_priority (&w->io, ev_priority (w)); |
2908 | ev_set_priority (&w->io, ev_priority (w)); |
2612 | ev_io_start (EV_A_ &w->io); |
2909 | ev_io_start (EV_A_ &w->io); |
2613 | |
2910 | |
2614 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2911 | ev_prepare_init (&w->prepare, embed_prepare_cb); |
2615 | ev_set_priority (&w->prepare, EV_MINPRI); |
2912 | ev_set_priority (&w->prepare, EV_MINPRI); |
2616 | ev_prepare_start (EV_A_ &w->prepare); |
2913 | ev_prepare_start (EV_A_ &w->prepare); |
2617 | |
2914 | |
|
|
2915 | ev_fork_init (&w->fork, embed_fork_cb); |
|
|
2916 | ev_fork_start (EV_A_ &w->fork); |
|
|
2917 | |
2618 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2918 | /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ |
2619 | |
2919 | |
2620 | ev_start (EV_A_ (W)w, 1); |
2920 | ev_start (EV_A_ (W)w, 1); |
|
|
2921 | |
|
|
2922 | EV_FREQUENT_CHECK; |
2621 | } |
2923 | } |
2622 | |
2924 | |
2623 | void |
2925 | void |
2624 | ev_embed_stop (EV_P_ ev_embed *w) |
2926 | ev_embed_stop (EV_P_ ev_embed *w) |
2625 | { |
2927 | { |
2626 | clear_pending (EV_A_ (W)w); |
2928 | clear_pending (EV_A_ (W)w); |
2627 | if (expect_false (!ev_is_active (w))) |
2929 | if (expect_false (!ev_is_active (w))) |
2628 | return; |
2930 | return; |
2629 | |
2931 | |
|
|
2932 | EV_FREQUENT_CHECK; |
|
|
2933 | |
2630 | ev_io_stop (EV_A_ &w->io); |
2934 | ev_io_stop (EV_A_ &w->io); |
2631 | ev_prepare_stop (EV_A_ &w->prepare); |
2935 | ev_prepare_stop (EV_A_ &w->prepare); |
|
|
2936 | ev_fork_stop (EV_A_ &w->fork); |
2632 | |
2937 | |
2633 | ev_stop (EV_A_ (W)w); |
2938 | EV_FREQUENT_CHECK; |
2634 | } |
2939 | } |
2635 | #endif |
2940 | #endif |
2636 | |
2941 | |
2637 | #if EV_FORK_ENABLE |
2942 | #if EV_FORK_ENABLE |
2638 | void |
2943 | void |
2639 | ev_fork_start (EV_P_ ev_fork *w) |
2944 | ev_fork_start (EV_P_ ev_fork *w) |
2640 | { |
2945 | { |
2641 | if (expect_false (ev_is_active (w))) |
2946 | if (expect_false (ev_is_active (w))) |
2642 | return; |
2947 | return; |
|
|
2948 | |
|
|
2949 | EV_FREQUENT_CHECK; |
2643 | |
2950 | |
2644 | ev_start (EV_A_ (W)w, ++forkcnt); |
2951 | ev_start (EV_A_ (W)w, ++forkcnt); |
2645 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
2952 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
2646 | forks [forkcnt - 1] = w; |
2953 | forks [forkcnt - 1] = w; |
|
|
2954 | |
|
|
2955 | EV_FREQUENT_CHECK; |
2647 | } |
2956 | } |
2648 | |
2957 | |
2649 | void |
2958 | void |
2650 | ev_fork_stop (EV_P_ ev_fork *w) |
2959 | ev_fork_stop (EV_P_ ev_fork *w) |
2651 | { |
2960 | { |
2652 | clear_pending (EV_A_ (W)w); |
2961 | clear_pending (EV_A_ (W)w); |
2653 | if (expect_false (!ev_is_active (w))) |
2962 | if (expect_false (!ev_is_active (w))) |
2654 | return; |
2963 | return; |
2655 | |
2964 | |
|
|
2965 | EV_FREQUENT_CHECK; |
|
|
2966 | |
2656 | { |
2967 | { |
2657 | int active = ev_active (w); |
2968 | int active = ev_active (w); |
2658 | |
2969 | |
2659 | forks [active - 1] = forks [--forkcnt]; |
2970 | forks [active - 1] = forks [--forkcnt]; |
2660 | ev_active (forks [active - 1]) = active; |
2971 | ev_active (forks [active - 1]) = active; |
2661 | } |
2972 | } |
2662 | |
2973 | |
2663 | ev_stop (EV_A_ (W)w); |
2974 | ev_stop (EV_A_ (W)w); |
|
|
2975 | |
|
|
2976 | EV_FREQUENT_CHECK; |
2664 | } |
2977 | } |
2665 | #endif |
2978 | #endif |
2666 | |
2979 | |
2667 | #if EV_ASYNC_ENABLE |
2980 | #if EV_ASYNC_ENABLE |
2668 | void |
2981 | void |
… | |
… | |
2670 | { |
2983 | { |
2671 | if (expect_false (ev_is_active (w))) |
2984 | if (expect_false (ev_is_active (w))) |
2672 | return; |
2985 | return; |
2673 | |
2986 | |
2674 | evpipe_init (EV_A); |
2987 | evpipe_init (EV_A); |
|
|
2988 | |
|
|
2989 | EV_FREQUENT_CHECK; |
2675 | |
2990 | |
2676 | ev_start (EV_A_ (W)w, ++asynccnt); |
2991 | ev_start (EV_A_ (W)w, ++asynccnt); |
2677 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
2992 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
2678 | asyncs [asynccnt - 1] = w; |
2993 | asyncs [asynccnt - 1] = w; |
|
|
2994 | |
|
|
2995 | EV_FREQUENT_CHECK; |
2679 | } |
2996 | } |
2680 | |
2997 | |
2681 | void |
2998 | void |
2682 | ev_async_stop (EV_P_ ev_async *w) |
2999 | ev_async_stop (EV_P_ ev_async *w) |
2683 | { |
3000 | { |
2684 | clear_pending (EV_A_ (W)w); |
3001 | clear_pending (EV_A_ (W)w); |
2685 | if (expect_false (!ev_is_active (w))) |
3002 | if (expect_false (!ev_is_active (w))) |
2686 | return; |
3003 | return; |
2687 | |
3004 | |
|
|
3005 | EV_FREQUENT_CHECK; |
|
|
3006 | |
2688 | { |
3007 | { |
2689 | int active = ev_active (w); |
3008 | int active = ev_active (w); |
2690 | |
3009 | |
2691 | asyncs [active - 1] = asyncs [--asynccnt]; |
3010 | asyncs [active - 1] = asyncs [--asynccnt]; |
2692 | ev_active (asyncs [active - 1]) = active; |
3011 | ev_active (asyncs [active - 1]) = active; |
2693 | } |
3012 | } |
2694 | |
3013 | |
2695 | ev_stop (EV_A_ (W)w); |
3014 | ev_stop (EV_A_ (W)w); |
|
|
3015 | |
|
|
3016 | EV_FREQUENT_CHECK; |
2696 | } |
3017 | } |
2697 | |
3018 | |
2698 | void |
3019 | void |
2699 | ev_async_send (EV_P_ ev_async *w) |
3020 | ev_async_send (EV_P_ ev_async *w) |
2700 | { |
3021 | { |
… | |
… | |
2717 | once_cb (EV_P_ struct ev_once *once, int revents) |
3038 | once_cb (EV_P_ struct ev_once *once, int revents) |
2718 | { |
3039 | { |
2719 | void (*cb)(int revents, void *arg) = once->cb; |
3040 | void (*cb)(int revents, void *arg) = once->cb; |
2720 | void *arg = once->arg; |
3041 | void *arg = once->arg; |
2721 | |
3042 | |
2722 | ev_io_stop (EV_A_ &once->io); |
3043 | ev_io_stop (EV_A_ &once->io); |
2723 | ev_timer_stop (EV_A_ &once->to); |
3044 | ev_timer_stop (EV_A_ &once->to); |
2724 | ev_free (once); |
3045 | ev_free (once); |
2725 | |
3046 | |
2726 | cb (revents, arg); |
3047 | cb (revents, arg); |
2727 | } |
3048 | } |
2728 | |
3049 | |
2729 | static void |
3050 | static void |
2730 | once_cb_io (EV_P_ ev_io *w, int revents) |
3051 | once_cb_io (EV_P_ ev_io *w, int revents) |
2731 | { |
3052 | { |
2732 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); |
3053 | struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)); |
|
|
3054 | |
|
|
3055 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->to)); |
2733 | } |
3056 | } |
2734 | |
3057 | |
2735 | static void |
3058 | static void |
2736 | once_cb_to (EV_P_ ev_timer *w, int revents) |
3059 | once_cb_to (EV_P_ ev_timer *w, int revents) |
2737 | { |
3060 | { |
2738 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); |
3061 | struct ev_once *once = (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)); |
|
|
3062 | |
|
|
3063 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
2739 | } |
3064 | } |
2740 | |
3065 | |
2741 | void |
3066 | void |
2742 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
3067 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
2743 | { |
3068 | { |