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 <ryan@ofsky.org>
This commit is contained in:
Cory Fields
2025-05-09 17:31:37 +00:00
parent c3b0e6c7f4
commit 1a37507895

View File

@@ -205,20 +205,18 @@ public:
* queue is finished before continuing.
*/
template <typename T, typename R = std::remove_cvref_t<decltype(std::declval<T>()().value())>>
class CCheckQueueControl
class SCOPED_LOCKABLE CCheckQueueControl
{
private:
CCheckQueue<T, R>& m_queue;
UniqueLock<Mutex> m_lock;
bool fDone;
public:
CCheckQueueControl() = delete;
CCheckQueueControl(const CCheckQueueControl&) = delete;
CCheckQueueControl& operator=(const CCheckQueueControl&) = delete;
explicit CCheckQueueControl(CCheckQueue<T>& queueIn) : m_queue(queueIn), fDone(false)
{
ENTER_CRITICAL_SECTION(m_queue.m_control_mutex);
}
explicit CCheckQueueControl(CCheckQueue<T>& queueIn) EXCLUSIVE_LOCK_FUNCTION(queueIn.m_control_mutex) : m_queue(queueIn), m_lock(LOCK_ARGS(queueIn.m_control_mutex)), fDone(false) {}
std::optional<R> 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);
}
};