From 44c7440702249a02adb681fb738967bb28bfcc5f Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 23 Nov 2025 18:46:29 -0600 Subject: [PATCH] Common:: Add DummyMutex and make WorkQueueThreadBase use it. --- Source/Core/Common/Mutex.h | 14 ++++++++++++++ Source/Core/Common/WorkQueueThread.h | 16 ++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Source/Core/Common/Mutex.h b/Source/Core/Common/Mutex.h index 22aebd08b1b..fbb7c1a4c7f 100644 --- a/Source/Core/Common/Mutex.h +++ b/Source/Core/Common/Mutex.h @@ -48,4 +48,18 @@ using AtomicMutex = detail::AtomicMutexBase; // Very fast to lock and unlock when uncontested (~3x faster than std::mutex). using SpinMutex = detail::AtomicMutexBase; +// This "mutex" class provides no actual thread synchronization. +// It has a std::shared_mutex interface only to be compatible with standard locks. +// Useful when template parameters can determine that a mutex is not actually needed. +struct DummyMutex +{ + constexpr void lock() {} + constexpr bool try_lock() { return true; } + constexpr void unlock() {} + + constexpr void lock_shared() {} + constexpr bool try_lock_shared() { return true; } + constexpr void unlock_shared() {} +}; + } // namespace Common diff --git a/Source/Core/Common/WorkQueueThread.h b/Source/Core/Common/WorkQueueThread.h index 8816ddda16d..6a5eaa73b25 100644 --- a/Source/Core/Common/WorkQueueThread.h +++ b/Source/Core/Common/WorkQueueThread.h @@ -10,6 +10,7 @@ #include #include "Common/Event.h" +#include "Common/Mutex.h" #include "Common/SPSCQueue.h" #include "Common/Thread.h" @@ -128,19 +129,7 @@ private: m_commands.Clear(); } - auto GetLockGuard() - { - struct DummyLockGuard - { - // Silences unused variable warning. - ~DummyLockGuard() { void(); } - }; - - if constexpr (IsSingleProducer) - return DummyLockGuard{}; - else - return std::lock_guard{m_mutex}; - } + auto GetLockGuard() { return std::lock_guard{m_mutex}; } bool IsRunning() { return m_thread.joinable(); } @@ -177,7 +166,6 @@ private: Common::WaitableSPSCQueue m_commands; Common::Event m_event; - using DummyMutex = std::type_identity; using ProducerMutex = std::conditional_t; ProducerMutex m_mutex; };