Skip to content

Commit 1a37507

Browse files
theuniryanofsky
andcommitted
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>
1 parent c3b0e6c commit 1a37507

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/checkqueue.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,18 @@ class CCheckQueue
205205
* queue is finished before continuing.
206206
*/
207207
template <typename T, typename R = std::remove_cvref_t<decltype(std::declval<T>()().value())>>
208-
class CCheckQueueControl
208+
class SCOPED_LOCKABLE CCheckQueueControl
209209
{
210210
private:
211211
CCheckQueue<T, R>& m_queue;
212+
UniqueLock<Mutex> m_lock;
212213
bool fDone;
213214

214215
public:
215216
CCheckQueueControl() = delete;
216217
CCheckQueueControl(const CCheckQueueControl&) = delete;
217218
CCheckQueueControl& operator=(const CCheckQueueControl&) = delete;
218-
explicit CCheckQueueControl(CCheckQueue<T>& queueIn) : m_queue(queueIn), fDone(false)
219-
{
220-
ENTER_CRITICAL_SECTION(m_queue.m_control_mutex);
221-
}
219+
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) {}
222220

223221
std::optional<R> Complete()
224222
{
@@ -232,11 +230,10 @@ class CCheckQueueControl
232230
m_queue.Add(std::move(vChecks));
233231
}
234232

235-
~CCheckQueueControl()
233+
~CCheckQueueControl() UNLOCK_FUNCTION()
236234
{
237235
if (!fDone)
238236
Complete();
239-
LEAVE_CRITICAL_SECTION(m_queue.m_control_mutex);
240237
}
241238
};
242239

0 commit comments

Comments
 (0)