PATCH: Integrating libev with other runloops

Rasmus Andersson rasmus at notion.se
Sat Oct 23 18:36:13 CEST 2010


Greetings, knights of libev.

I'm part of the node.js dev community and are working on a library
version of node (which can be embedded in other programs). Many "host"
systems already use a runloop system of their own (e.g. OS X
applications use something called CFRunLoop) thus there's a need to
have node running in symbios with these systems.

For this to work smoothly there's some information related to a libev
runloop which is not exposed through the API. We added the following
four functions:

• ev_backend_fd -- ability to acquire the FD used by the backend (e.g.
to register for events so the parent runloop can yield for libev when
appropriate).

• ev_refcount -- ability to know the number of active events, so the
runloop iteration invocation can be optimized.

• ev_loop_fdchangecount -- ability to know when to stop yielding for libev

• ev_loop_next_waittime -- ability to know when to next invoke ev_loop.


In our current implementation, we call the following function when
needed (either because backend FD has pending changes or waittime
passed):

void NodeLoopIteration() {
 ev_now_update();
 ev_loop(EV_DEFAULT_UC_ EVLOOP_NONBLOCK);
 while(ev_loop_fdchangecount() != 0) {
  ev_loop(EV_DEFAULT_UC_ EVLOOP_NONBLOCK);
 }
}

I've attached the patch we created. It's very rudimentary and the only
real code (ev_loop_next_waittime) is copy-pasted from ev_loop.


Would really appreciate this patch being integrated!

Thank you.

--
Rasmus Andersson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libev.patch
Type: application/octet-stream
Size: 3427 bytes
Desc: not available
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20101023/c194d823/attachment.obj>


More information about the libev mailing list