loader/dri3: Check for window destruction in dri3_wait_for_event_locked
authorMichel Dänzer <mdaenzer@redhat.com>
Fri, 5 Jun 2020 17:07:55 +0000 (19:07 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 29 Jun 2020 17:05:52 +0000 (17:05 +0000)
commitd7d7687829875e401690219d4a72458fb2bbe4de
treec7f7c3b0855283ed4c86d8ee54d9c4ced7e1f61d
parent7c226116c6c0793d6d9a7dec52ac7cf54b82b57f
loader/dri3: Check for window destruction in dri3_wait_for_event_locked

If the underlying X11 window gets destroyed, the event we're waiting
for may never be delivered, in which case xcb_wait_for_special_event
would hang indefinitely.

Solution:

1. Use xcb_poll_for_special_event to check if an event has arrived yet.
2. If not, Wait up to ~1s for XCB's file descriptor to become readable;
   if it does, go back to step 1.
3. If the file descriptor didn't become readable, make a round-trip to
   the X server to check that the window still exists. Go back to step
   1 if it does, otherwise bail.

Also add an early bail-out when it's known that the window was
destroyed.

Cc: mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/116
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5368>
src/loader/loader_dri3_helper.c
src/loader/loader_dri3_helper.h