From 7dc19d941e4c8bf45ad2ab21b5aa8a00c31f252d Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 9 Apr 2024 13:17:22 +0200 Subject: [PATCH] util/u_queue: read fence->signalled locked with TSAN When TSAN is enabled we use standard mutexes instead of futexes. With futexes the fence->signalled is read using an atomic operation, to best mimic this let's protect the read with a locked mutex. This avoids TSAN reporting a race condition (false positive with futexes) with Zink when accessing the pipeline cache. Signed-off-by: Gert Wollny Part-of: --- src/util/u_queue.h | 18 ++++++++++++++++++ tsan-blacklist.txt | 3 +-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/util/u_queue.h b/src/util/u_queue.h index d83a8162e8b..2d5ef91bc91 100644 --- a/src/util/u_queue.h +++ b/src/util/u_queue.h @@ -138,6 +138,7 @@ void util_queue_fence_signal(struct util_queue_fence *fence); * \warning The caller must ensure that no other thread may currently be * waiting (or about to wait) on the fence. */ +#if !THREAD_SANITIZER static inline void util_queue_fence_reset(struct util_queue_fence *fence) { @@ -150,6 +151,23 @@ util_queue_fence_is_signalled(struct util_queue_fence *fence) { return fence->signalled != 0; } +#else +static inline void +util_queue_fence_reset(struct util_queue_fence *fence) +{ + assert(fence->signalled); + fence->signalled = 0; +} + +static inline bool +util_queue_fence_is_signalled(struct util_queue_fence *fence) +{ + mtx_lock(&fence->mutex); + bool signalled = fence->signalled != 0; + mtx_unlock(&fence->mutex); + return signalled; +} +#endif #endif void diff --git a/tsan-blacklist.txt b/tsan-blacklist.txt index 46f383c4112..48f2c5552df 100644 --- a/tsan-blacklist.txt +++ b/tsan-blacklist.txt @@ -1,2 +1 @@ -# Placeholder file, will be filled with surpressions for TSAN - +# Placeholder file, will be filled with surpressions for TSAN