From 1a37507895402ee08b1f248262701d4f848647e1 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Fri, 9 May 2025 17:31:37 +0000 Subject: [PATCH] validation: use a lock for CCheckQueueControl Uses an RAII lock for the exact same behavior as the old critical sections. Co-authored-by: Ryan Ofsky --- src/checkqueue.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/checkqueue.h b/src/checkqueue.h index e9eb96034cb..5920d2935dc 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -205,20 +205,18 @@ public: * queue is finished before continuing. */ template ()().value())>> -class CCheckQueueControl +class SCOPED_LOCKABLE CCheckQueueControl { private: CCheckQueue& m_queue; + UniqueLock m_lock; bool fDone; public: CCheckQueueControl() = delete; CCheckQueueControl(const CCheckQueueControl&) = delete; CCheckQueueControl& operator=(const CCheckQueueControl&) = delete; - explicit CCheckQueueControl(CCheckQueue& queueIn) : m_queue(queueIn), fDone(false) - { - ENTER_CRITICAL_SECTION(m_queue.m_control_mutex); - } + explicit CCheckQueueControl(CCheckQueue& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {} std::optional Complete() { @@ -232,11 +230,10 @@ public: m_queue.Add(std::move(vChecks)); } - ~CCheckQueueControl() + ~CCheckQueueControl() UNLOCK_FUNCTION() { if (!fDone) Complete(); - LEAVE_CRITICAL_SECTION(m_queue.m_control_mutex); } };