Acquire CCheckQueue's lock to avoid race condition

This fixes a potential race condition in the CCheckQueueControl constructor,
which was looking directly at data in CCheckQueue without acquiring its lock.

Remove the now-unnecessary friendship for CCheckQueueControl

Rebased-From: cf008ac8c3
Github-Pull: #5721
This commit is contained in:
Suhas Daftuar 2015-01-28 13:48:36 -05:00 committed by Wladimir J. van der Laan
parent 7f502be259
commit d148f62e00
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6

View File

@ -161,7 +161,12 @@ public:
{
}
friend class CCheckQueueControl<T>;
bool IsIdle()
{
boost::unique_lock<boost::mutex> lock(mutex);
return (nTotal == nIdle && nTodo == 0 && fAllOk == true);
}
};
/**
@ -180,9 +185,8 @@ public:
{
// passed queue is supposed to be unused, or NULL
if (pqueue != NULL) {
assert(pqueue->nTotal == pqueue->nIdle);
assert(pqueue->nTodo == 0);
assert(pqueue->fAllOk == true);
bool isIdle = pqueue->IsIdle();
assert(isIdle);
}
}