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

Comparing libev/ev.c (file contents):
Revision 1.128 by root, Thu Nov 22 12:28:27 2007 UTC vs.
Revision 1.132 by root, Fri Nov 23 10:36:30 2007 UTC

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
464 } 458 }
465#endif 459#endif
466 460
467 anfd->reify = 0; 461 anfd->reify = 0;
468 462
469 method_modify (EV_A_ fd, anfd->events, events); 463 backend_modify (EV_A_ fd, anfd->events, events);
470 anfd->events = events; 464 anfd->events = events;
471 } 465 }
472 466
473 fdchangecnt = 0; 467 fdchangecnt = 0;
474} 468}
532 fd_kill (EV_A_ fd); 526 fd_kill (EV_A_ fd);
533 return; 527 return;
534 } 528 }
535} 529}
536 530
537/* 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 */
538static void 532static void
539fd_rearm_all (EV_P) 533fd_rearm_all (EV_P)
540{ 534{
541 int fd; 535 int fd;
542 536
733 int pid, status; 727 int pid, status;
734 728
735 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 729 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
736 { 730 {
737 /* 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 */
738 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); 733 ev_feed_event (EV_A_ (W)sw, EV_SIGNAL);
739 734
740 child_reap (EV_A_ sw, pid, pid, status); 735 child_reap (EV_A_ sw, pid, pid, status);
741 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 */
742 } 737 }
743} 738}
744 739
745#endif 740#endif
746 741
785 || getgid () != getegid (); 780 || getgid () != getegid ();
786#endif 781#endif
787} 782}
788 783
789unsigned int 784unsigned int
790ev_method (EV_P) 785ev_supported_backends (void)
791{ 786{
792 return method; 787 unsigned int flags = 0;
788
789 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
790 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
791 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
792 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
793 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT;
794
795 return flags;
796}
797
798unsigned int
799ev_recommended_backends (void)
800{
801 unsigned int flags = ev_supported_backends ();
802
803#ifndef __NetBSD__
804 /* kqueue is borked on everything but netbsd apparently */
805 /* it usually doesn't work correctly on anything but sockets and pipes */
806 flags &= ~EVBACKEND_KQUEUE;
807#endif
808#ifdef __APPLE__
809 // flags &= ~EVBACKEND_KQUEUE; for documentation
810 flags &= ~EVBACKEND_POLL;
811#endif
812
813 return flags;
814}
815
816unsigned int
817ev_backend (EV_P)
818{
819 return backend;
793} 820}
794 821
795static void 822static void
796loop_init (EV_P_ unsigned int flags) 823loop_init (EV_P_ unsigned int flags)
797{ 824{
798 if (!method) 825 if (!backend)
799 { 826 {
800#if EV_USE_MONOTONIC 827#if EV_USE_MONOTONIC
801 { 828 {
802 struct timespec ts; 829 struct timespec ts;
803 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 830 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
813 if (!(flags & EVFLAG_NOENV) 840 if (!(flags & EVFLAG_NOENV)
814 && !enable_secure () 841 && !enable_secure ()
815 && getenv ("LIBEV_FLAGS")) 842 && getenv ("LIBEV_FLAGS"))
816 flags = atoi (getenv ("LIBEV_FLAGS")); 843 flags = atoi (getenv ("LIBEV_FLAGS"));
817 844
818 if (!(flags & EVMETHOD_ALL)) 845 if (!(flags & 0x0000ffffUL))
819 { 846 flags |= ev_recommended_backends ();
820 flags |= EVMETHOD_ALL;
821#if EV_USE_KQUEUE && !defined (__NetBSD__)
822 /* kqueue is borked on everything but netbsd apparently */
823 /* it usually doesn't work correctly on anything but sockets and pipes */
824 flags &= ~EVMETHOD_KQUEUE;
825#endif
826 }
827 847
828 method = 0; 848 backend = 0;
829#if EV_USE_PORT 849#if EV_USE_PORT
830 if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags); 850 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
831#endif 851#endif
832#if EV_USE_KQUEUE 852#if EV_USE_KQUEUE
833 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); 853 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags);
834#endif 854#endif
835#if EV_USE_EPOLL 855#if EV_USE_EPOLL
836 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); 856 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
837#endif 857#endif
838#if EV_USE_POLL 858#if EV_USE_POLL
839 if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); 859 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
840#endif 860#endif
841#if EV_USE_SELECT 861#if EV_USE_SELECT
842 if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); 862 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags);
843#endif 863#endif
844 864
845 ev_init (&sigev, sigcb); 865 ev_init (&sigev, sigcb);
846 ev_set_priority (&sigev, EV_MAXPRI); 866 ev_set_priority (&sigev, EV_MAXPRI);
847 } 867 }
851loop_destroy (EV_P) 871loop_destroy (EV_P)
852{ 872{
853 int i; 873 int i;
854 874
855#if EV_USE_PORT 875#if EV_USE_PORT
856 if (method == EVMETHOD_PORT ) port_destroy (EV_A); 876 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
857#endif 877#endif
858#if EV_USE_KQUEUE 878#if EV_USE_KQUEUE
859 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 879 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A);
860#endif 880#endif
861#if EV_USE_EPOLL 881#if EV_USE_EPOLL
862 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 882 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
863#endif 883#endif
864#if EV_USE_POLL 884#if EV_USE_POLL
865 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 885 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
866#endif 886#endif
867#if EV_USE_SELECT 887#if EV_USE_SELECT
868 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 888 if (backend == EVBACKEND_SELECT) select_destroy (EV_A);
869#endif 889#endif
870 890
871 for (i = NUMPRI; i--; ) 891 for (i = NUMPRI; i--; )
872 array_free (pending, [i]); 892 array_free (pending, [i]);
873 893
879#endif 899#endif
880 array_free (idle, EMPTY0); 900 array_free (idle, EMPTY0);
881 array_free (prepare, EMPTY0); 901 array_free (prepare, EMPTY0);
882 array_free (check, EMPTY0); 902 array_free (check, EMPTY0);
883 903
884 method = 0; 904 backend = 0;
885} 905}
886 906
887static void 907static void
888loop_fork (EV_P) 908loop_fork (EV_P)
889{ 909{
890#if EV_USE_PORT 910#if EV_USE_PORT
891 if (method == EVMETHOD_PORT ) port_fork (EV_A); 911 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
892#endif 912#endif
893#if EV_USE_KQUEUE 913#if EV_USE_KQUEUE
894 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 914 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A);
895#endif 915#endif
896#if EV_USE_EPOLL 916#if EV_USE_EPOLL
897 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 917 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
898#endif 918#endif
899 919
900 if (ev_is_active (&sigev)) 920 if (ev_is_active (&sigev))
901 { 921 {
902 /* default loop */ 922 /* default loop */
923 943
924 memset (loop, 0, sizeof (struct ev_loop)); 944 memset (loop, 0, sizeof (struct ev_loop));
925 945
926 loop_init (EV_A_ flags); 946 loop_init (EV_A_ flags);
927 947
928 if (ev_method (EV_A)) 948 if (ev_backend (EV_A))
929 return loop; 949 return loop;
930 950
931 return 0; 951 return 0;
932} 952}
933 953
966 ev_default_loop_ptr = 1; 986 ev_default_loop_ptr = 1;
967#endif 987#endif
968 988
969 loop_init (EV_A_ flags); 989 loop_init (EV_A_ flags);
970 990
971 if (ev_method (EV_A)) 991 if (ev_backend (EV_A))
972 { 992 {
973 siginit (EV_A); 993 siginit (EV_A);
974 994
975#ifndef _WIN32 995#ifndef _WIN32
976 ev_signal_init (&childev, childcb, SIGCHLD); 996 ev_signal_init (&childev, childcb, SIGCHLD);
1012{ 1032{
1013#if EV_MULTIPLICITY 1033#if EV_MULTIPLICITY
1014 struct ev_loop *loop = ev_default_loop_ptr; 1034 struct ev_loop *loop = ev_default_loop_ptr;
1015#endif 1035#endif
1016 1036
1017 if (method) 1037 if (backend)
1018 postfork = 1; 1038 postfork = 1;
1019} 1039}
1020 1040
1021/*****************************************************************************/ 1041/*****************************************************************************/
1022 1042
1254 { 1274 {
1255 block = MAX_BLOCKTIME; 1275 block = MAX_BLOCKTIME;
1256 1276
1257 if (timercnt) 1277 if (timercnt)
1258 { 1278 {
1259 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; 1279 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge;
1260 if (block > to) block = to; 1280 if (block > to) block = to;
1261 } 1281 }
1262 1282
1263#if EV_PERIODICS 1283#if EV_PERIODICS
1264 if (periodiccnt) 1284 if (periodiccnt)
1265 { 1285 {
1266 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;
1267 if (block > to) block = to; 1287 if (block > to) block = to;
1268 } 1288 }
1269#endif 1289#endif
1270 1290
1271 if (expect_false (block < 0.)) block = 0.; 1291 if (expect_false (block < 0.)) block = 0.;
1272 } 1292 }
1273 1293
1274 method_poll (EV_A_ block); 1294 backend_poll (EV_A_ block);
1275 1295
1276 /* update ev_rt_now, do magic */ 1296 /* update ev_rt_now, do magic */
1277 time_update (EV_A); 1297 time_update (EV_A);
1278 1298
1279 /* queue pending timers and reschedule them */ 1299 /* queue pending timers and reschedule them */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines