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:
1 parent
c3b0e6c7f4
commit
1a37507895
1 file changed
+4
-7
+4
-7
@@ -205,20 +205,18 @@ public:
|
|||||||
* queue is finished before continuing.
|
* queue is finished before continuing.
|
||||||
*/
|
*/
|
||||||
template <typename T, typename R = std::remove_cvref_t<decltype(std::declval<T>()().value())>>
|
template <typename T, typename R = std::remove_cvref_t<decltype(std::declval<T>()().value())>>
|
||||||
class CCheckQueueControl
|
class SCOPED_LOCKABLE CCheckQueueControl
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CCheckQueue<T, R>& m_queue;
|
CCheckQueue<T, R>& m_queue;
|
||||||
|
UniqueLock<Mutex> m_lock;
|
||||||
bool fDone;
|
bool fDone;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CCheckQueueControl() = delete;
|
CCheckQueueControl() = delete;
|
||||||
CCheckQueueControl(const CCheckQueueControl&) = delete;
|
CCheckQueueControl(const CCheckQueueControl&) = delete;
|
||||||
CCheckQueueControl& operator=(const CCheckQueueControl&) = delete;
|
CCheckQueueControl& operator=(const CCheckQueueControl&) = delete;
|
||||||
explicit CCheckQueueControl(CCheckQueue<T>& queueIn) : m_queue(queueIn), fDone(false)
|
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) {}
|
||||||
{
|
|
||||||
ENTER_CRITICAL_SECTION(m_queue.m_control_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<R> Complete()
|
std::optional<R> Complete()
|
||||||
{
|
{
|
||||||
@@ -232,11 +230,10 @@ public:
|
|||||||
m_queue.Add(std::move(vChecks));
|
m_queue.Add(std::move(vChecks));
|
||||||
}
|
}
|
||||||
|
|
||||||
~CCheckQueueControl()
|
~CCheckQueueControl() UNLOCK_FUNCTION()
|
||||||
{
|
{
|
||||||
if (!fDone)
|
if (!fDone)
|
||||||
Complete();
|
Complete();
|
||||||
LEAVE_CRITICAL_SECTION(m_queue.m_control_mutex);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user