mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-13 20:36:21 +01:00
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:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user