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

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

120# define EV_USE_REALTIME 1 120# define EV_USE_REALTIME 1
121#endif 121#endif
122 122
123/**/ 123/**/
124 124
125/* darwin simply cannot be helped */
126#ifdef __APPLE__
127# undef EV_USE_POLL
128# undef EV_USE_KQUEUE
129#endif
130
125#ifndef CLOCK_MONOTONIC 131#ifndef CLOCK_MONOTONIC
126# undef EV_USE_MONOTONIC 132# undef EV_USE_MONOTONIC
127# define EV_USE_MONOTONIC 0 133# define EV_USE_MONOTONIC 0
128#endif 134#endif
129 135
304{ 310{
305 return ev_rt_now; 311 return ev_rt_now;
306} 312}
307#endif 313#endif
308 314
309#define array_roundsize(type,n) ((n) | 4 & ~3) 315#define array_roundsize(type,n) (((n) | 4) & ~3)
310 316
311#define array_needsize(type,base,cur,cnt,init) \ 317#define array_needsize(type,base,cur,cnt,init) \
312 if (expect_false ((cnt) > cur)) \ 318 if (expect_false ((cnt) > cur)) \
313 { \ 319 { \
314 int newcnt = cur; \ 320 int newcnt = cur; \
747{ 753{
748 return method; 754 return method;
749} 755}
750 756
751static void 757static void
752loop_init (EV_P_ int methods) 758loop_init (EV_P_ unsigned int flags)
753{ 759{
754 if (!method) 760 if (!method)
755 { 761 {
756#if EV_USE_MONOTONIC 762#if EV_USE_MONOTONIC
757 { 763 {
764 ev_rt_now = ev_time (); 770 ev_rt_now = ev_time ();
765 mn_now = get_clock (); 771 mn_now = get_clock ();
766 now_floor = mn_now; 772 now_floor = mn_now;
767 rtmn_diff = ev_rt_now - mn_now; 773 rtmn_diff = ev_rt_now - mn_now;
768 774
769 if (methods == EVMETHOD_AUTO) 775 if (!(flags & EVMETHOD_NOENV) && !enable_secure () && getenv ("LIBEV_FLAGS"))
770 if (!enable_secure () && getenv ("LIBEV_METHODS"))
771 methods = atoi (getenv ("LIBEV_METHODS")); 776 flags = atoi (getenv ("LIBEV_FLAGS"));
772 else 777
773 methods = EVMETHOD_ANY; 778 if (!(flags & 0x0000ffff))
779 flags |= 0x0000ffff;
774 780
775 method = 0; 781 method = 0;
776#if EV_USE_KQUEUE 782#if EV_USE_KQUEUE
777 if (!method && (methods & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ methods); 783 if (!method && (flags & EVMETHOD_KQUEUE)) method = kqueue_init (EV_A_ flags);
778#endif 784#endif
779#if EV_USE_EPOLL 785#if EV_USE_EPOLL
780 if (!method && (methods & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ methods); 786 if (!method && (flags & EVMETHOD_EPOLL )) method = epoll_init (EV_A_ flags);
781#endif 787#endif
782#if EV_USE_POLL 788#if EV_USE_POLL
783 if (!method && (methods & EVMETHOD_POLL )) method = poll_init (EV_A_ methods); 789 if (!method && (flags & EVMETHOD_POLL )) method = poll_init (EV_A_ flags);
784#endif 790#endif
785#if EV_USE_SELECT 791#if EV_USE_SELECT
786 if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); 792 if (!method && (flags & EVMETHOD_SELECT)) method = select_init (EV_A_ flags);
787#endif 793#endif
788 794
789 ev_init (&sigev, sigcb); 795 ev_init (&sigev, sigcb);
790 ev_set_priority (&sigev, EV_MAXPRI); 796 ev_set_priority (&sigev, EV_MAXPRI);
791 } 797 }
853 postfork = 0; 859 postfork = 0;
854} 860}
855 861
856#if EV_MULTIPLICITY 862#if EV_MULTIPLICITY
857struct ev_loop * 863struct ev_loop *
858ev_loop_new (int methods) 864ev_loop_new (unsigned int flags)
859{ 865{
860 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));
861 867
862 memset (loop, 0, sizeof (struct ev_loop)); 868 memset (loop, 0, sizeof (struct ev_loop));
863 869
864 loop_init (EV_A_ methods); 870 loop_init (EV_A_ flags);
865 871
866 if (ev_method (EV_A)) 872 if (ev_method (EV_A))
867 return loop; 873 return loop;
868 874
869 return 0; 875 return 0;
887#if EV_MULTIPLICITY 893#if EV_MULTIPLICITY
888struct ev_loop * 894struct ev_loop *
889#else 895#else
890int 896int
891#endif 897#endif
892ev_default_loop (int methods) 898ev_default_loop (unsigned int flags)
893{ 899{
894 if (sigpipe [0] == sigpipe [1]) 900 if (sigpipe [0] == sigpipe [1])
895 if (pipe (sigpipe)) 901 if (pipe (sigpipe))
896 return 0; 902 return 0;
897 903
901 struct ev_loop *loop = default_loop = &default_loop_struct; 907 struct ev_loop *loop = default_loop = &default_loop_struct;
902#else 908#else
903 default_loop = 1; 909 default_loop = 1;
904#endif 910#endif
905 911
906 loop_init (EV_A_ methods); 912 loop_init (EV_A_ flags);
907 913
908 if (ev_method (EV_A)) 914 if (ev_method (EV_A))
909 { 915 {
910 siginit (EV_A); 916 siginit (EV_A);
911 917
1025 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 1031 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
1026 1032
1027 /* first reschedule or stop timer */ 1033 /* first reschedule or stop timer */
1028 if (w->reschedule_cb) 1034 if (w->reschedule_cb)
1029 { 1035 {
1030 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);
1031
1032 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));
1033 downheap ((WT *)periodics, periodiccnt, 0); 1038 downheap ((WT *)periodics, periodiccnt, 0);
1034 } 1039 }
1035 else if (w->interval) 1040 else if (w->interval)
1036 { 1041 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines