… | |
… | |
154 | # define EV_USE_PORT 0 |
154 | # define EV_USE_PORT 0 |
155 | #endif |
155 | #endif |
156 | |
156 | |
157 | /**/ |
157 | /**/ |
158 | |
158 | |
159 | /* darwin simply cannot be helped */ |
|
|
160 | #ifdef __APPLE__ |
|
|
161 | # undef EV_USE_POLL |
|
|
162 | # undef EV_USE_KQUEUE |
|
|
163 | #endif |
|
|
164 | |
|
|
165 | #ifndef CLOCK_MONOTONIC |
159 | #ifndef CLOCK_MONOTONIC |
166 | # undef EV_USE_MONOTONIC |
160 | # undef EV_USE_MONOTONIC |
167 | # define EV_USE_MONOTONIC 0 |
161 | # define EV_USE_MONOTONIC 0 |
168 | #endif |
162 | #endif |
169 | |
163 | |
… | |
… | |
785 | || getgid () != getegid (); |
779 | || getgid () != getegid (); |
786 | #endif |
780 | #endif |
787 | } |
781 | } |
788 | |
782 | |
789 | unsigned int |
783 | unsigned int |
790 | ev_method (EV_P) |
784 | ev_supported_backends (void) |
791 | { |
785 | { |
792 | return method; |
786 | } |
|
|
787 | |
|
|
788 | unsigned int |
|
|
789 | ev_recommended_backends (void) |
|
|
790 | { |
|
|
791 | unsigned int flags; |
|
|
792 | |
|
|
793 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
|
|
794 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
|
|
795 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
796 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
|
|
797 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
|
|
798 | |
|
|
799 | return flags; |
|
|
800 | } |
|
|
801 | |
|
|
802 | unsigned int |
|
|
803 | ev_backend (EV_P) |
|
|
804 | { |
|
|
805 | unsigned int flags = ev_recommended_backends (); |
|
|
806 | |
|
|
807 | #ifndef __NetBSD__ |
|
|
808 | /* kqueue is borked on everything but netbsd apparently */ |
|
|
809 | /* it usually doesn't work correctly on anything but sockets and pipes */ |
|
|
810 | flags &= ~EVBACKEND_KQUEUE; |
|
|
811 | #endif |
|
|
812 | #ifdef __APPLE__ |
|
|
813 | // flags &= ~EVBACKEND_KQUEUE; for documentation |
|
|
814 | flags &= ~EVBACKEND_POLL; |
|
|
815 | #endif |
|
|
816 | |
|
|
817 | return flags; |
793 | } |
818 | } |
794 | |
819 | |
795 | static void |
820 | static void |
796 | loop_init (EV_P_ unsigned int flags) |
821 | loop_init (EV_P_ unsigned int flags) |
797 | { |
822 | { |
… | |
… | |
808 | ev_rt_now = ev_time (); |
833 | ev_rt_now = ev_time (); |
809 | mn_now = get_clock (); |
834 | mn_now = get_clock (); |
810 | now_floor = mn_now; |
835 | now_floor = mn_now; |
811 | rtmn_diff = ev_rt_now - mn_now; |
836 | rtmn_diff = ev_rt_now - mn_now; |
812 | |
837 | |
813 | if (!(flags & EVFLAG_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS")) |
838 | if (!(flags & EVFLAG_NOENV) |
|
|
839 | && !enable_secure () |
|
|
840 | && getenv ("LIBEV_FLAGS")) |
814 | flags = atoi (getenv ("LIBEV_FLAGS")); |
841 | flags = atoi (getenv ("LIBEV_FLAGS")); |
815 | |
842 | |
816 | if (!(flags & 0x0000ffff)) |
843 | if (!(flags & 0x0000ffffUL)) |
817 | flags |= 0x0000ffff; |
844 | flags |= ev_recommended_backends (); |
818 | |
845 | |
819 | method = 0; |
846 | method = 0; |
820 | #if EV_USE_PORT |
847 | #if EV_USE_PORT |
821 | if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags); |
848 | if (!method && (flags & EVBACKEND_PORT )) method = port_init (EV_A_ flags); |
822 | #endif |
849 | #endif |
823 | #if EV_USE_KQUEUE |
850 | #if EV_USE_KQUEUE |
824 | if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); |
851 | if (!method && (flags & EVBACKEND_KQUEUE)) method = kqueue_init (EV_A_ flags); |
825 | #endif |
852 | #endif |
826 | #if EV_USE_EPOLL |
853 | #if EV_USE_EPOLL |
827 | if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); |
854 | if (!method && (flags & EVBACKEND_EPOLL )) method = epoll_init (EV_A_ flags); |
828 | #endif |
855 | #endif |
829 | #if EV_USE_POLL |
856 | #if EV_USE_POLL |
830 | if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); |
857 | if (!method && (flags & EVBACKEND_POLL )) method = poll_init (EV_A_ flags); |
831 | #endif |
858 | #endif |
832 | #if EV_USE_SELECT |
859 | #if EV_USE_SELECT |
833 | if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); |
860 | if (!method && (flags & EVBACKEND_SELECT)) method = select_init (EV_A_ flags); |
834 | #endif |
861 | #endif |
835 | |
862 | |
836 | ev_init (&sigev, sigcb); |
863 | ev_init (&sigev, sigcb); |
837 | ev_set_priority (&sigev, EV_MAXPRI); |
864 | ev_set_priority (&sigev, EV_MAXPRI); |
838 | } |
865 | } |
… | |
… | |
842 | loop_destroy (EV_P) |
869 | loop_destroy (EV_P) |
843 | { |
870 | { |
844 | int i; |
871 | int i; |
845 | |
872 | |
846 | #if EV_USE_PORT |
873 | #if EV_USE_PORT |
847 | if (method == EVMETHOD_PORT ) port_destroy (EV_A); |
874 | if (method == EVBACKEND_PORT ) port_destroy (EV_A); |
848 | #endif |
875 | #endif |
849 | #if EV_USE_KQUEUE |
876 | #if EV_USE_KQUEUE |
850 | if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); |
877 | if (method == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
851 | #endif |
878 | #endif |
852 | #if EV_USE_EPOLL |
879 | #if EV_USE_EPOLL |
853 | if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); |
880 | if (method == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
854 | #endif |
881 | #endif |
855 | #if EV_USE_POLL |
882 | #if EV_USE_POLL |
856 | if (method == EVMETHOD_POLL ) poll_destroy (EV_A); |
883 | if (method == EVBACKEND_POLL ) poll_destroy (EV_A); |
857 | #endif |
884 | #endif |
858 | #if EV_USE_SELECT |
885 | #if EV_USE_SELECT |
859 | if (method == EVMETHOD_SELECT) select_destroy (EV_A); |
886 | if (method == EVBACKEND_SELECT) select_destroy (EV_A); |
860 | #endif |
887 | #endif |
861 | |
888 | |
862 | for (i = NUMPRI; i--; ) |
889 | for (i = NUMPRI; i--; ) |
863 | array_free (pending, [i]); |
890 | array_free (pending, [i]); |
864 | |
891 | |
… | |
… | |
877 | |
904 | |
878 | static void |
905 | static void |
879 | loop_fork (EV_P) |
906 | loop_fork (EV_P) |
880 | { |
907 | { |
881 | #if EV_USE_PORT |
908 | #if EV_USE_PORT |
882 | if (method == EVMETHOD_PORT ) port_fork (EV_A); |
909 | if (method == EVBACKEND_PORT ) port_fork (EV_A); |
883 | #endif |
910 | #endif |
884 | #if EV_USE_KQUEUE |
911 | #if EV_USE_KQUEUE |
885 | if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); |
912 | if (method == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
886 | #endif |
913 | #endif |
887 | #if EV_USE_EPOLL |
914 | #if EV_USE_EPOLL |
888 | if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); |
915 | if (method == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
889 | #endif |
916 | #endif |
890 | |
917 | |
891 | if (ev_is_active (&sigev)) |
918 | if (ev_is_active (&sigev)) |
892 | { |
919 | { |
893 | /* default loop */ |
920 | /* default loop */ |