Skip to content

Commit

Permalink
Acquire CCheckQueue's lock to avoid race condition
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sdaftuar committed Feb 3, 2015
1 parent b6acd45 commit cf008ac
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/checkqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ class CCheckQueue
{
}

friend class CCheckQueueControl<T>;
bool IsIdle()
{
boost::unique_lock<boost::mutex> lock(mutex);
return (nTotal == nIdle && nTodo == 0 && fAllOk == true);
}

};

/**
Expand All @@ -180,9 +185,8 @@ class CCheckQueueControl
{
// 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);
}
}

Expand Down

0 comments on commit cf008ac

Please sign in to comment.