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

Comparing libev/ev.c (file contents):
Revision 1.127 by root, Sun Nov 18 02:17:57 2007 UTC vs.
Revision 1.131 by root, Fri Nov 23 05:43:45 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
785 || getgid () != getegid (); 779 || getgid () != getegid ();
786#endif 780#endif
787} 781}
788 782
789unsigned int 783unsigned int
790ev_method (EV_P) 784ev_supported_backends (void)
791{ 785{
792 return method; 786 unsigned int flags = 0;
787
788 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
789 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
790 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
791 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
792 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT;
793
794 return flags;
795}
796
797unsigned int
798ev_recommended_backends (void)
799{
800 unsigned int flags = ev_supported_backends ();
801
802#ifndef __NetBSD__
803 /* kqueue is borked on everything but netbsd apparently */
804 /* it usually doesn't work correctly on anything but sockets and pipes */
805 flags &= ~EVBACKEND_KQUEUE;
806#endif
807#ifdef __APPLE__
808 // flags &= ~EVBACKEND_KQUEUE; for documentation
809 flags &= ~EVBACKEND_POLL;
810#endif
811
812 return flags;
813}
814
815unsigned int
816ev_backend (EV_P)
817{
818 return backend;
793} 819}
794 820
795static void 821static void
796loop_init (EV_P_ unsigned int flags) 822loop_init (EV_P_ unsigned int flags)
797{ 823{
798 if (!method) 824 if (!backend)
799 { 825 {
800#if EV_USE_MONOTONIC 826#if EV_USE_MONOTONIC
801 { 827 {
802 struct timespec ts; 828 struct timespec ts;
803 if (!clock_gettime (CLOCK_MONOTONIC, &ts)) 829 if (!clock_gettime (CLOCK_MONOTONIC, &ts))
808 ev_rt_now = ev_time (); 834 ev_rt_now = ev_time ();
809 mn_now = get_clock (); 835 mn_now = get_clock ();
810 now_floor = mn_now; 836 now_floor = mn_now;
811 rtmn_diff = ev_rt_now - mn_now; 837 rtmn_diff = ev_rt_now - mn_now;
812 838
813 if (!(flags & EVFLAG_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS")) 839 if (!(flags & EVFLAG_NOENV)
840 && !enable_secure ()
841 && getenv ("LIBEV_FLAGS"))
814 flags = atoi (getenv ("LIBEV_FLAGS")); 842 flags = atoi (getenv ("LIBEV_FLAGS"));
815 843
816 if (!(flags & 0x0000ffff)) 844 if (!(flags & 0x0000ffffUL))
817 flags |= 0x0000ffff; 845 flags |= ev_recommended_backends ();
818 846
819 method = 0; 847 backend = 0;
820#if EV_USE_PORT 848#if EV_USE_PORT
821 if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags); 849 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
822#endif 850#endif
823#if EV_USE_KQUEUE 851#if EV_USE_KQUEUE
824 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); 852 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags);
825#endif 853#endif
826#if EV_USE_EPOLL 854#if EV_USE_EPOLL
827 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); 855 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
828#endif 856#endif
829#if EV_USE_POLL 857#if EV_USE_POLL
830 if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); 858 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
831#endif 859#endif
832#if EV_USE_SELECT 860#if EV_USE_SELECT
833 if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); 861 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags);
834#endif 862#endif
835 863
836 ev_init (&sigev, sigcb); 864 ev_init (&sigev, sigcb);
837 ev_set_priority (&sigev, EV_MAXPRI); 865 ev_set_priority (&sigev, EV_MAXPRI);
838 } 866 }
842loop_destroy (EV_P) 870loop_destroy (EV_P)
843{ 871{
844 int i; 872 int i;
845 873
846#if EV_USE_PORT 874#if EV_USE_PORT
847 if (method == EVMETHOD_PORT ) port_destroy (EV_A); 875 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
848#endif 876#endif
849#if EV_USE_KQUEUE 877#if EV_USE_KQUEUE
850 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 878 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A);
851#endif 879#endif
852#if EV_USE_EPOLL 880#if EV_USE_EPOLL
853 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 881 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
854#endif 882#endif
855#if EV_USE_POLL 883#if EV_USE_POLL
856 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 884 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
857#endif 885#endif
858#if EV_USE_SELECT 886#if EV_USE_SELECT
859 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 887 if (backend == EVBACKEND_SELECT) select_destroy (EV_A);
860#endif 888#endif
861 889
862 for (i = NUMPRI; i--; ) 890 for (i = NUMPRI; i--; )
863 array_free (pending, [i]); 891 array_free (pending, [i]);
864 892
870#endif 898#endif
871 array_free (idle, EMPTY0); 899 array_free (idle, EMPTY0);
872 array_free (prepare, EMPTY0); 900 array_free (prepare, EMPTY0);
873 array_free (check, EMPTY0); 901 array_free (check, EMPTY0);
874 902
875 method = 0; 903 backend = 0;
876} 904}
877 905
878static void 906static void
879loop_fork (EV_P) 907loop_fork (EV_P)
880{ 908{
881#if EV_USE_PORT 909#if EV_USE_PORT
882 if (method == EVMETHOD_PORT ) port_fork (EV_A); 910 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
883#endif 911#endif
884#if EV_USE_KQUEUE 912#if EV_USE_KQUEUE
885 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 913 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A);
886#endif 914#endif
887#if EV_USE_EPOLL 915#if EV_USE_EPOLL
888 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 916 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
889#endif 917#endif
890 918
891 if (ev_is_active (&sigev)) 919 if (ev_is_active (&sigev))
892 { 920 {
893 /* default loop */ 921 /* default loop */
914 942
915 memset (loop, 0, sizeof (struct ev_loop)); 943 memset (loop, 0, sizeof (struct ev_loop));
916 944
917 loop_init (EV_A_ flags); 945 loop_init (EV_A_ flags);
918 946
919 if (ev_method (EV_A)) 947 if (ev_backend (EV_A))
920 return loop; 948 return loop;
921 949
922 return 0; 950 return 0;
923} 951}
924 952
957 ev_default_loop_ptr = 1; 985 ev_default_loop_ptr = 1;
958#endif 986#endif
959 987
960 loop_init (EV_A_ flags); 988 loop_init (EV_A_ flags);
961 989
962 if (ev_method (EV_A)) 990 if (ev_backend (EV_A))
963 { 991 {
964 siginit (EV_A); 992 siginit (EV_A);
965 993
966#ifndef _WIN32 994#ifndef _WIN32
967 ev_signal_init (&childev, childcb, SIGCHLD); 995 ev_signal_init (&childev, childcb, SIGCHLD);
1003{ 1031{
1004#if EV_MULTIPLICITY 1032#if EV_MULTIPLICITY
1005 struct ev_loop *loop = ev_default_loop_ptr; 1033 struct ev_loop *loop = ev_default_loop_ptr;
1006#endif 1034#endif
1007 1035
1008 if (method) 1036 if (backend)
1009 postfork = 1; 1037 postfork = 1;
1010} 1038}
1011 1039
1012/*****************************************************************************/ 1040/*****************************************************************************/
1013 1041
1245 { 1273 {
1246 block = MAX_BLOCKTIME; 1274 block = MAX_BLOCKTIME;
1247 1275
1248 if (timercnt) 1276 if (timercnt)
1249 { 1277 {
1250 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; 1278 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge;
1251 if (block > to) block = to; 1279 if (block > to) block = to;
1252 } 1280 }
1253 1281
1254#if EV_PERIODICS 1282#if EV_PERIODICS
1255 if (periodiccnt) 1283 if (periodiccnt)
1256 { 1284 {
1257 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;
1258 if (block > to) block = to; 1286 if (block > to) block = to;
1259 } 1287 }
1260#endif 1288#endif
1261 1289
1262 if (expect_false (block < 0.)) block = 0.; 1290 if (expect_false (block < 0.)) block = 0.;
1263 } 1291 }
1264 1292
1265 method_poll (EV_A_ block); 1293 backend_poll (EV_A_ block);
1266 1294
1267 /* update ev_rt_now, do magic */ 1295 /* update ev_rt_now, do magic */
1268 time_update (EV_A); 1296 time_update (EV_A);
1269 1297
1270 /* queue pending timers and reschedule them */ 1298 /* queue pending timers and reschedule them */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines