ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.129 by root, Fri Nov 23 05:00:44 2007 UTC vs.
Revision 1.132 by root, Fri Nov 23 10:36:30 2007 UTC

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 */
532static void 532static void
533fd_rearm_all (EV_P) 533fd_rearm_all (EV_P)
534{ 534{
535 int fd; 535 int fd;
536 536
727 int pid, status; 727 int pid, status;
728 728
729 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 729 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
730 { 730 {
731 /* make sure we are called again until all childs have been reaped */ 731 /* make sure we are called again until all childs have been reaped */
732 /* we need to do it this way so that the callback gets called before we continue */
732 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 733 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
733 734
734 child_reap (EV_A_ sw, pid, pid, status); 735 child_reap (EV_A_ sw, pid, pid, status);
735 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ 736 child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */
736 } 737 }
737} 738}
738 739
739#endif 740#endif
740 741
781} 782}
782 783
783unsigned int 784unsigned int
784ev_supported_backends (void) 785ev_supported_backends (void)
785{ 786{
786}
787
788unsigned int
789ev_recommended_backends (void)
790{
791 unsigned int flags; 787 unsigned int flags = 0;
792 788
793 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 789 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
794 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 790 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
795 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; 791 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
796 if (EV_USE_POLL ) flags |= EVBACKEND_POLL; 792 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
798 794
799 return flags; 795 return flags;
800} 796}
801 797
802unsigned int 798unsigned int
803ev_backend (EV_P) 799ev_recommended_backends (void)
804{ 800{
805 unsigned int flags = ev_recommended_backends (); 801 unsigned int flags = ev_supported_backends ();
806 802
807#ifndef __NetBSD__ 803#ifndef __NetBSD__
808 /* kqueue is borked on everything but netbsd apparently */ 804 /* kqueue is borked on everything but netbsd apparently */
809 /* it usually doesn't work correctly on anything but sockets and pipes */ 805 /* it usually doesn't work correctly on anything but sockets and pipes */
810 flags &= ~EVBACKEND_KQUEUE; 806 flags &= ~EVBACKEND_KQUEUE;
815#endif 811#endif
816 812
817 return flags; 813 return flags;
818} 814}
819 815
816unsigned int
817ev_backend (EV_P)
818{
819 return backend;
820}
821
820static void 822static void
821loop_init (EV_P_ unsigned int flags) 823loop_init (EV_P_ unsigned int flags)
822{ 824{
823 if (!method) 825 if (!backend)
824 { 826 {
825#if EV_USE_MONOTONIC 827#if EV_USE_MONOTONIC
826 { 828 {
827 struct timespec ts; 829 struct timespec ts;
828 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 830 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
841 flags = atoi (getenv ("LIBEV_FLAGS")); 843 flags = atoi (getenv ("LIBEV_FLAGS"));
842 844
843 if (!(flags & 0x0000ffffUL)) 845 if (!(flags & 0x0000ffffUL))
844 flags |= ev_recommended_backends (); 846 flags |= ev_recommended_backends ();
845 847
846 method = 0; 848 backend = 0;
847#if EV_USE_PORT 849#if EV_USE_PORT
848 if (!method && (flags & EVBACKEND_PORT )) method = port_init (EV_A_ flags); 850 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
849#endif 851#endif
850#if EV_USE_KQUEUE 852#if EV_USE_KQUEUE
851 if (!method && (flags & EVBACKEND_KQUEUE)) method = kqueue_init (EV_A_ flags); 853 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags);
852#endif 854#endif
853#if EV_USE_EPOLL 855#if EV_USE_EPOLL
854 if (!method && (flags & EVBACKEND_EPOLL )) method = epoll_init (EV_A_ flags); 856 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
855#endif 857#endif
856#if EV_USE_POLL 858#if EV_USE_POLL
857 if (!method && (flags & EVBACKEND_POLL )) method = poll_init (EV_A_ flags); 859 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
858#endif 860#endif
859#if EV_USE_SELECT 861#if EV_USE_SELECT
860 if (!method && (flags & EVBACKEND_SELECT)) method = select_init (EV_A_ flags); 862 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags);
861#endif 863#endif
862 864
863 ev_init (&sigev, sigcb); 865 ev_init (&sigev, sigcb);
864 ev_set_priority (&sigev, EV_MAXPRI); 866 ev_set_priority (&sigev, EV_MAXPRI);
865 } 867 }
869loop_destroy (EV_P) 871loop_destroy (EV_P)
870{ 872{
871 int i; 873 int i;
872 874
873#if EV_USE_PORT 875#if EV_USE_PORT
874 if (method == EVBACKEND_PORT ) port_destroy (EV_A); 876 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
875#endif 877#endif
876#if EV_USE_KQUEUE 878#if EV_USE_KQUEUE
877 if (method == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); 879 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A);
878#endif 880#endif
879#if EV_USE_EPOLL 881#if EV_USE_EPOLL
880 if (method == EVBACKEND_EPOLL ) epoll_destroy (EV_A); 882 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
881#endif 883#endif
882#if EV_USE_POLL 884#if EV_USE_POLL
883 if (method == EVBACKEND_POLL ) poll_destroy (EV_A); 885 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
884#endif 886#endif
885#if EV_USE_SELECT 887#if EV_USE_SELECT
886 if (method == EVBACKEND_SELECT) select_destroy (EV_A); 888 if (backend == EVBACKEND_SELECT) select_destroy (EV_A);
887#endif 889#endif
888 890
889 for (i = NUMPRI; i--; ) 891 for (i = NUMPRI; i--; )
890 array_free (pending, [i]); 892 array_free (pending, [i]);
891 893
897#endif 899#endif
898 array_free (idle, EMPTY0); 900 array_free (idle, EMPTY0);
899 array_free (prepare, EMPTY0); 901 array_free (prepare, EMPTY0);
900 array_free (check, EMPTY0); 902 array_free (check, EMPTY0);
901 903
902 method = 0; 904 backend = 0;
903} 905}
904 906
905static void 907static void
906loop_fork (EV_P) 908loop_fork (EV_P)
907{ 909{
908#if EV_USE_PORT 910#if EV_USE_PORT
909 if (method == EVBACKEND_PORT ) port_fork (EV_A); 911 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
910#endif 912#endif
911#if EV_USE_KQUEUE 913#if EV_USE_KQUEUE
912 if (method == EVBACKEND_KQUEUE) kqueue_fork (EV_A); 914 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A);
913#endif 915#endif
914#if EV_USE_EPOLL 916#if EV_USE_EPOLL
915 if (method == EVBACKEND_EPOLL ) epoll_fork (EV_A); 917 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
916#endif 918#endif
917 919
918 if (ev_is_active (&sigev)) 920 if (ev_is_active (&sigev))
919 { 921 {
920 /* default loop */ 922 /* default loop */
941 943
942 memset (loop, 0, sizeof (struct ev_loop)); 944 memset (loop, 0, sizeof (struct ev_loop));
943 945
944 loop_init (EV_A_ flags); 946 loop_init (EV_A_ flags);
945 947
946 if (ev_method (EV_A)) 948 if (ev_backend (EV_A))
947 return loop; 949 return loop;
948 950
949 return 0; 951 return 0;
950} 952}
951 953
984 ev_default_loop_ptr = 1; 986 ev_default_loop_ptr = 1;
985#endif 987#endif
986 988
987 loop_init (EV_A_ flags); 989 loop_init (EV_A_ flags);
988 990
989 if (ev_method (EV_A)) 991 if (ev_backend (EV_A))
990 { 992 {
991 siginit (EV_A); 993 siginit (EV_A);
992 994
993#ifndef _WIN32 995#ifndef _WIN32
994 ev_signal_init (&childev, childcb, SIGCHLD); 996 ev_signal_init (&childev, childcb, SIGCHLD);
1030{ 1032{
1031#if EV_MULTIPLICITY 1033#if EV_MULTIPLICITY
1032 struct ev_loop *loop = ev_default_loop_ptr; 1034 struct ev_loop *loop = ev_default_loop_ptr;
1033#endif 1035#endif
1034 1036
1035 if (method) 1037 if (backend)
1036 postfork = 1; 1038 postfork = 1;
1037} 1039}
1038 1040
1039/*****************************************************************************/ 1041/*****************************************************************************/
1040 1042
1272 { 1274 {
1273 block = MAX_BLOCKTIME; 1275 block = MAX_BLOCKTIME;
1274 1276
1275 if (timercnt) 1277 if (timercnt)
1276 { 1278 {
1277 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; 1279 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge;
1278 if (block > to) block = to; 1280 if (block > to) block = to;
1279 } 1281 }
1280 1282
1281#if EV_PERIODICS 1283#if EV_PERIODICS
1282 if (periodiccnt) 1284 if (periodiccnt)
1283 { 1285 {
1284 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; 1286 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge;
1285 if (block > to) block = to; 1287 if (block > to) block = to;
1286 } 1288 }
1287#endif 1289#endif
1288 1290
1289 if (expect_false (block < 0.)) block = 0.; 1291 if (expect_false (block < 0.)) block = 0.;
1290 } 1292 }
1291 1293
1292 method_poll (EV_A_ block); 1294 backend_poll (EV_A_ block);
1293 1295
1294 /* update ev_rt_now, do magic */ 1296 /* update ev_rt_now, do magic */
1295 time_update (EV_A); 1297 time_update (EV_A);
1296 1298
1297 /* queue pending timers and reschedule them */ 1299 /* queue pending timers and reschedule them */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines