On Thu, Jun 2, 2011 at 8:25 AM, Alexey Borzenkov <[email protected]> wrote:

> +  backend_fudge  = 1e-3;
>

This helps with CPU load but it still causes ev_timer(0) to issue
ev_sleep(>0) which puts the process to sleep.

However, for ev_timer with AT = 0, the guarantee that the timers are only
executed after AT seconds is passed is satisfied immediately, and thus there
is no need to sleep.

It is possible to use ev_timer(-1) but that's not as clear as ev_timer(0).

What do you think about making a special case for ev_timer(at=0)?

Here's a possible patch:

diff -r 4e6eab41f320 libev/ev.c
--- a/libev/ev.c    Thu Jun 02 21:03:56 2011 +0200
+++ b/libev/ev.c    Thu Jun 02 21:47:49 2011 +0200
@@ -2241,9 +2241,12 @@
           /* first reschedule or stop timer */
           if (w->repeat)
             {
-              ev_at (w) += w->repeat;
+              if (ev_at(w))
+                ev_at (w) += w->repeat;
+              else
+                ev_at (w) = mn_now + w->repeat;
               if (ev_at (w) < mn_now)
-                ev_at (w) = mn_now;
+                  ev_at (w) = mn_now;

               assert (("libev: negative ev_timer repeat value found while
processing timers", w->repeat > 0.));

@@ -2761,7 +2764,8 @@
   if (expect_false (ev_is_active (w)))
     return;

-  ev_at (w) += mn_now;
+  if (ev_at(w))
+      ev_at (w) += mn_now;

   assert (("libev: ev_timer_start called with negative timer repeat value",
w->repeat >= 0.));

@@ -2802,7 +2806,8 @@
       }
   }

-  ev_at (w) -= mn_now;
+  if (ev_at(w))
+      ev_at (w) -= mn_now;

   ev_stop (EV_A_ (W)w);

@@ -2837,7 +2842,9 @@
 ev_tstamp
 ev_timer_remaining (EV_P_ ev_timer *w)
 {
-  return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
+  if (ev_at(w))
+      return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
+  return 0.;
 }

 #if EV_PERIODIC_ENABLE
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to