Skip to content

Commit c43aa62

Browse files
committed
Avoid excessive lock contention in CCheckQueue::Add
1 parent 7efc628 commit c43aa62

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/checkqueue.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,15 @@ class CCheckQueue
167167
//! Add a batch of checks to the queue
168168
void Add(std::vector<T>& vChecks)
169169
{
170-
LOCK(m_mutex);
171-
for (T& check : vChecks) {
172-
queue.push_back(T());
173-
check.swap(queue.back());
170+
{
171+
LOCK(m_mutex);
172+
for (T& check : vChecks) {
173+
queue.emplace_back();
174+
check.swap(queue.back());
175+
}
176+
nTodo += vChecks.size();
174177
}
175-
nTodo += vChecks.size();
178+
176179
if (vChecks.size() == 1)
177180
m_worker_cv.notify_one();
178181
else if (vChecks.size() > 1)

0 commit comments

Comments
 (0)