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.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))
813 if (!(flags & EVFLAG_NOENV) 839 if (!(flags & EVFLAG_NOENV)
814 && !enable_secure () 840 && !enable_secure ()
815 && getenv ("LIBEV_FLAGS")) 841 && getenv ("LIBEV_FLAGS"))
816 flags = atoi (getenv ("LIBEV_FLAGS")); 842 flags = atoi (getenv ("LIBEV_FLAGS"));
817 843
818 if (!(flags & EVMETHOD_ALL)) 844 if (!(flags & 0x0000ffffUL))
819 { 845 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 846
828 method = 0; 847 backend = 0;
829#if EV_USE_PORT 848#if EV_USE_PORT
830 if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags); 849 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
831#endif 850#endif
832#if EV_USE_KQUEUE 851#if EV_USE_KQUEUE
833 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); 852 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags);
834#endif 853#endif
835#if EV_USE_EPOLL 854#if EV_USE_EPOLL
836 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); 855 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
837#endif 856#endif
838#if EV_USE_POLL 857#if EV_USE_POLL
839 if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); 858 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
840#endif 859#endif
841#if EV_USE_SELECT 860#if EV_USE_SELECT
842 if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); 861 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags);
843#endif 862#endif
844 863
845 ev_init (&sigev, sigcb); 864 ev_init (&sigev, sigcb);
846 ev_set_priority (&sigev, EV_MAXPRI); 865 ev_set_priority (&sigev, EV_MAXPRI);
847 } 866 }
851loop_destroy (EV_P) 870loop_destroy (EV_P)
852{ 871{
853 int i; 872 int i;
854 873
855#if EV_USE_PORT 874#if EV_USE_PORT
856 if (method == EVMETHOD_PORT ) port_destroy (EV_A); 875 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
857#endif 876#endif
858#if EV_USE_KQUEUE 877#if EV_USE_KQUEUE
859 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 878 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A);
860#endif 879#endif
861#if EV_USE_EPOLL 880#if EV_USE_EPOLL
862 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 881 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
863#endif 882#endif
864#if EV_USE_POLL 883#if EV_USE_POLL
865 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 884 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
866#endif 885#endif
867#if EV_USE_SELECT 886#if EV_USE_SELECT
868 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 887 if (backend == EVBACKEND_SELECT) select_destroy (EV_A);
869#endif 888#endif
870 889
871 for (i = NUMPRI; i--; ) 890 for (i = NUMPRI; i--; )
872 array_free (pending, [i]); 891 array_free (pending, [i]);
873 892
879#endif 898#endif
880 array_free (idle, EMPTY0); 899 array_free (idle, EMPTY0);
881 array_free (prepare, EMPTY0); 900 array_free (prepare, EMPTY0);
882 array_free (check, EMPTY0); 901 array_free (check, EMPTY0);
883 902
884 method = 0; 903 backend = 0;
885} 904}
886 905
887static void 906static void
888loop_fork (EV_P) 907loop_fork (EV_P)
889{ 908{
890#if EV_USE_PORT 909#if EV_USE_PORT
891 if (method == EVMETHOD_PORT ) port_fork (EV_A); 910 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
892#endif 911#endif
893#if EV_USE_KQUEUE 912#if EV_USE_KQUEUE
894 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 913 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A);
895#endif 914#endif
896#if EV_USE_EPOLL 915#if EV_USE_EPOLL
897 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 916 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
898#endif 917#endif
899 918
900 if (ev_is_active (&sigev)) 919 if (ev_is_active (&sigev))
901 { 920 {
902 /* default loop */ 921 /* default loop */
923 942
924 memset (loop, 0, sizeof (struct ev_loop)); 943 memset (loop, 0, sizeof (struct ev_loop));
925 944
926 loop_init (EV_A_ flags); 945 loop_init (EV_A_ flags);
927 946
928 if (ev_method (EV_A)) 947 if (ev_backend (EV_A))
929 return loop; 948 return loop;
930 949
931 return 0; 950 return 0;
932} 951}
933 952
966 ev_default_loop_ptr = 1; 985 ev_default_loop_ptr = 1;
967#endif 986#endif
968 987
969 loop_init (EV_A_ flags); 988 loop_init (EV_A_ flags);
970 989
971 if (ev_method (EV_A)) 990 if (ev_backend (EV_A))
972 { 991 {
973 siginit (EV_A); 992 siginit (EV_A);
974 993
975#ifndef _WIN32 994#ifndef _WIN32
976 ev_signal_init (&childev, childcb, SIGCHLD); 995 ev_signal_init (&childev, childcb, SIGCHLD);
1012{ 1031{
1013#if EV_MULTIPLICITY 1032#if EV_MULTIPLICITY
1014 struct ev_loop *loop = ev_default_loop_ptr; 1033 struct ev_loop *loop = ev_default_loop_ptr;
1015#endif 1034#endif
1016 1035
1017 if (method) 1036 if (backend)
1018 postfork = 1; 1037 postfork = 1;
1019} 1038}
1020 1039
1021/*****************************************************************************/ 1040/*****************************************************************************/
1022 1041
1254 { 1273 {
1255 block = MAX_BLOCKTIME; 1274 block = MAX_BLOCKTIME;
1256 1275
1257 if (timercnt) 1276 if (timercnt)
1258 { 1277 {
1259 ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; 1278 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge;
1260 if (block > to) block = to; 1279 if (block > to) block = to;
1261 } 1280 }
1262 1281
1263#if EV_PERIODICS 1282#if EV_PERIODICS
1264 if (periodiccnt) 1283 if (periodiccnt)
1265 { 1284 {
1266 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;
1267 if (block > to) block = to; 1286 if (block > to) block = to;
1268 } 1287 }
1269#endif 1288#endif
1270 1289
1271 if (expect_false (block < 0.)) block = 0.; 1290 if (expect_false (block < 0.)) block = 0.;
1272 } 1291 }
1273 1292
1274 method_poll (EV_A_ block); 1293 backend_poll (EV_A_ block);
1275 1294
1276 /* update ev_rt_now, do magic */ 1295 /* update ev_rt_now, do magic */
1277 time_update (EV_A); 1296 time_update (EV_A);
1278 1297
1279 /* queue pending timers and reschedule them */ 1298 /* queue pending timers and reschedule them */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines