Integrate the Glib main loop into the libev event loop (C++)
Marc Lehmann
schmorp at schmorp.de
Wed Jul 7 03:21:27 CEST 2021
On Wed, Jul 07, 2021 at 12:06:37AM +0200, Oleksandr Kozlov <aleks.a.kozlov at gmail.com> wrote:
> from the EV::Glib Perl module [3].
Note that this is likely going to be slow, as glib does not have the
necessary hooks to efficiently be embedded into another event loop.
> ctx.poll_fds.clear();
> int timeout = 0;
> ctx.context->query(ctx.priority, timeout, ctx.poll_fds);
> for (Glib::PollFD &poll_fd : ctx.poll_fds) {
> int fd = poll_fd.get_fd();
> ctx.ios.try_emplace(fd, fd, to_ev_events(poll_fd.get_events()));
This looks as if you cache io watchers by fd, and could be the reason for
the problem - Glib doesn't tell you when the fd changes, so the fd is not
a unique enough primary key for your map (which really should be an array,
too).
What EV::Glib is doing is create I/O watchers in a prepare call and stop
them in the check call - you could simply push them onto a vector and clear
it out in check.
You could also try forcing libev to use select or poll as backend, which,
if Glib uses a lot of watchers, is likely more efficient, and this is a
quick way of checking whether this is your real problem - note that using
these backends for these side effects is not really supported by libev,
so you should definitely fix the c++ side, possibly followed by using
select/poll for efficiency.
--
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