Sorry, I just broke the ev++.h API completely.

The advantages of the new approach:

- C++ watchers have exactly the same size as C ones
- the "this" ptr is stored in the data member
- const methods, static methods and function pointers are now supported
  as callbacks, and its easy to add other functors.
- if the callback is an inline function then it can be inlined into
  the thunking code, leading to the same codesize and efficiency
  as a corresponding C callback.
- it is fully standard c++ compliant.
- less macro magic in ev++.h...

This is achieved by generating a small thunking function that is used as
the callback, which contains the inlined method call (and as the compiler
knows what method to call at runtime, it can optimise).

Here is an example of an actual thunking function in the best case, with
g++-4.3:

<void callback<void ()(_XEvent&)>::thunk<rxvt_term, 
&(rxvt_term::x_cb(_XEvent&))>(void*, _XEvent&)>
   440e80:       e9 1b 0e ff ff          jmpq   431ca0 
<rxvt_term::x_cb(_XEvent&)>

If "this" adjustments are required they will usually result in 1-3 extra
instructions, the same is true for virtual methods.

Unfortunately, C++ isn't flexible enough to make all this into a nice
syntax, so the syntax had to change considerably:

   ev.constructor(object, method, loop)

becomes:

   ev.constructor (loop)
   ev.set<klass, method> (object);

i.e.

   : some_ev (this, &myclass::method, loop)

becomes:

   some_ev.set (loop);
   some_ev.set<myclass, &myclass::method> (this);

There seems to be no way in c++ to deduce the class type out of the method
pointer constant without having to specify it separately anyways.

(and yes, there are a bit too many set functions, I am considering
replacing the callback-set method by "cb" or so).

Functions can be set with the same set (but simpler) syntax:

  static void some_cb (ev::timer &w, int revents);
  some_ev.set (some_cb);

Docs have not yet been updated.

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

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

Reply via email to