New iteration over the ev++ improvement patch.

Marc Lehmann schmorp at
Sat Jan 19 11:55:18 CET 2008

On Fri, Jan 18, 2008 at 05:09:15PM -0200, Leandro Lucarella <llucax at> wrote:
> About this. What about exposing the default loop functions in the ev
> namespace?

thats probably not a bad idea, as it underscores that the default loop is not
an objetc to be instantiated by user code.

to me, ev::init doesn't give me the default loop or intziailises, it simply
ensures that the default loop is there.

and ev::destroy is more a "really, destroy it even if everybody else hates
it, because for some obscure reason we should not have a default loop" (i
cannot imagine such situation, really, I am open for examples).

> ev::init (flags) -> ev_default_loop (flags)

  ev::default_loop or default_init (not that important)

> ev::get ()       -> ev_default_loop (0)

  maybe ev::default_loop () as well?

> ev::destroy ()   -> ev_default_destroy ()

  I think this really should be ev::default_destroy, its too non-obvious

> ev::count ()     -> ev_count (ev_default_loop (0))
> ev::backend ()   -> ev_backend (ev_default_loop (0))
> I'll keep the default loop struct wrapper too, because in a multi loop
> environment let you use a callback for a default or a dynamic loop
> indisticly, like:

How about nuking th default_loop wrapper and instead returnign a loop_ref of
the default loop instead?

Then the interface would be the same:

   ev::default_loop ().loop ()
   ev::default_loop ().post_fork ();

etc. I think default_loop should preferably a variable (this has many
problems! don't! :)

that is, have functions only for the most common uses (such as loop) and
stuff you can't have in a loop_ref (create/destroy), but keep everythign else
in the loop_ref.

> void cb (watcher &w, int revents)
> {
> 	w.loop.unloop (); // I don't care if is the default or not.
> }

That should definitely work, yes.

> So you can reuse callbacks. You can also use automatic destruction for the
> default loop:

automatic destruction for the default loop makes what sense? I'd really
like to know. In about 100% of the cases its a big waste of time and

> What do you think?

Its a good idea that I would like to slightly modify, if possible :)

> PS: The "big" problem comes with ev::now () =P

hhehe, my proposal fixes thta, as it would be:

ev::default_loop ().now ()

i think users should store the default_loop in soem variable as soon
as possible anyways (and most people will liekly do just to avoid the
function call).

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

More information about the libev mailing list