[timers] - triggering at the same time

Marc Lehmann schmorp at schmorp.de
Sun Dec 18 17:47:03 CET 2011

On Fri, Dec 16, 2011 at 07:15:57PM -0800, Neeraj Rai <rneeraj at yahoo.com> wrote:
> 1. Sorry, I am not that familiar with libev. 
>   a) Is there a libev function I can call to check if there is already a 


>   b) if not, what would be the best data structure for that?

well, you'd probably want to do timer management on your own.

> 2. I was thinking of assigning running seqno, so large number of pri.
>   Maybe this option is not such a good idea.

not with libev, no.

> 4. the prepare callback sounds promising but I can't figure out from the
>   example how it would be used.
>   When I init/start a timer, do I also init/start a prepare ?
>   Are all the timers at the same time bunched in same preppare callback ?

ok, here is what libev is doing:

   invoke prepare watchers
   poll kernel for new events
   invoke check watchers
   invoke other watchers

or in other words, all timers will be invoked, then prepare watchers, and
then it might block for new events.

the idea is to collect all invoked timers, i.e. when their callback is
called, push them into a list and start a prepare watcher.

the prepare watcher will be run AFTER all outstanding timers have been
invoked but BEFORE the loop sleeps again. there are some minor limitations,
within a prepare watcher callback, but mostly you can sitll start and stop
any watchers.

in the prepare watcher, you then have a (smallish) list of timers that are
pending, and you cna sort that yourself, presumably, and then call them in
the right order.

I'll have a look and see if its feasible to support a strict timer ordering.

otoh, why do you need the strict timer ordering? maybe your goal can be
achieved without it?

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list