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

Comparing libev/ev.c (file contents):
Revision 1.126 by root, Sun Nov 18 01:25:23 2007 UTC vs.
Revision 1.129 by root, Fri Nov 23 05:00:44 2007 UTC

50# ifndef EV_USE_REALTIME 50# ifndef EV_USE_REALTIME
51# define EV_USE_REALTIME 0 51# define EV_USE_REALTIME 0
52# endif 52# endif
53# endif 53# endif
54 54
55# if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) 55# ifndef EV_USE_SELECT
56# if HAVE_SELECT && HAVE_SYS_SELECT_H
56# define EV_USE_SELECT 1 57# define EV_USE_SELECT 1
57# else 58# else
58# define EV_USE_SELECT 0 59# define EV_USE_SELECT 0
60# endif
59# endif 61# endif
60 62
61# if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) 63# ifndef EV_USE_POLL
64# if HAVE_POLL && HAVE_POLL_H
62# define EV_USE_POLL 1 65# define EV_USE_POLL 1
63# else 66# else
64# define EV_USE_POLL 0 67# define EV_USE_POLL 0
68# endif
65# endif 69# endif
66 70
67# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) 71# ifndef EV_USE_EPOLL
72# if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
68# define EV_USE_EPOLL 1 73# define EV_USE_EPOLL 1
69# else 74# else
70# define EV_USE_EPOLL 0 75# define EV_USE_EPOLL 0
76# endif
71# endif 77# endif
72 78
79# ifndef EV_USE_KQUEUE
73# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) 80# if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H
74# define EV_USE_KQUEUE 1 81# define EV_USE_KQUEUE 1
75# else 82# else
76# define EV_USE_KQUEUE 0 83# define EV_USE_KQUEUE 0
84# endif
77# endif 85# endif
78 86
79# if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT) 87# ifndef EV_USE_PORT
88# if HAVE_PORT_H && HAVE_PORT_CREATE
80# define EV_USE_PORT 1 89# define EV_USE_PORT 1
81# else 90# else
82# define EV_USE_PORT 0 91# define EV_USE_PORT 0
92# endif
83# endif 93# endif
84 94
85#endif 95#endif
86 96
87#include <math.h> 97#include <math.h>
143#ifndef EV_USE_PORT 153#ifndef EV_USE_PORT
144# define EV_USE_PORT 0 154# define EV_USE_PORT 0
145#endif 155#endif
146 156
147/**/ 157/**/
148
149/* darwin simply cannot be helped */
150#ifdef __APPLE__
151# undef EV_USE_POLL
152# undef EV_USE_KQUEUE
153#endif
154 158
155#ifndef CLOCK_MONOTONIC 159#ifndef CLOCK_MONOTONIC
156# undef EV_USE_MONOTONIC 160# undef EV_USE_MONOTONIC
157# define EV_USE_MONOTONIC 0 161# define EV_USE_MONOTONIC 0
158#endif 162#endif
775 || getgid () != getegid (); 779 || getgid () != getegid ();
776#endif 780#endif
777} 781}
778 782
779unsigned int 783unsigned int
780ev_method (EV_P) 784ev_supported_backends (void)
781{ 785{
782 return method; 786}
787
788unsigned int
789ev_recommended_backends (void)
790{
791 unsigned int flags;
792
793 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
794 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
795 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
796 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
797 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT;
798
799 return flags;
800}
801
802unsigned int
803ev_backend (EV_P)
804{
805 unsigned int flags = ev_recommended_backends ();
806
807#ifndef __NetBSD__
808 /* kqueue is borked on everything but netbsd apparently */
809 /* it usually doesn't work correctly on anything but sockets and pipes */
810 flags &= ~EVBACKEND_KQUEUE;
811#endif
812#ifdef __APPLE__
813 // flags &= ~EVBACKEND_KQUEUE; for documentation
814 flags &= ~EVBACKEND_POLL;
815#endif
816
817 return flags;
783} 818}
784 819
785static void 820static void
786loop_init (EV_P_ unsigned int flags) 821loop_init (EV_P_ unsigned int flags)
787{ 822{
798 ev_rt_now = ev_time (); 833 ev_rt_now = ev_time ();
799 mn_now = get_clock (); 834 mn_now = get_clock ();
800 now_floor = mn_now; 835 now_floor = mn_now;
801 rtmn_diff = ev_rt_now - mn_now; 836 rtmn_diff = ev_rt_now - mn_now;
802 837
803 if (!(flags & EVFLAG_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS")) 838 if (!(flags & EVFLAG_NOENV)
839 && !enable_secure ()
840 && getenv ("LIBEV_FLAGS"))
804 flags = atoi (getenv ("LIBEV_FLAGS")); 841 flags = atoi (getenv ("LIBEV_FLAGS"));
805 842
806 if (!(flags & 0x0000ffff)) 843 if (!(flags & 0x0000ffffUL))
807 flags |= 0x0000ffff; 844 flags |= ev_recommended_backends ();
808 845
809 method = 0; 846 method = 0;
810#if EV_USE_PORT 847#if EV_USE_PORT
811 if (!method && (flags & EVMETHOD_PORT )) method = port_init (EV_A_ flags); 848 if (!method && (flags & EVBACKEND_PORT )) method = port_init (EV_A_ flags);
812#endif 849#endif
813#if EV_USE_KQUEUE 850#if EV_USE_KQUEUE
814 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags); 851 if (!method && (flags & EVBACKEND_KQUEUE)) method = kqueue_init (EV_A_ flags);
815#endif 852#endif
816#if EV_USE_EPOLL 853#if EV_USE_EPOLL
817 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags); 854 if (!method && (flags & EVBACKEND_EPOLL )) method = epoll_init (EV_A_ flags);
818#endif 855#endif
819#if EV_USE_POLL 856#if EV_USE_POLL
820 if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags); 857 if (!method && (flags & EVBACKEND_POLL )) method = poll_init (EV_A_ flags);
821#endif 858#endif
822#if EV_USE_SELECT 859#if EV_USE_SELECT
823 if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags); 860 if (!method && (flags & EVBACKEND_SELECT)) method = select_init (EV_A_ flags);
824#endif 861#endif
825 862
826 ev_init (&sigev, sigcb); 863 ev_init (&sigev, sigcb);
827 ev_set_priority (&sigev, EV_MAXPRI); 864 ev_set_priority (&sigev, EV_MAXPRI);
828 } 865 }
832loop_destroy (EV_P) 869loop_destroy (EV_P)
833{ 870{
834 int i; 871 int i;
835 872
836#if EV_USE_PORT 873#if EV_USE_PORT
837 if (method == EVMETHOD_PORT ) port_destroy (EV_A); 874 if (method == EVBACKEND_PORT ) port_destroy (EV_A);
838#endif 875#endif
839#if EV_USE_KQUEUE 876#if EV_USE_KQUEUE
840 if (method == EVMETHOD_KQUEUE) kqueue_destroy (EV_A); 877 if (method == EVBACKEND_KQUEUE) kqueue_destroy (EV_A);
841#endif 878#endif
842#if EV_USE_EPOLL 879#if EV_USE_EPOLL
843 if (method == EVMETHOD_EPOLL ) epoll_destroy (EV_A); 880 if (method == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
844#endif 881#endif
845#if EV_USE_POLL 882#if EV_USE_POLL
846 if (method == EVMETHOD_POLL ) poll_destroy (EV_A); 883 if (method == EVBACKEND_POLL ) poll_destroy (EV_A);
847#endif 884#endif
848#if EV_USE_SELECT 885#if EV_USE_SELECT
849 if (method == EVMETHOD_SELECT) select_destroy (EV_A); 886 if (method == EVBACKEND_SELECT) select_destroy (EV_A);
850#endif 887#endif
851 888
852 for (i = NUMPRI; i--; ) 889 for (i = NUMPRI; i--; )
853 array_free (pending, [i]); 890 array_free (pending, [i]);
854 891
867 904
868static void 905static void
869loop_fork (EV_P) 906loop_fork (EV_P)
870{ 907{
871#if EV_USE_PORT 908#if EV_USE_PORT
872 if (method == EVMETHOD_PORT ) port_fork (EV_A); 909 if (method == EVBACKEND_PORT ) port_fork (EV_A);
873#endif 910#endif
874#if EV_USE_KQUEUE 911#if EV_USE_KQUEUE
875 if (method == EVMETHOD_KQUEUE) kqueue_fork (EV_A); 912 if (method == EVBACKEND_KQUEUE) kqueue_fork (EV_A);
876#endif 913#endif
877#if EV_USE_EPOLL 914#if EV_USE_EPOLL
878 if (method == EVMETHOD_EPOLL ) epoll_fork (EV_A); 915 if (method == EVBACKEND_EPOLL ) epoll_fork (EV_A);
879#endif 916#endif
880 917
881 if (ev_is_active (&sigev)) 918 if (ev_is_active (&sigev))
882 { 919 {
883 /* default loop */ 920 /* default loop */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines