… | |
… | |
458 | } |
458 | } |
459 | #endif |
459 | #endif |
460 | |
460 | |
461 | anfd->reify = 0; |
461 | anfd->reify = 0; |
462 | |
462 | |
463 | method_modify (EV_A_ fd, anfd->events, events); |
463 | backend_modify (EV_A_ fd, anfd->events, events); |
464 | anfd->events = events; |
464 | anfd->events = events; |
465 | } |
465 | } |
466 | |
466 | |
467 | fdchangecnt = 0; |
467 | fdchangecnt = 0; |
468 | } |
468 | } |
… | |
… | |
526 | fd_kill (EV_A_ fd); |
526 | fd_kill (EV_A_ fd); |
527 | return; |
527 | return; |
528 | } |
528 | } |
529 | } |
529 | } |
530 | |
530 | |
531 | /* usually called after fork if method needs to re-arm all fds from scratch */ |
531 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
532 | static void |
532 | static void |
533 | fd_rearm_all (EV_P) |
533 | fd_rearm_all (EV_P) |
534 | { |
534 | { |
535 | int fd; |
535 | int fd; |
536 | |
536 | |
… | |
… | |
781 | } |
781 | } |
782 | |
782 | |
783 | unsigned int |
783 | unsigned int |
784 | ev_supported_backends (void) |
784 | ev_supported_backends (void) |
785 | { |
785 | { |
786 | } |
|
|
787 | |
|
|
788 | unsigned int |
|
|
789 | ev_recommended_backends (void) |
|
|
790 | { |
|
|
791 | unsigned int flags; |
786 | unsigned int flags = 0; |
792 | |
787 | |
793 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
788 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
794 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
789 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
795 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
790 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
796 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
791 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
… | |
… | |
798 | |
793 | |
799 | return flags; |
794 | return flags; |
800 | } |
795 | } |
801 | |
796 | |
802 | unsigned int |
797 | unsigned int |
803 | ev_backend (EV_P) |
798 | ev_recommended_backends (void) |
804 | { |
799 | { |
805 | unsigned int flags = ev_recommended_backends (); |
800 | unsigned int flags = ev_recommended_backends (); |
806 | |
801 | |
807 | #ifndef __NetBSD__ |
802 | #ifndef __NetBSD__ |
808 | /* kqueue is borked on everything but netbsd apparently */ |
803 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
815 | #endif |
810 | #endif |
816 | |
811 | |
817 | return flags; |
812 | return flags; |
818 | } |
813 | } |
819 | |
814 | |
|
|
815 | unsigned int |
|
|
816 | ev_backend (EV_P) |
|
|
817 | { |
|
|
818 | return backend; |
|
|
819 | } |
|
|
820 | |
820 | static void |
821 | static void |
821 | loop_init (EV_P_ unsigned int flags) |
822 | loop_init (EV_P_ unsigned int flags) |
822 | { |
823 | { |
823 | if (!method) |
824 | if (!backend) |
824 | { |
825 | { |
825 | #if EV_USE_MONOTONIC |
826 | #if EV_USE_MONOTONIC |
826 | { |
827 | { |
827 | struct timespec ts; |
828 | struct timespec ts; |
828 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
829 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
… | |
… | |
841 | flags = atoi (getenv ("LIBEV_FLAGS")); |
842 | flags = atoi (getenv ("LIBEV_FLAGS")); |
842 | |
843 | |
843 | if (!(flags & 0x0000ffffUL)) |
844 | if (!(flags & 0x0000ffffUL)) |
844 | flags |= ev_recommended_backends (); |
845 | flags |= ev_recommended_backends (); |
845 | |
846 | |
846 | method = 0; |
847 | backend = 0; |
847 | #if EV_USE_PORT |
848 | #if EV_USE_PORT |
848 | if (!method && (flags & EVBACKEND_PORT )) method = port_init (EV_A_ flags); |
849 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
849 | #endif |
850 | #endif |
850 | #if EV_USE_KQUEUE |
851 | #if EV_USE_KQUEUE |
851 | if (!method && (flags & EVBACKEND_KQUEUE)) method = kqueue_init (EV_A_ flags); |
852 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
852 | #endif |
853 | #endif |
853 | #if EV_USE_EPOLL |
854 | #if EV_USE_EPOLL |
854 | if (!method && (flags & EVBACKEND_EPOLL )) method = epoll_init (EV_A_ flags); |
855 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
855 | #endif |
856 | #endif |
856 | #if EV_USE_POLL |
857 | #if EV_USE_POLL |
857 | if (!method && (flags & EVBACKEND_POLL )) method = poll_init (EV_A_ flags); |
858 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
858 | #endif |
859 | #endif |
859 | #if EV_USE_SELECT |
860 | #if EV_USE_SELECT |
860 | if (!method && (flags & EVBACKEND_SELECT)) method = select_init (EV_A_ flags); |
861 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
861 | #endif |
862 | #endif |
862 | |
863 | |
863 | ev_init (&sigev, sigcb); |
864 | ev_init (&sigev, sigcb); |
864 | ev_set_priority (&sigev, EV_MAXPRI); |
865 | ev_set_priority (&sigev, EV_MAXPRI); |
865 | } |
866 | } |
… | |
… | |
869 | loop_destroy (EV_P) |
870 | loop_destroy (EV_P) |
870 | { |
871 | { |
871 | int i; |
872 | int i; |
872 | |
873 | |
873 | #if EV_USE_PORT |
874 | #if EV_USE_PORT |
874 | if (method == EVBACKEND_PORT ) port_destroy (EV_A); |
875 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
875 | #endif |
876 | #endif |
876 | #if EV_USE_KQUEUE |
877 | #if EV_USE_KQUEUE |
877 | if (method == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
878 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
878 | #endif |
879 | #endif |
879 | #if EV_USE_EPOLL |
880 | #if EV_USE_EPOLL |
880 | if (method == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
881 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
881 | #endif |
882 | #endif |
882 | #if EV_USE_POLL |
883 | #if EV_USE_POLL |
883 | if (method == EVBACKEND_POLL ) poll_destroy (EV_A); |
884 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
884 | #endif |
885 | #endif |
885 | #if EV_USE_SELECT |
886 | #if EV_USE_SELECT |
886 | if (method == EVBACKEND_SELECT) select_destroy (EV_A); |
887 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
887 | #endif |
888 | #endif |
888 | |
889 | |
889 | for (i = NUMPRI; i--; ) |
890 | for (i = NUMPRI; i--; ) |
890 | array_free (pending, [i]); |
891 | array_free (pending, [i]); |
891 | |
892 | |
… | |
… | |
897 | #endif |
898 | #endif |
898 | array_free (idle, EMPTY0); |
899 | array_free (idle, EMPTY0); |
899 | array_free (prepare, EMPTY0); |
900 | array_free (prepare, EMPTY0); |
900 | array_free (check, EMPTY0); |
901 | array_free (check, EMPTY0); |
901 | |
902 | |
902 | method = 0; |
903 | backend = 0; |
903 | } |
904 | } |
904 | |
905 | |
905 | static void |
906 | static void |
906 | loop_fork (EV_P) |
907 | loop_fork (EV_P) |
907 | { |
908 | { |
908 | #if EV_USE_PORT |
909 | #if EV_USE_PORT |
909 | if (method == EVBACKEND_PORT ) port_fork (EV_A); |
910 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
910 | #endif |
911 | #endif |
911 | #if EV_USE_KQUEUE |
912 | #if EV_USE_KQUEUE |
912 | if (method == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
913 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
913 | #endif |
914 | #endif |
914 | #if EV_USE_EPOLL |
915 | #if EV_USE_EPOLL |
915 | if (method == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
916 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
916 | #endif |
917 | #endif |
917 | |
918 | |
918 | if (ev_is_active (&sigev)) |
919 | if (ev_is_active (&sigev)) |
919 | { |
920 | { |
920 | /* default loop */ |
921 | /* default loop */ |
… | |
… | |
941 | |
942 | |
942 | memset (loop, 0, sizeof (struct ev_loop)); |
943 | memset (loop, 0, sizeof (struct ev_loop)); |
943 | |
944 | |
944 | loop_init (EV_A_ flags); |
945 | loop_init (EV_A_ flags); |
945 | |
946 | |
946 | if (ev_method (EV_A)) |
947 | if (ev_backend (EV_A)) |
947 | return loop; |
948 | return loop; |
948 | |
949 | |
949 | return 0; |
950 | return 0; |
950 | } |
951 | } |
951 | |
952 | |
… | |
… | |
984 | ev_default_loop_ptr = 1; |
985 | ev_default_loop_ptr = 1; |
985 | #endif |
986 | #endif |
986 | |
987 | |
987 | loop_init (EV_A_ flags); |
988 | loop_init (EV_A_ flags); |
988 | |
989 | |
989 | if (ev_method (EV_A)) |
990 | if (ev_backend (EV_A)) |
990 | { |
991 | { |
991 | siginit (EV_A); |
992 | siginit (EV_A); |
992 | |
993 | |
993 | #ifndef _WIN32 |
994 | #ifndef _WIN32 |
994 | ev_signal_init (&childev, childcb, SIGCHLD); |
995 | ev_signal_init (&childev, childcb, SIGCHLD); |
… | |
… | |
1030 | { |
1031 | { |
1031 | #if EV_MULTIPLICITY |
1032 | #if EV_MULTIPLICITY |
1032 | struct ev_loop *loop = ev_default_loop_ptr; |
1033 | struct ev_loop *loop = ev_default_loop_ptr; |
1033 | #endif |
1034 | #endif |
1034 | |
1035 | |
1035 | if (method) |
1036 | if (backend) |
1036 | postfork = 1; |
1037 | postfork = 1; |
1037 | } |
1038 | } |
1038 | |
1039 | |
1039 | /*****************************************************************************/ |
1040 | /*****************************************************************************/ |
1040 | |
1041 | |
… | |
… | |
1272 | { |
1273 | { |
1273 | block = MAX_BLOCKTIME; |
1274 | block = MAX_BLOCKTIME; |
1274 | |
1275 | |
1275 | if (timercnt) |
1276 | if (timercnt) |
1276 | { |
1277 | { |
1277 | ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; |
1278 | ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; |
1278 | if (block > to) block = to; |
1279 | if (block > to) block = to; |
1279 | } |
1280 | } |
1280 | |
1281 | |
1281 | #if EV_PERIODICS |
1282 | #if EV_PERIODICS |
1282 | if (periodiccnt) |
1283 | if (periodiccnt) |
1283 | { |
1284 | { |
1284 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; |
1285 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; |
1285 | if (block > to) block = to; |
1286 | if (block > to) block = to; |
1286 | } |
1287 | } |
1287 | #endif |
1288 | #endif |
1288 | |
1289 | |
1289 | if (expect_false (block < 0.)) block = 0.; |
1290 | if (expect_false (block < 0.)) block = 0.; |
1290 | } |
1291 | } |
1291 | |
1292 | |
1292 | method_poll (EV_A_ block); |
1293 | backend_poll (EV_A_ block); |
1293 | |
1294 | |
1294 | /* update ev_rt_now, do magic */ |
1295 | /* update ev_rt_now, do magic */ |
1295 | time_update (EV_A); |
1296 | time_update (EV_A); |
1296 | |
1297 | |
1297 | /* queue pending timers and reschedule them */ |
1298 | /* queue pending timers and reschedule them */ |