wsi/x11: Fix possible deadlock with wait_ready.
authorHans-Kristian Arntzen <post@arntzen-software.no>
Thu, 24 Nov 2022 13:11:05 +0000 (14:11 +0100)
committerMarge Bot <emma+marge@anholt.net>
Wed, 14 Dec 2022 14:20:54 +0000 (14:20 +0000)
commit9e55766f630dff107c2b007c92a53506d30ac126
treebb14c01974ca84be048cbf9cd4d36aa27fe5277d
parent657d1be15395a28ab21796eab5f9c19c055db4ac
wsi/x11: Fix possible deadlock with wait_ready.

With the introduction of locks around the XCB polling mechanism,
a possible deadlock was introduced.

If all 5 images were rapidly acquired and presented before the
FIFO thread had the chance to submit a present,
we would deadlock.

Before the lock however, it was still buggy since the two threads would
race to poll events and update internal state.

The fix is to just ensure that there are pending presentation requests
in flight, so that forward progress is guaranteed before we take the
poll lock.

Also, use a timedlock for acquire next image.

Similar as WaitForPresentKHR.
Also need to make the busy flag atomic to actually allow acquire thread
and present threads to access the busy flag.
Take advantage of busy flag being atomic so that we can gracefully handle
timeout == 0 scenarios where there actually are images available.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
Fixes: 8fc7927787 ("wsi/x11: Implement VK_KHR_present_wait on X11.)
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19990>
src/vulkan/wsi/wsi_common_x11.c