summaryrefslogtreecommitdiffstats
path: root/src/loader/loader_dri3_helper.h
diff options
context:
space:
mode:
authorThomas Hellstrom <[email protected]>2017-09-19 19:41:22 +0200
committerThomas Hellstrom <[email protected]>2017-11-13 12:43:39 +0100
commit54a58b2856377e18ea6a42706bea0304a8d7845e (patch)
tree4a3905f4987d24e5bf9ab750361783898004420a /src/loader/loader_dri3_helper.h
parent2b72ab58e5f63f82fe64cfc1beccddb2f4844405 (diff)
loader/dri3: Improve dri3 thread-safety
It turned out that with recent changes that call into dri3 from glFinish(), it appears like different thread end up waiting for X events simultaneously, causing deadlocks since they steal events from eachoter and update the dri3 counters behind eachothers backs. This patch intends to improve on that. It allows at most one thread at a time to wait on events for a single drawable. If another thread intends to do the same, it's put to sleep until the first thread finishes waiting, and then it rechecks counters and optionally retries the waiting. Threads that poll for X events never pulls X events off the event queue if there are other threads waiting for events on that drawable. Counters in the dri3 drawable structure are protected by a mutex. Finally, the mutex we introduce is never held while waiting for the X server to avoid unnecessary stalls. This does not make dri3 drawables completely thread-safe but at least it's a first step. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102358 Fixes: d5ba75f8881 "st/dri2 Plumb the flush_swapbuffer functionality through to dri3" Signed-off-by: Thomas Hellstrom <[email protected]> Acked-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/loader/loader_dri3_helper.h')
-rw-r--r--src/loader/loader_dri3_helper.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/loader/loader_dri3_helper.h b/src/loader/loader_dri3_helper.h
index d3f4b0c00a9..0dd37e91717 100644
--- a/src/loader/loader_dri3_helper.h
+++ b/src/loader/loader_dri3_helper.h
@@ -33,6 +33,7 @@
#include <GL/gl.h>
#include <GL/internal/dri_interface.h>
+#include <c11/threads.h>
enum loader_dri3_buffer_type {
loader_dri3_buffer_back = 0,
@@ -159,6 +160,15 @@ struct loader_dri3_drawable {
unsigned int swap_method;
unsigned int back_format;
+
+ /* Currently protects the following fields:
+ * event_cnd, has_event_waiter,
+ * recv_sbc, ust, msc, recv_msc_serial,
+ * notify_ust, notify_msc
+ */
+ mtx_t mtx;
+ cnd_t event_cnd;
+ bool has_event_waiter;
};
void