… | |
… | |
39 | |
39 | |
40 | #ifdef __cplusplus |
40 | #ifdef __cplusplus |
41 | extern "C" { |
41 | extern "C" { |
42 | #endif |
42 | #endif |
43 | |
43 | |
|
|
44 | /* this big block deduces configuration from config.h */ |
44 | #ifndef EV_STANDALONE |
45 | #ifndef EV_STANDALONE |
45 | # ifdef EV_CONFIG_H |
46 | # ifdef EV_CONFIG_H |
46 | # include EV_CONFIG_H |
47 | # include EV_CONFIG_H |
47 | # else |
48 | # else |
48 | # include "config.h" |
49 | # include "config.h" |
… | |
… | |
118 | # else |
119 | # else |
119 | # define EV_USE_INOTIFY 0 |
120 | # define EV_USE_INOTIFY 0 |
120 | # endif |
121 | # endif |
121 | # endif |
122 | # endif |
122 | |
123 | |
|
|
124 | # ifndef EV_USE_EVENTFD |
|
|
125 | # if HAVE_EVENTFD |
|
|
126 | # define EV_USE_EVENTFD 1 |
|
|
127 | # else |
|
|
128 | # define EV_USE_EVENTFD 0 |
|
|
129 | # endif |
|
|
130 | # endif |
|
|
131 | |
123 | #endif |
132 | #endif |
124 | |
133 | |
125 | #include <math.h> |
134 | #include <math.h> |
126 | #include <stdlib.h> |
135 | #include <stdlib.h> |
127 | #include <fcntl.h> |
136 | #include <fcntl.h> |
… | |
… | |
152 | # ifndef EV_SELECT_IS_WINSOCKET |
161 | # ifndef EV_SELECT_IS_WINSOCKET |
153 | # define EV_SELECT_IS_WINSOCKET 1 |
162 | # define EV_SELECT_IS_WINSOCKET 1 |
154 | # endif |
163 | # endif |
155 | #endif |
164 | #endif |
156 | |
165 | |
157 | /**/ |
166 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
158 | |
167 | |
159 | #ifndef EV_USE_MONOTONIC |
168 | #ifndef EV_USE_MONOTONIC |
160 | # define EV_USE_MONOTONIC 0 |
169 | # define EV_USE_MONOTONIC 0 |
161 | #endif |
170 | #endif |
162 | |
171 | |
… | |
… | |
179 | # define EV_USE_POLL 1 |
188 | # define EV_USE_POLL 1 |
180 | # endif |
189 | # endif |
181 | #endif |
190 | #endif |
182 | |
191 | |
183 | #ifndef EV_USE_EPOLL |
192 | #ifndef EV_USE_EPOLL |
|
|
193 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
|
|
194 | # define EV_USE_EPOLL 1 |
|
|
195 | # else |
184 | # define EV_USE_EPOLL 0 |
196 | # define EV_USE_EPOLL 0 |
|
|
197 | # endif |
185 | #endif |
198 | #endif |
186 | |
199 | |
187 | #ifndef EV_USE_KQUEUE |
200 | #ifndef EV_USE_KQUEUE |
188 | # define EV_USE_KQUEUE 0 |
201 | # define EV_USE_KQUEUE 0 |
189 | #endif |
202 | #endif |
… | |
… | |
191 | #ifndef EV_USE_PORT |
204 | #ifndef EV_USE_PORT |
192 | # define EV_USE_PORT 0 |
205 | # define EV_USE_PORT 0 |
193 | #endif |
206 | #endif |
194 | |
207 | |
195 | #ifndef EV_USE_INOTIFY |
208 | #ifndef EV_USE_INOTIFY |
|
|
209 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
|
|
210 | # define EV_USE_INOTIFY 1 |
|
|
211 | # else |
196 | # define EV_USE_INOTIFY 0 |
212 | # define EV_USE_INOTIFY 0 |
|
|
213 | # endif |
197 | #endif |
214 | #endif |
198 | |
215 | |
199 | #ifndef EV_PID_HASHSIZE |
216 | #ifndef EV_PID_HASHSIZE |
200 | # if EV_MINIMAL |
217 | # if EV_MINIMAL |
201 | # define EV_PID_HASHSIZE 1 |
218 | # define EV_PID_HASHSIZE 1 |
… | |
… | |
210 | # else |
227 | # else |
211 | # define EV_INOTIFY_HASHSIZE 16 |
228 | # define EV_INOTIFY_HASHSIZE 16 |
212 | # endif |
229 | # endif |
213 | #endif |
230 | #endif |
214 | |
231 | |
215 | /**/ |
232 | #ifndef EV_USE_EVENTFD |
|
|
233 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
|
|
234 | # define EV_USE_EVENTFD 1 |
|
|
235 | # else |
|
|
236 | # define EV_USE_EVENTFD 0 |
|
|
237 | # endif |
|
|
238 | #endif |
|
|
239 | |
|
|
240 | /* this block fixes any misconfiguration where we know we run into trouble otherwise */ |
216 | |
241 | |
217 | #ifndef CLOCK_MONOTONIC |
242 | #ifndef CLOCK_MONOTONIC |
218 | # undef EV_USE_MONOTONIC |
243 | # undef EV_USE_MONOTONIC |
219 | # define EV_USE_MONOTONIC 0 |
244 | # define EV_USE_MONOTONIC 0 |
220 | #endif |
245 | #endif |
… | |
… | |
239 | # include <sys/inotify.h> |
264 | # include <sys/inotify.h> |
240 | #endif |
265 | #endif |
241 | |
266 | |
242 | #if EV_SELECT_IS_WINSOCKET |
267 | #if EV_SELECT_IS_WINSOCKET |
243 | # include <winsock.h> |
268 | # include <winsock.h> |
|
|
269 | #endif |
|
|
270 | |
|
|
271 | #if EV_USE_EVENTFD |
|
|
272 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
|
|
273 | # include <stdint.h> |
|
|
274 | # ifdef __cplusplus |
|
|
275 | extern "C" { |
|
|
276 | # endif |
|
|
277 | int eventfd (unsigned int initval, int flags); |
|
|
278 | # ifdef __cplusplus |
|
|
279 | } |
|
|
280 | # endif |
244 | #endif |
281 | #endif |
245 | |
282 | |
246 | /**/ |
283 | /**/ |
247 | |
284 | |
248 | /* |
285 | /* |
… | |
… | |
263 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
300 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
264 | # define noinline __attribute__ ((noinline)) |
301 | # define noinline __attribute__ ((noinline)) |
265 | #else |
302 | #else |
266 | # define expect(expr,value) (expr) |
303 | # define expect(expr,value) (expr) |
267 | # define noinline |
304 | # define noinline |
268 | # if __STDC_VERSION__ < 199901L |
305 | # if __STDC_VERSION__ < 199901L && __GNUC__ < 2 |
269 | # define inline |
306 | # define inline |
270 | # endif |
307 | # endif |
271 | #endif |
308 | #endif |
272 | |
309 | |
273 | #define expect_false(expr) expect ((expr) != 0, 0) |
310 | #define expect_false(expr) expect ((expr) != 0, 0) |
… | |
… | |
323 | perror (msg); |
360 | perror (msg); |
324 | abort (); |
361 | abort (); |
325 | } |
362 | } |
326 | } |
363 | } |
327 | |
364 | |
|
|
365 | static void * |
|
|
366 | ev_realloc_emul (void *ptr, long size) |
|
|
367 | { |
|
|
368 | /* some systems, notably openbsd and darwin, fail to properly |
|
|
369 | * implement realloc (x, 0) (as required by both ansi c-98 and |
|
|
370 | * the single unix specification, so work around them here. |
|
|
371 | */ |
|
|
372 | |
|
|
373 | if (size) |
|
|
374 | return realloc (ptr, size); |
|
|
375 | |
|
|
376 | free (ptr); |
|
|
377 | return 0; |
|
|
378 | } |
|
|
379 | |
328 | static void *(*alloc)(void *ptr, long size); |
380 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
329 | |
381 | |
330 | void |
382 | void |
331 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
383 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
332 | { |
384 | { |
333 | alloc = cb; |
385 | alloc = cb; |
334 | } |
386 | } |
335 | |
387 | |
336 | inline_speed void * |
388 | inline_speed void * |
337 | ev_realloc (void *ptr, long size) |
389 | ev_realloc (void *ptr, long size) |
338 | { |
390 | { |
339 | ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); |
391 | ptr = alloc (ptr, size); |
340 | |
392 | |
341 | if (!ptr && size) |
393 | if (!ptr && size) |
342 | { |
394 | { |
343 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
395 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
344 | abort (); |
396 | abort (); |
… | |
… | |
451 | ts.tv_sec = (time_t)delay; |
503 | ts.tv_sec = (time_t)delay; |
452 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
504 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
453 | |
505 | |
454 | nanosleep (&ts, 0); |
506 | nanosleep (&ts, 0); |
455 | #elif defined(_WIN32) |
507 | #elif defined(_WIN32) |
456 | Sleep (delay * 1e3); |
508 | Sleep ((unsigned long)(delay * 1e3)); |
457 | #else |
509 | #else |
458 | struct timeval tv; |
510 | struct timeval tv; |
459 | |
511 | |
460 | tv.tv_sec = (time_t)delay; |
512 | tv.tv_sec = (time_t)delay; |
461 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
513 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
… | |
… | |
702 | } |
754 | } |
703 | } |
755 | } |
704 | |
756 | |
705 | /*****************************************************************************/ |
757 | /*****************************************************************************/ |
706 | |
758 | |
|
|
759 | /* towards the root */ |
707 | void inline_speed |
760 | void inline_speed |
708 | upheap (WT *heap, int k) |
761 | upheap (WT *heap, int k) |
709 | { |
762 | { |
710 | WT w = heap [k]; |
763 | WT w = heap [k]; |
711 | |
764 | |
… | |
… | |
723 | |
776 | |
724 | heap [k] = w; |
777 | heap [k] = w; |
725 | ((W)heap [k])->active = k + 1; |
778 | ((W)heap [k])->active = k + 1; |
726 | } |
779 | } |
727 | |
780 | |
|
|
781 | /* away from the root */ |
728 | void inline_speed |
782 | void inline_speed |
729 | downheap (WT *heap, int N, int k) |
783 | downheap (WT *heap, int N, int k) |
730 | { |
784 | { |
731 | WT w = heap [k]; |
785 | WT w = heap [k]; |
732 | |
786 | |
… | |
… | |
802 | static void noinline |
856 | static void noinline |
803 | evpipe_init (EV_P) |
857 | evpipe_init (EV_P) |
804 | { |
858 | { |
805 | if (!ev_is_active (&pipeev)) |
859 | if (!ev_is_active (&pipeev)) |
806 | { |
860 | { |
|
|
861 | #if EV_USE_EVENTFD |
|
|
862 | if ((evfd = eventfd (0, 0)) >= 0) |
|
|
863 | { |
|
|
864 | evpipe [0] = -1; |
|
|
865 | fd_intern (evfd); |
|
|
866 | ev_io_set (&pipeev, evfd, EV_READ); |
|
|
867 | } |
|
|
868 | else |
|
|
869 | #endif |
|
|
870 | { |
807 | while (pipe (evpipe)) |
871 | while (pipe (evpipe)) |
808 | syserr ("(libev) error creating signal/async pipe"); |
872 | syserr ("(libev) error creating signal/async pipe"); |
809 | |
873 | |
810 | fd_intern (evpipe [0]); |
874 | fd_intern (evpipe [0]); |
811 | fd_intern (evpipe [1]); |
875 | fd_intern (evpipe [1]); |
812 | |
|
|
813 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
876 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
|
|
877 | } |
|
|
878 | |
814 | ev_io_start (EV_A_ &pipeev); |
879 | ev_io_start (EV_A_ &pipeev); |
815 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
880 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
816 | } |
881 | } |
817 | } |
882 | } |
818 | |
883 | |
819 | void inline_size |
884 | void inline_size |
820 | evpipe_write (EV_P_ int sig, int async) |
885 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
821 | { |
886 | { |
822 | if (!(gotasync || gotsig)) |
887 | if (!*flag) |
823 | { |
888 | { |
824 | int old_errno = errno; |
889 | int old_errno = errno; /* save errno because write might clobber it */ |
825 | |
890 | |
826 | if (sig) gotsig = 1; |
891 | *flag = 1; |
827 | if (async) gotasync = 1; |
|
|
828 | |
892 | |
|
|
893 | #if EV_USE_EVENTFD |
|
|
894 | if (evfd >= 0) |
|
|
895 | { |
|
|
896 | uint64_t counter = 1; |
|
|
897 | write (evfd, &counter, sizeof (uint64_t)); |
|
|
898 | } |
|
|
899 | else |
|
|
900 | #endif |
829 | write (evpipe [1], &old_errno, 1); |
901 | write (evpipe [1], &old_errno, 1); |
|
|
902 | |
830 | errno = old_errno; |
903 | errno = old_errno; |
831 | } |
904 | } |
832 | } |
905 | } |
833 | |
906 | |
834 | static void |
907 | static void |
835 | pipecb (EV_P_ ev_io *iow, int revents) |
908 | pipecb (EV_P_ ev_io *iow, int revents) |
836 | { |
909 | { |
|
|
910 | #if EV_USE_EVENTFD |
|
|
911 | if (evfd >= 0) |
837 | { |
912 | { |
838 | int dummy; |
913 | uint64_t counter = 1; |
|
|
914 | read (evfd, &counter, sizeof (uint64_t)); |
|
|
915 | } |
|
|
916 | else |
|
|
917 | #endif |
|
|
918 | { |
|
|
919 | char dummy; |
839 | read (evpipe [0], &dummy, 1); |
920 | read (evpipe [0], &dummy, 1); |
840 | } |
921 | } |
841 | |
922 | |
842 | if (gotsig) |
923 | if (gotsig && ev_is_default_loop (EV_A)) |
843 | { |
924 | { |
844 | int signum; |
925 | int signum; |
845 | gotsig = 0; |
926 | gotsig = 0; |
846 | |
927 | |
847 | for (signum = signalmax; signum--; ) |
928 | for (signum = signalmax; signum--; ) |
848 | if (signals [signum].gotsig) |
929 | if (signals [signum].gotsig) |
849 | ev_feed_signal_event (EV_A_ signum + 1); |
930 | ev_feed_signal_event (EV_A_ signum + 1); |
850 | } |
931 | } |
851 | |
932 | |
|
|
933 | #if EV_ASYNC_ENABLE |
852 | if (gotasync) |
934 | if (gotasync) |
853 | { |
935 | { |
854 | int i; |
936 | int i; |
855 | gotasync = 0; |
937 | gotasync = 0; |
856 | |
938 | |
… | |
… | |
859 | { |
941 | { |
860 | asyncs [i]->sent = 0; |
942 | asyncs [i]->sent = 0; |
861 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
943 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
862 | } |
944 | } |
863 | } |
945 | } |
|
|
946 | #endif |
864 | } |
947 | } |
865 | |
948 | |
866 | /*****************************************************************************/ |
949 | /*****************************************************************************/ |
867 | |
950 | |
868 | static void |
951 | static void |
869 | sighandler (int signum) |
952 | ev_sighandler (int signum) |
870 | { |
953 | { |
871 | #if EV_MULTIPLICITY |
954 | #if EV_MULTIPLICITY |
872 | struct ev_loop *loop = &default_loop_struct; |
955 | struct ev_loop *loop = &default_loop_struct; |
873 | #endif |
956 | #endif |
874 | |
957 | |
875 | #if _WIN32 |
958 | #if _WIN32 |
876 | signal (signum, sighandler); |
959 | signal (signum, ev_sighandler); |
877 | #endif |
960 | #endif |
878 | |
961 | |
879 | signals [signum - 1].gotsig = 1; |
962 | signals [signum - 1].gotsig = 1; |
880 | evpipe_write (EV_A_ 1, 0); |
963 | evpipe_write (EV_A_ &gotsig); |
881 | } |
964 | } |
882 | |
965 | |
883 | void noinline |
966 | void noinline |
884 | ev_feed_signal_event (EV_P_ int signum) |
967 | ev_feed_signal_event (EV_P_ int signum) |
885 | { |
968 | { |
… | |
… | |
911 | #ifndef WIFCONTINUED |
994 | #ifndef WIFCONTINUED |
912 | # define WIFCONTINUED(status) 0 |
995 | # define WIFCONTINUED(status) 0 |
913 | #endif |
996 | #endif |
914 | |
997 | |
915 | void inline_speed |
998 | void inline_speed |
916 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
999 | child_reap (EV_P_ int chain, int pid, int status) |
917 | { |
1000 | { |
918 | ev_child *w; |
1001 | ev_child *w; |
919 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1002 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
920 | |
1003 | |
921 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1004 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
922 | { |
1005 | { |
923 | if ((w->pid == pid || !w->pid) |
1006 | if ((w->pid == pid || !w->pid) |
924 | && (!traced || (w->flags & 1))) |
1007 | && (!traced || (w->flags & 1))) |
925 | { |
1008 | { |
926 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
1009 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
927 | w->rpid = pid; |
1010 | w->rpid = pid; |
928 | w->rstatus = status; |
1011 | w->rstatus = status; |
929 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
1012 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
930 | } |
1013 | } |
931 | } |
1014 | } |
… | |
… | |
945 | if (!WCONTINUED |
1028 | if (!WCONTINUED |
946 | || errno != EINVAL |
1029 | || errno != EINVAL |
947 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
1030 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
948 | return; |
1031 | return; |
949 | |
1032 | |
950 | /* make sure we are called again until all childs have been reaped */ |
1033 | /* make sure we are called again until all children have been reaped */ |
951 | /* we need to do it this way so that the callback gets called before we continue */ |
1034 | /* we need to do it this way so that the callback gets called before we continue */ |
952 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1035 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
953 | |
1036 | |
954 | child_reap (EV_A_ sw, pid, pid, status); |
1037 | child_reap (EV_A_ pid, pid, status); |
955 | if (EV_PID_HASHSIZE > 1) |
1038 | if (EV_PID_HASHSIZE > 1) |
956 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1039 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
957 | } |
1040 | } |
958 | |
1041 | |
959 | #endif |
1042 | #endif |
960 | |
1043 | |
961 | /*****************************************************************************/ |
1044 | /*****************************************************************************/ |
… | |
… | |
1079 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1162 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
1080 | have_monotonic = 1; |
1163 | have_monotonic = 1; |
1081 | } |
1164 | } |
1082 | #endif |
1165 | #endif |
1083 | |
1166 | |
1084 | ev_rt_now = ev_time (); |
1167 | ev_rt_now = ev_time (); |
1085 | mn_now = get_clock (); |
1168 | mn_now = get_clock (); |
1086 | now_floor = mn_now; |
1169 | now_floor = mn_now; |
1087 | rtmn_diff = ev_rt_now - mn_now; |
1170 | rtmn_diff = ev_rt_now - mn_now; |
1088 | |
1171 | |
1089 | io_blocktime = 0.; |
1172 | io_blocktime = 0.; |
1090 | timeout_blocktime = 0.; |
1173 | timeout_blocktime = 0.; |
|
|
1174 | backend = 0; |
|
|
1175 | backend_fd = -1; |
|
|
1176 | gotasync = 0; |
|
|
1177 | #if EV_USE_INOTIFY |
|
|
1178 | fs_fd = -2; |
|
|
1179 | #endif |
1091 | |
1180 | |
1092 | /* pid check not overridable via env */ |
1181 | /* pid check not overridable via env */ |
1093 | #ifndef _WIN32 |
1182 | #ifndef _WIN32 |
1094 | if (flags & EVFLAG_FORKCHECK) |
1183 | if (flags & EVFLAG_FORKCHECK) |
1095 | curpid = getpid (); |
1184 | curpid = getpid (); |
… | |
… | |
1098 | if (!(flags & EVFLAG_NOENV) |
1187 | if (!(flags & EVFLAG_NOENV) |
1099 | && !enable_secure () |
1188 | && !enable_secure () |
1100 | && getenv ("LIBEV_FLAGS")) |
1189 | && getenv ("LIBEV_FLAGS")) |
1101 | flags = atoi (getenv ("LIBEV_FLAGS")); |
1190 | flags = atoi (getenv ("LIBEV_FLAGS")); |
1102 | |
1191 | |
1103 | if (!(flags & 0x0000ffffUL)) |
1192 | if (!(flags & 0x0000ffffU)) |
1104 | flags |= ev_recommended_backends (); |
1193 | flags |= ev_recommended_backends (); |
1105 | |
|
|
1106 | backend = 0; |
|
|
1107 | backend_fd = -1; |
|
|
1108 | #if EV_USE_INOTIFY |
|
|
1109 | fs_fd = -2; |
|
|
1110 | #endif |
|
|
1111 | |
1194 | |
1112 | #if EV_USE_PORT |
1195 | #if EV_USE_PORT |
1113 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1196 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1114 | #endif |
1197 | #endif |
1115 | #if EV_USE_KQUEUE |
1198 | #if EV_USE_KQUEUE |
… | |
… | |
1138 | if (ev_is_active (&pipeev)) |
1221 | if (ev_is_active (&pipeev)) |
1139 | { |
1222 | { |
1140 | ev_ref (EV_A); /* signal watcher */ |
1223 | ev_ref (EV_A); /* signal watcher */ |
1141 | ev_io_stop (EV_A_ &pipeev); |
1224 | ev_io_stop (EV_A_ &pipeev); |
1142 | |
1225 | |
1143 | close (evpipe [0]); evpipe [0] = 0; |
1226 | #if EV_USE_EVENTFD |
1144 | close (evpipe [1]); evpipe [1] = 0; |
1227 | if (evfd >= 0) |
|
|
1228 | close (evfd); |
|
|
1229 | #endif |
|
|
1230 | |
|
|
1231 | if (evpipe [0] >= 0) |
|
|
1232 | { |
|
|
1233 | close (evpipe [0]); |
|
|
1234 | close (evpipe [1]); |
|
|
1235 | } |
1145 | } |
1236 | } |
1146 | |
1237 | |
1147 | #if EV_USE_INOTIFY |
1238 | #if EV_USE_INOTIFY |
1148 | if (fs_fd >= 0) |
1239 | if (fs_fd >= 0) |
1149 | close (fs_fd); |
1240 | close (fs_fd); |
… | |
… | |
1187 | #if EV_FORK_ENABLE |
1278 | #if EV_FORK_ENABLE |
1188 | array_free (fork, EMPTY); |
1279 | array_free (fork, EMPTY); |
1189 | #endif |
1280 | #endif |
1190 | array_free (prepare, EMPTY); |
1281 | array_free (prepare, EMPTY); |
1191 | array_free (check, EMPTY); |
1282 | array_free (check, EMPTY); |
|
|
1283 | #if EV_ASYNC_ENABLE |
|
|
1284 | array_free (async, EMPTY); |
|
|
1285 | #endif |
1192 | |
1286 | |
1193 | backend = 0; |
1287 | backend = 0; |
1194 | } |
1288 | } |
1195 | |
1289 | |
|
|
1290 | #if EV_USE_INOTIFY |
1196 | void inline_size infy_fork (EV_P); |
1291 | void inline_size infy_fork (EV_P); |
|
|
1292 | #endif |
1197 | |
1293 | |
1198 | void inline_size |
1294 | void inline_size |
1199 | loop_fork (EV_P) |
1295 | loop_fork (EV_P) |
1200 | { |
1296 | { |
1201 | #if EV_USE_PORT |
1297 | #if EV_USE_PORT |
… | |
… | |
1212 | #endif |
1308 | #endif |
1213 | |
1309 | |
1214 | if (ev_is_active (&pipeev)) |
1310 | if (ev_is_active (&pipeev)) |
1215 | { |
1311 | { |
1216 | /* this "locks" the handlers against writing to the pipe */ |
1312 | /* this "locks" the handlers against writing to the pipe */ |
|
|
1313 | /* while we modify the fd vars */ |
|
|
1314 | gotsig = 1; |
|
|
1315 | #if EV_ASYNC_ENABLE |
1217 | gotsig = gotasync = 1; |
1316 | gotasync = 1; |
|
|
1317 | #endif |
1218 | |
1318 | |
1219 | ev_ref (EV_A); |
1319 | ev_ref (EV_A); |
1220 | ev_io_stop (EV_A_ &pipeev); |
1320 | ev_io_stop (EV_A_ &pipeev); |
|
|
1321 | |
|
|
1322 | #if EV_USE_EVENTFD |
|
|
1323 | if (evfd >= 0) |
|
|
1324 | close (evfd); |
|
|
1325 | #endif |
|
|
1326 | |
|
|
1327 | if (evpipe [0] >= 0) |
|
|
1328 | { |
1221 | close (evpipe [0]); |
1329 | close (evpipe [0]); |
1222 | close (evpipe [1]); |
1330 | close (evpipe [1]); |
|
|
1331 | } |
1223 | |
1332 | |
1224 | evpipe_init (EV_A); |
1333 | evpipe_init (EV_A); |
1225 | /* now iterate over everything, in case we missed something */ |
1334 | /* now iterate over everything, in case we missed something */ |
1226 | pipecb (EV_A_ &pipeev, EV_READ); |
1335 | pipecb (EV_A_ &pipeev, EV_READ); |
1227 | } |
1336 | } |
… | |
… | |
1534 | static int loop_done; |
1643 | static int loop_done; |
1535 | |
1644 | |
1536 | void |
1645 | void |
1537 | ev_loop (EV_P_ int flags) |
1646 | ev_loop (EV_P_ int flags) |
1538 | { |
1647 | { |
1539 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
1648 | loop_done = EVUNLOOP_CANCEL; |
1540 | ? EVUNLOOP_ONE |
|
|
1541 | : EVUNLOOP_CANCEL; |
|
|
1542 | |
1649 | |
1543 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1650 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
1544 | |
1651 | |
1545 | do |
1652 | do |
1546 | { |
1653 | { |
… | |
… | |
1642 | /* queue check watchers, to be executed first */ |
1749 | /* queue check watchers, to be executed first */ |
1643 | if (expect_false (checkcnt)) |
1750 | if (expect_false (checkcnt)) |
1644 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1751 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1645 | |
1752 | |
1646 | call_pending (EV_A); |
1753 | call_pending (EV_A); |
1647 | |
|
|
1648 | } |
1754 | } |
1649 | while (expect_true (activecnt && !loop_done)); |
1755 | while (expect_true ( |
|
|
1756 | activecnt |
|
|
1757 | && !loop_done |
|
|
1758 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
|
|
1759 | )); |
1650 | |
1760 | |
1651 | if (loop_done == EVUNLOOP_ONE) |
1761 | if (loop_done == EVUNLOOP_ONE) |
1652 | loop_done = EVUNLOOP_CANCEL; |
1762 | loop_done = EVUNLOOP_CANCEL; |
1653 | } |
1763 | } |
1654 | |
1764 | |
… | |
… | |
1922 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
2032 | wlist_add (&signals [w->signum - 1].head, (WL)w); |
1923 | |
2033 | |
1924 | if (!((WL)w)->next) |
2034 | if (!((WL)w)->next) |
1925 | { |
2035 | { |
1926 | #if _WIN32 |
2036 | #if _WIN32 |
1927 | signal (w->signum, sighandler); |
2037 | signal (w->signum, ev_sighandler); |
1928 | #else |
2038 | #else |
1929 | struct sigaction sa; |
2039 | struct sigaction sa; |
1930 | sa.sa_handler = sighandler; |
2040 | sa.sa_handler = ev_sighandler; |
1931 | sigfillset (&sa.sa_mask); |
2041 | sigfillset (&sa.sa_mask); |
1932 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
2042 | sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ |
1933 | sigaction (w->signum, &sa, 0); |
2043 | sigaction (w->signum, &sa, 0); |
1934 | #endif |
2044 | #endif |
1935 | } |
2045 | } |
… | |
… | |
2458 | |
2568 | |
2459 | void |
2569 | void |
2460 | ev_async_send (EV_P_ ev_async *w) |
2570 | ev_async_send (EV_P_ ev_async *w) |
2461 | { |
2571 | { |
2462 | w->sent = 1; |
2572 | w->sent = 1; |
2463 | evpipe_write (EV_A_ 0, 1); |
2573 | evpipe_write (EV_A_ &gotasync); |
2464 | } |
2574 | } |
2465 | #endif |
2575 | #endif |
2466 | |
2576 | |
2467 | /*****************************************************************************/ |
2577 | /*****************************************************************************/ |
2468 | |
2578 | |