aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGareth Webb <gareth.webb@umbralsoftware.co.uk>2024-03-27 19:45:18 +0000
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2024-03-27 17:21:22 -0500
commit3617af28811d9cc15fc2bb5b4a6565cd19b08089 (patch)
treeb26b0358dcc6871dc59591ae9283f65687d98f96
parente3f8bd7aa6a77eff9b9c4328c79db5b91732817a (diff)
downloadusermoji-3617af28811d9cc15fc2bb5b4a6565cd19b08089.tar.xz
vkcube: Thread safe event polling
-rw-r--r--cube/cube.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/cube/cube.c b/cube/cube.c
index edae7855..07d4a97a 100644
--- a/cube/cube.c
+++ b/cube/cube.c
@@ -37,7 +37,6 @@
#if defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR)
#include <X11/Xutil.h>
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
-#include <poll.h>
#include <linux/input.h>
#include "xdg-shell-client-header.h"
#include "xdg-decoration-client-header.h"
@@ -2818,18 +2817,24 @@ static void demo_create_xcb_window(struct demo *demo) {
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
static void demo_run(struct demo *demo) {
while (!demo->quit) {
+ // Flush any commands to the server
+ wl_display_flush(demo->display);
+
if (demo->pause) {
- wl_display_dispatch(demo->display); // block and wait for input
+ // block and wait for input
+ wl_display_dispatch(demo->display);
} else {
- struct pollfd pollfd = {
- .fd = wl_display_get_fd(demo->display),
- .events = POLLIN,
- };
- if (poll(&pollfd, 1, 0) > 0) {
- wl_display_dispatch(demo->display);
- } else {
- wl_display_dispatch_pending(demo->display); // don't block
+ // Lock the display event queue in case the driver is doing something on another thread
+ // while we wait, keep pumping events
+ while (wl_display_prepare_read(demo->display) != 0) {
+ wl_display_dispatch_pending(demo->display);
}
+ // Actually do the read from the socket
+ wl_display_read_events(demo->display);
+
+ // Pump events
+ wl_display_dispatch_pending(demo->display);
+
demo_draw(demo);
demo->curFrame++;
if (demo->frameCount != INT32_MAX && demo->curFrame == demo->frameCount) demo->quit = true;