… | |
… | |
310 | { |
310 | { |
311 | return ev_rt_now; |
311 | return ev_rt_now; |
312 | } |
312 | } |
313 | #endif |
313 | #endif |
314 | |
314 | |
315 | #define array_roundsize(type,n) ((n) | 4 & ~3) |
315 | #define array_roundsize(type,n) (((n) | 4) & ~3) |
316 | |
316 | |
317 | #define array_needsize(type,base,cur,cnt,init) \ |
317 | #define array_needsize(type,base,cur,cnt,init) \ |
318 | if (expect_false ((cnt) > cur)) \ |
318 | if (expect_false ((cnt) > cur)) \ |
319 | { \ |
319 | { \ |
320 | int newcnt = cur; \ |
320 | int newcnt = cur; \ |
… | |
… | |
753 | { |
753 | { |
754 | return method; |
754 | return method; |
755 | } |
755 | } |
756 | |
756 | |
757 | static void |
757 | static void |
758 | loop_init (EV_P_ int methods) |
758 | loop_init (EV_P_ unsigned int flags) |
759 | { |
759 | { |
760 | if (!method) |
760 | if (!method) |
761 | { |
761 | { |
762 | #if EV_USE_MONOTONIC |
762 | #if EV_USE_MONOTONIC |
763 | { |
763 | { |
… | |
… | |
770 | ev_rt_now = ev_time (); |
770 | ev_rt_now = ev_time (); |
771 | mn_now = get_clock (); |
771 | mn_now = get_clock (); |
772 | now_floor = mn_now; |
772 | now_floor = mn_now; |
773 | rtmn_diff = ev_rt_now - mn_now; |
773 | rtmn_diff = ev_rt_now - mn_now; |
774 | |
774 | |
775 | if (methods == EVMETHOD_AUTO) |
775 | if (!(flags & EVMETHOD_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS")) |
776 | if (!enable_secure () && getenv ("LIBEV_METHODS")) |
|
|
777 | methods = atoi (getenv ("LIBEV_METHODS")); |
776 | flags = atoi (getenv ("LIBEV_FLAGS")); |
778 | else |
777 | |
779 | methods = EVMETHOD_ANY; |
778 | if (!(flags & 0x0000ffff)) |
|
|
779 | flags |= 0x0000ffff; |
780 | |
780 | |
781 | method = 0; |
781 | method = 0; |
782 | #if EV_USE_KQUEUE |
782 | #if EV_USE_KQUEUE |
783 | if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); |
783 | if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); |
784 | #endif |
784 | #endif |
785 | #if EV_USE_EPOLL |
785 | #if EV_USE_EPOLL |
786 | if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); |
786 | if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); |
787 | #endif |
787 | #endif |
788 | #if EV_USE_POLL |
788 | #if EV_USE_POLL |
789 | if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); |
789 | if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); |
790 | #endif |
790 | #endif |
791 | #if EV_USE_SELECT |
791 | #if EV_USE_SELECT |
792 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
792 | if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); |
793 | #endif |
793 | #endif |
794 | |
794 | |
795 | ev_init (&sigev, sigcb); |
795 | ev_init (&sigev, sigcb); |
796 | ev_set_priority (&sigev, EV_MAXPRI); |
796 | ev_set_priority (&sigev, EV_MAXPRI); |
797 | } |
797 | } |
… | |
… | |
859 | postfork = 0; |
859 | postfork = 0; |
860 | } |
860 | } |
861 | |
861 | |
862 | #if EV_MULTIPLICITY |
862 | #if EV_MULTIPLICITY |
863 | struct ev_loop * |
863 | struct ev_loop * |
864 | ev_loop_new (int methods) |
864 | ev_loop_new (unsigned int flags) |
865 | { |
865 | { |
866 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
866 | struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
867 | |
867 | |
868 | memset (loop, 0, sizeof (struct ev_loop)); |
868 | memset (loop, 0, sizeof (struct ev_loop)); |
869 | |
869 | |
870 | loop_init (EV_A_ methods); |
870 | loop_init (EV_A_ flags); |
871 | |
871 | |
872 | if (ev_method (EV_A)) |
872 | if (ev_method (EV_A)) |
873 | return loop; |
873 | return loop; |
874 | |
874 | |
875 | return 0; |
875 | return 0; |
… | |
… | |
893 | #if EV_MULTIPLICITY |
893 | #if EV_MULTIPLICITY |
894 | struct ev_loop * |
894 | struct ev_loop * |
895 | #else |
895 | #else |
896 | int |
896 | int |
897 | #endif |
897 | #endif |
898 | ev_default_loop (int methods) |
898 | ev_default_loop (unsigned int methods) |
899 | { |
899 | { |
900 | if (sigpipe [0] == sigpipe [1]) |
900 | if (sigpipe [0] == sigpipe [1]) |
901 | if (pipe (sigpipe)) |
901 | if (pipe (sigpipe)) |
902 | return 0; |
902 | return 0; |
903 | |
903 | |
… | |
… | |
1031 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1031 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1032 | |
1032 | |
1033 | /* first reschedule or stop timer */ |
1033 | /* first reschedule or stop timer */ |
1034 | if (w->reschedule_cb) |
1034 | if (w->reschedule_cb) |
1035 | { |
1035 | { |
1036 | ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); |
1036 | ((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)); |
1037 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1039 | downheap ((WT *)periodics, periodiccnt, 0); |
1038 | downheap ((WT *)periodics, periodiccnt, 0); |
1040 | } |
1039 | } |
1041 | else if (w->interval) |
1040 | else if (w->interval) |
1042 | { |
1041 | { |