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

Comparing libev/ev.c (file contents):
Revision 1.103 by root, Mon Nov 12 00:31:08 2007 UTC vs.
Revision 1.110 by root, Mon Nov 12 05:56:49 2007 UTC

95# define EV_USE_MONOTONIC 1 95# define EV_USE_MONOTONIC 1
96#endif 96#endif
97 97
98#ifndef EV_USE_SELECT 98#ifndef EV_USE_SELECT
99# define EV_USE_SELECT 1 99# define EV_USE_SELECT 1
100# define EV_SELECT_USE_FD_SET 1
100#endif 101#endif
101 102
102#ifndef EV_USE_POLL 103#ifndef EV_USE_POLL
103# define EV_USE_POLL 0 /* poll is usually slower than select, and not as well tested */ 104# ifdef _WIN32
105# define EV_USE_POLL 0
106# else
107# define EV_USE_POLL 1
108# endif
104#endif 109#endif
105 110
106#ifndef EV_USE_EPOLL 111#ifndef EV_USE_EPOLL
107# define EV_USE_EPOLL 0 112# define EV_USE_EPOLL 0
108#endif 113#endif
114#ifndef EV_USE_REALTIME 119#ifndef EV_USE_REALTIME
115# define EV_USE_REALTIME 1 120# define EV_USE_REALTIME 1
116#endif 121#endif
117 122
118/**/ 123/**/
124
125/* darwin simply cannot be helped */
126#ifdef __APPLE__
127# undef EV_USE_POLL
128# undef EV_USE_KQUEUE
129#endif
119 130
120#ifndef CLOCK_MONOTONIC 131#ifndef CLOCK_MONOTONIC
121# undef EV_USE_MONOTONIC 132# undef EV_USE_MONOTONIC
122# define EV_USE_MONOTONIC 0 133# define EV_USE_MONOTONIC 0
123#endif 134#endif
299{ 310{
300 return ev_rt_now; 311 return ev_rt_now;
301} 312}
302#endif 313#endif
303 314
304#define array_roundsize(type,n) ((n) | 4 & ~3) 315#define array_roundsize(type,n) (((n) | 4) & ~3)
305 316
306#define array_needsize(type,base,cur,cnt,init) \ 317#define array_needsize(type,base,cur,cnt,init) \
307 if (expect_false ((cnt) > cur)) \ 318 if (expect_false ((cnt) > cur)) \
308 { \ 319 { \
309 int newcnt = cur; \ 320 int newcnt = cur; \
742{ 753{
743 return method; 754 return method;
744} 755}
745 756
746static void 757static void
747loop_init (EV_P_ int methods) 758loop_init (EV_P_ unsigned int flags)
748{ 759{
749 if (!method) 760 if (!method)
750 { 761 {
751#if EV_USE_MONOTONIC 762#if EV_USE_MONOTONIC
752 { 763 {
759 ev_rt_now = ev_time (); 770 ev_rt_now = ev_time ();
760 mn_now = get_clock (); 771 mn_now = get_clock ();
761 now_floor = mn_now; 772 now_floor = mn_now;
762 rtmn_diff = ev_rt_now - mn_now; 773 rtmn_diff = ev_rt_now - mn_now;
763 774
764 if (methods == EVMETHOD_AUTO) 775 if (!(flags & EVMETHOD_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS"))
765 if (!enable_secure () && getenv ("LIBEV_METHODS"))
766 methods = atoi (getenv ("LIBEV_METHODS")); 776 flags = atoi (getenv ("LIBEV_FLAGS"));
767 else 777
768 methods = EVMETHOD_ANY; 778 if (!(flags & 0x0000ffff))
779 flags |= 0x0000ffff;
769 780
770 method = 0; 781 method = 0;
771#if EV_USE_KQUEUE 782#if EV_USE_KQUEUE
772 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 783 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags);
773#endif 784#endif
774#if EV_USE_EPOLL 785#if EV_USE_EPOLL
775 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 786 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags);
776#endif 787#endif
777#if EV_USE_POLL 788#if EV_USE_POLL
778 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 789 if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags);
779#endif 790#endif
780#if EV_USE_SELECT 791#if EV_USE_SELECT
781 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 792 if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags);
782#endif 793#endif
783 794
784 ev_init (&sigev, sigcb); 795 ev_init (&sigev, sigcb);
785 ev_set_priority (&sigev, EV_MAXPRI); 796 ev_set_priority (&sigev, EV_MAXPRI);
786 } 797 }
848 postfork = 0; 859 postfork = 0;
849} 860}
850 861
851#if EV_MULTIPLICITY 862#if EV_MULTIPLICITY
852struct ev_loop * 863struct ev_loop *
853ev_loop_new (int methods) 864ev_loop_new (unsigned int flags)
854{ 865{
855 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 866 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
856 867
857 memset (loop, 0, sizeof (struct ev_loop)); 868 memset (loop, 0, sizeof (struct ev_loop));
858 869
859 loop_init (EV_A_ methods); 870 loop_init (EV_A_ flags);
860 871
861 if (ev_method (EV_A)) 872 if (ev_method (EV_A))
862 return loop; 873 return loop;
863 874
864 return 0; 875 return 0;
882#if EV_MULTIPLICITY 893#if EV_MULTIPLICITY
883struct ev_loop * 894struct ev_loop *
884#else 895#else
885int 896int
886#endif 897#endif
887ev_default_loop (int methods) 898ev_default_loop (unsigned int flags)
888{ 899{
889 if (sigpipe [0] == sigpipe [1]) 900 if (sigpipe [0] == sigpipe [1])
890 if (pipe (sigpipe)) 901 if (pipe (sigpipe))
891 return 0; 902 return 0;
892 903
896 struct ev_loop *loop = default_loop = &default_loop_struct; 907 struct ev_loop *loop = default_loop = &default_loop_struct;
897#else 908#else
898 default_loop = 1; 909 default_loop = 1;
899#endif 910#endif
900 911
901 loop_init (EV_A_ methods); 912 loop_init (EV_A_ flags);
902 913
903 if (ev_method (EV_A)) 914 if (ev_method (EV_A))
904 { 915 {
905 siginit (EV_A); 916 siginit (EV_A);
906 917
1020 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 1031 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
1021 1032
1022 /* first reschedule or stop timer */ 1033 /* first reschedule or stop timer */
1023 if (w->reschedule_cb) 1034 if (w->reschedule_cb)
1024 { 1035 {
1025 ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); 1036 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001);
1026
1027 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); 1037 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now));
1028 downheap ((WT *)periodics, periodiccnt, 0); 1038 downheap ((WT *)periodics, periodiccnt, 0);
1029 } 1039 }
1030 else if (w->interval) 1040 else if (w->interval)
1031 { 1041 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines