… | |
… | |
59 | |
59 | |
60 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) |
60 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) |
61 | # define EV_USE_KQUEUE 1 |
61 | # define EV_USE_KQUEUE 1 |
62 | # endif |
62 | # endif |
63 | |
63 | |
|
|
64 | # if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT) |
|
|
65 | # define EV_USE_PORT 1 |
|
|
66 | # endif |
|
|
67 | |
64 | #endif |
68 | #endif |
65 | |
69 | |
66 | #include <math.h> |
70 | #include <math.h> |
67 | #include <stdlib.h> |
71 | #include <stdlib.h> |
68 | #include <fcntl.h> |
72 | #include <fcntl.h> |
… | |
… | |
93 | |
97 | |
94 | #ifndef EV_USE_MONOTONIC |
98 | #ifndef EV_USE_MONOTONIC |
95 | # define EV_USE_MONOTONIC 1 |
99 | # define EV_USE_MONOTONIC 1 |
96 | #endif |
100 | #endif |
97 | |
101 | |
|
|
102 | #ifndef EV_USE_REALTIME |
|
|
103 | # define EV_USE_REALTIME 1 |
|
|
104 | #endif |
|
|
105 | |
98 | #ifndef EV_USE_SELECT |
106 | #ifndef EV_USE_SELECT |
99 | # define EV_USE_SELECT 1 |
107 | # define EV_USE_SELECT 1 |
100 | # define EV_SELECT_USE_FD_SET 1 |
108 | # define EV_SELECT_USE_FD_SET 1 |
101 | #endif |
109 | #endif |
102 | |
110 | |
… | |
… | |
114 | |
122 | |
115 | #ifndef EV_USE_KQUEUE |
123 | #ifndef EV_USE_KQUEUE |
116 | # define EV_USE_KQUEUE 0 |
124 | # define EV_USE_KQUEUE 0 |
117 | #endif |
125 | #endif |
118 | |
126 | |
119 | #ifndef EV_USE_REALTIME |
127 | #ifndef EV_USE_PORT |
120 | # define EV_USE_REALTIME 1 |
128 | # define EV_USE_PORT 0 |
121 | #endif |
129 | #endif |
122 | |
130 | |
123 | /**/ |
131 | /**/ |
124 | |
132 | |
125 | /* darwin simply cnanot be helped */ |
133 | /* darwin simply cannot be helped */ |
126 | #ifdef __APPLE__ |
134 | #ifdef __APPLE__ |
127 | # undef EV_USE_POLL |
135 | # undef EV_USE_POLL |
128 | # undef EV_USE_KQUEUE |
136 | # undef EV_USE_KQUEUE |
129 | #endif |
137 | #endif |
130 | |
138 | |
… | |
… | |
167 | #define expect_true(expr) expect ((expr) != 0, 1) |
175 | #define expect_true(expr) expect ((expr) != 0, 1) |
168 | |
176 | |
169 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
177 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
170 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
178 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
171 | |
179 | |
172 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
180 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
|
|
181 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
173 | |
182 | |
174 | typedef struct ev_watcher *W; |
183 | typedef struct ev_watcher *W; |
175 | typedef struct ev_watcher_list *WL; |
184 | typedef struct ev_watcher_list *WL; |
176 | typedef struct ev_watcher_time *WT; |
185 | typedef struct ev_watcher_time *WT; |
177 | |
186 | |
… | |
… | |
257 | #include "ev_vars.h" |
266 | #include "ev_vars.h" |
258 | #undef VAR |
267 | #undef VAR |
259 | }; |
268 | }; |
260 | #include "ev_wrap.h" |
269 | #include "ev_wrap.h" |
261 | |
270 | |
262 | struct ev_loop default_loop_struct; |
271 | static struct ev_loop default_loop_struct; |
263 | static struct ev_loop *default_loop; |
272 | struct ev_loop *ev_default_loop_ptr; |
264 | |
273 | |
265 | #else |
274 | #else |
266 | |
275 | |
267 | ev_tstamp ev_rt_now; |
276 | ev_tstamp ev_rt_now; |
268 | #define VAR(name,decl) static decl; |
277 | #define VAR(name,decl) static decl; |
269 | #include "ev_vars.h" |
278 | #include "ev_vars.h" |
270 | #undef VAR |
279 | #undef VAR |
271 | |
280 | |
272 | static int default_loop; |
281 | static int ev_default_loop_ptr; |
273 | |
282 | |
274 | #endif |
283 | #endif |
275 | |
284 | |
276 | /*****************************************************************************/ |
285 | /*****************************************************************************/ |
277 | |
286 | |
… | |
… | |
310 | { |
319 | { |
311 | return ev_rt_now; |
320 | return ev_rt_now; |
312 | } |
321 | } |
313 | #endif |
322 | #endif |
314 | |
323 | |
315 | #define array_roundsize(type,n) ((n) | 4 & ~3) |
324 | #define array_roundsize(type,n) (((n) | 4) & ~3) |
316 | |
325 | |
317 | #define array_needsize(type,base,cur,cnt,init) \ |
326 | #define array_needsize(type,base,cur,cnt,init) \ |
318 | if (expect_false ((cnt) > cur)) \ |
327 | if (expect_false ((cnt) > cur)) \ |
319 | { \ |
328 | { \ |
320 | int newcnt = cur; \ |
329 | int newcnt = cur; \ |
… | |
… | |
365 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
374 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
366 | return; |
375 | return; |
367 | } |
376 | } |
368 | |
377 | |
369 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
378 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
370 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void)); |
379 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
371 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
380 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
372 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
381 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
373 | } |
382 | } |
374 | |
383 | |
375 | static void |
384 | static void |
… | |
… | |
445 | return; |
454 | return; |
446 | |
455 | |
447 | anfds [fd].reify = 1; |
456 | anfds [fd].reify = 1; |
448 | |
457 | |
449 | ++fdchangecnt; |
458 | ++fdchangecnt; |
450 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void)); |
459 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
451 | fdchanges [fdchangecnt - 1] = fd; |
460 | fdchanges [fdchangecnt - 1] = fd; |
452 | } |
461 | } |
453 | |
462 | |
454 | static void |
463 | static void |
455 | fd_kill (EV_P_ int fd) |
464 | fd_kill (EV_P_ int fd) |
… | |
… | |
613 | ev_feed_signal_event (EV_P_ int signum) |
622 | ev_feed_signal_event (EV_P_ int signum) |
614 | { |
623 | { |
615 | WL w; |
624 | WL w; |
616 | |
625 | |
617 | #if EV_MULTIPLICITY |
626 | #if EV_MULTIPLICITY |
618 | assert (("feeding signal events is only supported in the default loop", loop == default_loop)); |
627 | assert (("feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr)); |
619 | #endif |
628 | #endif |
620 | |
629 | |
621 | --signum; |
630 | --signum; |
622 | |
631 | |
623 | if (signum < 0 || signum >= signalmax) |
632 | if (signum < 0 || signum >= signalmax) |
… | |
… | |
709 | |
718 | |
710 | #endif |
719 | #endif |
711 | |
720 | |
712 | /*****************************************************************************/ |
721 | /*****************************************************************************/ |
713 | |
722 | |
|
|
723 | #if EV_USE_PORT |
|
|
724 | # include "ev_port.c" |
|
|
725 | #endif |
714 | #if EV_USE_KQUEUE |
726 | #if EV_USE_KQUEUE |
715 | # include "ev_kqueue.c" |
727 | # include "ev_kqueue.c" |
716 | #endif |
728 | #endif |
717 | #if EV_USE_EPOLL |
729 | #if EV_USE_EPOLL |
718 | # include "ev_epoll.c" |
730 | # include "ev_epoll.c" |
… | |
… | |
746 | return getuid () != geteuid () |
758 | return getuid () != geteuid () |
747 | || getgid () != getegid (); |
759 | || getgid () != getegid (); |
748 | #endif |
760 | #endif |
749 | } |
761 | } |
750 | |
762 | |
751 | int |
763 | unsigned int |
752 | ev_method (EV_P) |
764 | ev_method (EV_P) |
753 | { |
765 | { |
754 | return method; |
766 | return method; |
755 | } |
767 | } |
756 | |
768 | |
757 | static void |
769 | static void |
758 | loop_init (EV_P_ int methods) |
770 | loop_init (EV_P_ unsigned int flags) |
759 | { |
771 | { |
760 | if (!method) |
772 | if (!method) |
761 | { |
773 | { |
762 | #if EV_USE_MONOTONIC |
774 | #if EV_USE_MONOTONIC |
763 | { |
775 | { |
… | |
… | |
770 | ev_rt_now = ev_time (); |
782 | ev_rt_now = ev_time (); |
771 | mn_now = get_clock (); |
783 | mn_now = get_clock (); |
772 | now_floor = mn_now; |
784 | now_floor = mn_now; |
773 | rtmn_diff = ev_rt_now - mn_now; |
785 | rtmn_diff = ev_rt_now - mn_now; |
774 | |
786 | |
775 | if (methods == EVMETHOD_AUTO) |
787 | if (!(flags & EVFLAG_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS")) |
776 | if (!enable_secure () && getenv ("LIBEV_METHODS")) |
|
|
777 | methods = atoi (getenv ("LIBEV_METHODS")); |
788 | flags = atoi (getenv ("LIBEV_FLAGS")); |
778 | else |
789 | |
779 | methods = EVMETHOD_ANY; |
790 | if (!(flags & 0x0000ffff)) |
|
|
791 | flags |= 0x0000ffff; |
780 | |
792 | |
781 | method = 0; |
793 | method = 0; |
|
|
794 | #if EV_USE_PORT |
|
|
795 | if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags); |
|
|
796 | #endif |
782 | #if EV_USE_KQUEUE |
797 | #if EV_USE_KQUEUE |
783 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
798 | if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); |
784 | #endif |
799 | #endif |
785 | #if EV_USE_EPOLL |
800 | #if EV_USE_EPOLL |
786 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
801 | if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); |
787 | #endif |
802 | #endif |
788 | #if EV_USE_POLL |
803 | #if EV_USE_POLL |
789 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
804 | if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); |
790 | #endif |
805 | #endif |
791 | #if EV_USE_SELECT |
806 | #if EV_USE_SELECT |
792 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
807 | if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); |
793 | #endif |
808 | #endif |
794 | |
809 | |
795 | ev_init (&sigev, sigcb); |
810 | ev_init (&sigev, sigcb); |
796 | ev_set_priority (&sigev, EV_MAXPRI); |
811 | ev_set_priority (&sigev, EV_MAXPRI); |
797 | } |
812 | } |
… | |
… | |
800 | void |
815 | void |
801 | loop_destroy (EV_P) |
816 | loop_destroy (EV_P) |
802 | { |
817 | { |
803 | int i; |
818 | int i; |
804 | |
819 | |
|
|
820 | #if EV_USE_PORT |
|
|
821 | if (method == EVMETHOD_PORT ) port_destroy (EV_A); |
|
|
822 | #endif |
805 | #if EV_USE_KQUEUE |
823 | #if EV_USE_KQUEUE |
806 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
824 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
807 | #endif |
825 | #endif |
808 | #if EV_USE_EPOLL |
826 | #if EV_USE_EPOLL |
809 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
827 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
… | |
… | |
817 | |
835 | |
818 | for (i = NUMPRI; i--; ) |
836 | for (i = NUMPRI; i--; ) |
819 | array_free (pending, [i]); |
837 | array_free (pending, [i]); |
820 | |
838 | |
821 | /* have to use the microsoft-never-gets-it-right macro */ |
839 | /* have to use the microsoft-never-gets-it-right macro */ |
822 | array_free (fdchange, EMPTY); |
840 | array_free (fdchange, EMPTY0); |
823 | array_free (timer, EMPTY); |
841 | array_free (timer, EMPTY0); |
824 | #if EV_PERIODICS |
842 | #if EV_PERIODICS |
825 | array_free (periodic, EMPTY); |
843 | array_free (periodic, EMPTY0); |
826 | #endif |
844 | #endif |
827 | array_free (idle, EMPTY); |
845 | array_free (idle, EMPTY0); |
828 | array_free (prepare, EMPTY); |
846 | array_free (prepare, EMPTY0); |
829 | array_free (check, EMPTY); |
847 | array_free (check, EMPTY0); |
830 | |
848 | |
831 | method = 0; |
849 | method = 0; |
832 | } |
850 | } |
833 | |
851 | |
834 | static void |
852 | static void |
835 | loop_fork (EV_P) |
853 | loop_fork (EV_P) |
836 | { |
854 | { |
|
|
855 | #if EV_USE_PORT |
|
|
856 | if (method == EVMETHOD_PORT ) port_fork (EV_A); |
|
|
857 | #endif |
|
|
858 | #if EV_USE_KQUEUE |
|
|
859 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
|
|
860 | #endif |
837 | #if EV_USE_EPOLL |
861 | #if EV_USE_EPOLL |
838 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
862 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
839 | #endif |
|
|
840 | #if EV_USE_KQUEUE |
|
|
841 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
|
|
842 | #endif |
863 | #endif |
843 | |
864 | |
844 | if (ev_is_active (&sigev)) |
865 | if (ev_is_active (&sigev)) |
845 | { |
866 | { |
846 | /* default loop */ |
867 | /* default loop */ |
… | |
… | |
859 | postfork = 0; |
880 | postfork = 0; |
860 | } |
881 | } |
861 | |
882 | |
862 | #if EV_MULTIPLICITY |
883 | #if EV_MULTIPLICITY |
863 | struct ev_loop * |
884 | struct ev_loop * |
864 | ev_loop_new (int methods) |
885 | ev_loop_new (unsigned int flags) |
865 | { |
886 | { |
866 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
887 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
867 | |
888 | |
868 | memset (loop, 0, sizeof (struct ev_loop)); |
889 | memset (loop, 0, sizeof (struct ev_loop)); |
869 | |
890 | |
870 | loop_init (EV_A_ methods); |
891 | loop_init (EV_A_ flags); |
871 | |
892 | |
872 | if (ev_method (EV_A)) |
893 | if (ev_method (EV_A)) |
873 | return loop; |
894 | return loop; |
874 | |
895 | |
875 | return 0; |
896 | return 0; |
… | |
… | |
890 | |
911 | |
891 | #endif |
912 | #endif |
892 | |
913 | |
893 | #if EV_MULTIPLICITY |
914 | #if EV_MULTIPLICITY |
894 | struct ev_loop * |
915 | struct ev_loop * |
|
|
916 | ev_default_loop_ (unsigned int flags) |
895 | #else |
917 | #else |
896 | int |
918 | int |
|
|
919 | ev_default_loop (unsigned int flags) |
897 | #endif |
920 | #endif |
898 | ev_default_loop (int methods) |
|
|
899 | { |
921 | { |
900 | if (sigpipe [0] == sigpipe [1]) |
922 | if (sigpipe [0] == sigpipe [1]) |
901 | if (pipe (sigpipe)) |
923 | if (pipe (sigpipe)) |
902 | return 0; |
924 | return 0; |
903 | |
925 | |
904 | if (!default_loop) |
926 | if (!ev_default_loop_ptr) |
905 | { |
927 | { |
906 | #if EV_MULTIPLICITY |
928 | #if EV_MULTIPLICITY |
907 | struct ev_loop *loop = default_loop = &default_loop_struct; |
929 | struct ev_loop *loop = ev_default_loop_ptr = &default_loop_struct; |
908 | #else |
930 | #else |
909 | default_loop = 1; |
931 | ev_default_loop_ptr = 1; |
910 | #endif |
932 | #endif |
911 | |
933 | |
912 | loop_init (EV_A_ methods); |
934 | loop_init (EV_A_ flags); |
913 | |
935 | |
914 | if (ev_method (EV_A)) |
936 | if (ev_method (EV_A)) |
915 | { |
937 | { |
916 | siginit (EV_A); |
938 | siginit (EV_A); |
917 | |
939 | |
… | |
… | |
921 | ev_signal_start (EV_A_ &childev); |
943 | ev_signal_start (EV_A_ &childev); |
922 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
944 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
923 | #endif |
945 | #endif |
924 | } |
946 | } |
925 | else |
947 | else |
926 | default_loop = 0; |
948 | ev_default_loop_ptr = 0; |
927 | } |
949 | } |
928 | |
950 | |
929 | return default_loop; |
951 | return ev_default_loop_ptr; |
930 | } |
952 | } |
931 | |
953 | |
932 | void |
954 | void |
933 | ev_default_destroy (void) |
955 | ev_default_destroy (void) |
934 | { |
956 | { |
935 | #if EV_MULTIPLICITY |
957 | #if EV_MULTIPLICITY |
936 | struct ev_loop *loop = default_loop; |
958 | struct ev_loop *loop = ev_default_loop_ptr; |
937 | #endif |
959 | #endif |
938 | |
960 | |
939 | #ifndef _WIN32 |
961 | #ifndef _WIN32 |
940 | ev_ref (EV_A); /* child watcher */ |
962 | ev_ref (EV_A); /* child watcher */ |
941 | ev_signal_stop (EV_A_ &childev); |
963 | ev_signal_stop (EV_A_ &childev); |
… | |
… | |
952 | |
974 | |
953 | void |
975 | void |
954 | ev_default_fork (void) |
976 | ev_default_fork (void) |
955 | { |
977 | { |
956 | #if EV_MULTIPLICITY |
978 | #if EV_MULTIPLICITY |
957 | struct ev_loop *loop = default_loop; |
979 | struct ev_loop *loop = ev_default_loop_ptr; |
958 | #endif |
980 | #endif |
959 | |
981 | |
960 | if (method) |
982 | if (method) |
961 | postfork = 1; |
983 | postfork = 1; |
962 | } |
984 | } |
… | |
… | |
1031 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1053 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1032 | |
1054 | |
1033 | /* first reschedule or stop timer */ |
1055 | /* first reschedule or stop timer */ |
1034 | if (w->reschedule_cb) |
1056 | if (w->reschedule_cb) |
1035 | { |
1057 | { |
1036 | ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); |
1058 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); |
1037 | |
|
|
1038 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1059 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1039 | downheap ((WT *)periodics, periodiccnt, 0); |
1060 | downheap ((WT *)periodics, periodiccnt, 0); |
1040 | } |
1061 | } |
1041 | else if (w->interval) |
1062 | else if (w->interval) |
1042 | { |
1063 | { |
… | |
… | |
1160 | ev_loop (EV_P_ int flags) |
1181 | ev_loop (EV_P_ int flags) |
1161 | { |
1182 | { |
1162 | double block; |
1183 | double block; |
1163 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; |
1184 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; |
1164 | |
1185 | |
1165 | do |
1186 | while (activecnt) |
1166 | { |
1187 | { |
1167 | /* queue check watchers (and execute them) */ |
1188 | /* queue check watchers (and execute them) */ |
1168 | if (expect_false (preparecnt)) |
1189 | if (expect_false (preparecnt)) |
1169 | { |
1190 | { |
1170 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1191 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
… | |
… | |
1233 | /* queue check watchers, to be executed first */ |
1254 | /* queue check watchers, to be executed first */ |
1234 | if (checkcnt) |
1255 | if (checkcnt) |
1235 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1256 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1236 | |
1257 | |
1237 | call_pending (EV_A); |
1258 | call_pending (EV_A); |
|
|
1259 | |
|
|
1260 | if (loop_done) |
|
|
1261 | break; |
1238 | } |
1262 | } |
1239 | while (activecnt && !loop_done); |
|
|
1240 | |
1263 | |
1241 | if (loop_done != 2) |
1264 | if (loop_done != 2) |
1242 | loop_done = 0; |
1265 | loop_done = 0; |
1243 | } |
1266 | } |
1244 | |
1267 | |
… | |
… | |
1342 | ((WT)w)->at += mn_now; |
1365 | ((WT)w)->at += mn_now; |
1343 | |
1366 | |
1344 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1367 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1345 | |
1368 | |
1346 | ev_start (EV_A_ (W)w, ++timercnt); |
1369 | ev_start (EV_A_ (W)w, ++timercnt); |
1347 | array_needsize (struct ev_timer *, timers, timermax, timercnt, (void)); |
1370 | array_needsize (struct ev_timer *, timers, timermax, timercnt, EMPTY2); |
1348 | timers [timercnt - 1] = w; |
1371 | timers [timercnt - 1] = w; |
1349 | upheap ((WT *)timers, timercnt - 1); |
1372 | upheap ((WT *)timers, timercnt - 1); |
1350 | |
1373 | |
1351 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1374 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1352 | } |
1375 | } |
… | |
… | |
1383 | } |
1406 | } |
1384 | else |
1407 | else |
1385 | ev_timer_stop (EV_A_ w); |
1408 | ev_timer_stop (EV_A_ w); |
1386 | } |
1409 | } |
1387 | else if (w->repeat) |
1410 | else if (w->repeat) |
|
|
1411 | { |
|
|
1412 | w->at = w->repeat; |
1388 | ev_timer_start (EV_A_ w); |
1413 | ev_timer_start (EV_A_ w); |
|
|
1414 | } |
1389 | } |
1415 | } |
1390 | |
1416 | |
1391 | #if EV_PERIODICS |
1417 | #if EV_PERIODICS |
1392 | void |
1418 | void |
1393 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1419 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
… | |
… | |
1403 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1429 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1404 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1430 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1405 | } |
1431 | } |
1406 | |
1432 | |
1407 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1433 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1408 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); |
1434 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1409 | periodics [periodiccnt - 1] = w; |
1435 | periodics [periodiccnt - 1] = w; |
1410 | upheap ((WT *)periodics, periodiccnt - 1); |
1436 | upheap ((WT *)periodics, periodiccnt - 1); |
1411 | |
1437 | |
1412 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1438 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1413 | } |
1439 | } |
… | |
… | |
1444 | { |
1470 | { |
1445 | if (ev_is_active (w)) |
1471 | if (ev_is_active (w)) |
1446 | return; |
1472 | return; |
1447 | |
1473 | |
1448 | ev_start (EV_A_ (W)w, ++idlecnt); |
1474 | ev_start (EV_A_ (W)w, ++idlecnt); |
1449 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void)); |
1475 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
1450 | idles [idlecnt - 1] = w; |
1476 | idles [idlecnt - 1] = w; |
1451 | } |
1477 | } |
1452 | |
1478 | |
1453 | void |
1479 | void |
1454 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1480 | ev_idle_stop (EV_P_ struct ev_idle *w) |
… | |
… | |
1466 | { |
1492 | { |
1467 | if (ev_is_active (w)) |
1493 | if (ev_is_active (w)) |
1468 | return; |
1494 | return; |
1469 | |
1495 | |
1470 | ev_start (EV_A_ (W)w, ++preparecnt); |
1496 | ev_start (EV_A_ (W)w, ++preparecnt); |
1471 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void)); |
1497 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
1472 | prepares [preparecnt - 1] = w; |
1498 | prepares [preparecnt - 1] = w; |
1473 | } |
1499 | } |
1474 | |
1500 | |
1475 | void |
1501 | void |
1476 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1502 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
… | |
… | |
1488 | { |
1514 | { |
1489 | if (ev_is_active (w)) |
1515 | if (ev_is_active (w)) |
1490 | return; |
1516 | return; |
1491 | |
1517 | |
1492 | ev_start (EV_A_ (W)w, ++checkcnt); |
1518 | ev_start (EV_A_ (W)w, ++checkcnt); |
1493 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void)); |
1519 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); |
1494 | checks [checkcnt - 1] = w; |
1520 | checks [checkcnt - 1] = w; |
1495 | } |
1521 | } |
1496 | |
1522 | |
1497 | void |
1523 | void |
1498 | ev_check_stop (EV_P_ struct ev_check *w) |
1524 | ev_check_stop (EV_P_ struct ev_check *w) |
… | |
… | |
1511 | |
1537 | |
1512 | void |
1538 | void |
1513 | ev_signal_start (EV_P_ struct ev_signal *w) |
1539 | ev_signal_start (EV_P_ struct ev_signal *w) |
1514 | { |
1540 | { |
1515 | #if EV_MULTIPLICITY |
1541 | #if EV_MULTIPLICITY |
1516 | assert (("signal watchers are only supported in the default loop", loop == default_loop)); |
1542 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1517 | #endif |
1543 | #endif |
1518 | if (ev_is_active (w)) |
1544 | if (ev_is_active (w)) |
1519 | return; |
1545 | return; |
1520 | |
1546 | |
1521 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1547 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
… | |
… | |
1554 | |
1580 | |
1555 | void |
1581 | void |
1556 | ev_child_start (EV_P_ struct ev_child *w) |
1582 | ev_child_start (EV_P_ struct ev_child *w) |
1557 | { |
1583 | { |
1558 | #if EV_MULTIPLICITY |
1584 | #if EV_MULTIPLICITY |
1559 | assert (("child watchers are only supported in the default loop", loop == default_loop)); |
1585 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1560 | #endif |
1586 | #endif |
1561 | if (ev_is_active (w)) |
1587 | if (ev_is_active (w)) |
1562 | return; |
1588 | return; |
1563 | |
1589 | |
1564 | ev_start (EV_A_ (W)w, 1); |
1590 | ev_start (EV_A_ (W)w, 1); |