Should there be a way to query if an event queue is empty?
Neil Roberts
neil at linux.intel.com
Sat Jul 27 06:16:23 PDT 2013
Bill Spitzak <spitzak at gmail.com> writes:
> You can call dispatch_pending "last", ie as part of the dispatch
> function. It's in a loop, so doing something at the end of the loop is
> the same as doing it at the start.
I don't think that will work for GLib because you can't really control
the order of the dispatch functions to make sure that the dispatch for
the Wayland source will be invoked last. That means that for example if
you have a different source that causes a redraw which calls
eglSwapBuffers, that will cause Mesa to dispatch events for its own
event queue. That could also cause events to be queued for the main
event queue. If the redraw source is dispatched after the Wayland source
then nothing will cause poll to wake up even though there are events
that are immediately ready to be dispatched.
Having thought about this a bit more I think in the GLib case you could
just use wl_dispatch_prepare_read() because that does effectively let
you know whether there is anything in the queue. So you could call it
once in the prepare function and if it errors with EBUSY then you could
return TRUE to cause poll to wake up immediately and then in the
dispatch you would call wl_display_dispatch_pending instead of
wl_display_dispatch. This would probably be a good thing to do anyway to
make it thread safe.
This relies on being able to guarantee that the prepare function will be
called exactly once before entering poll and that the check function is
guaranteed to be called after exiting poll. Otherwise you can't match
the prepare_read with a read or a cancel. I think for a GSource this is
probably true so it won't cause any problems. However for Cogl we can't
currently guarantee that the prepare function will exactly tally up with
the dispatch function because these are driven by calls from the
application. However I'm not sure whether that is more a problem with
Cogl's design rather than Wayland's design.
Regards,
- Neil
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
More information about the wayland-devel
mailing list