Detecting idleness

Marc Lehmann schmorp at
Mon Apr 5 16:55:13 CEST 2010

On Sun, Apr 04, 2010 at 11:26:51PM -0700, ry at wrote:
> Can someone suggest a good way of detecting a period of idleness? That
> is, a way to get a callback after the event loop has done nothing for
> N seconds. (I suppose some combination of an ev_idle, ev_timer, and
> maybe ev_check watchers...)

I don't see a way to accomplish that with libev alone. Note that
"idleness" of your app is not the same as "idleness" of libev (libev
itself might have timers, or other parts of your app).

What you can do is, each time your app is doing sth. non-idle, save ev_now()
in a last_activity variable. Alos have a timer runnign every "N" seconds.

When the timer fires, check last_activity. If last_activity < ev_now ()
- N, then you are are for at least N seconds. Otherwise just restart the
timer to fire after last_activity + N - ev_now ().

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_    
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list