Skip to content

Commit

Permalink
Iteration fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kareldonk committed Sep 4, 2019
1 parent 4bd9181 commit 0c45417
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions QuantumGateLib/Core/KeyGeneration/KeyGenerationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,24 @@ namespace QuantumGate::Implementation::Core::KeyGeneration
{
m_KeyQueues.WithUniqueLock([&](KeyQueueMap& queues)
{
for (auto it = queues.begin(); it != queues.end() && !shutdown_event.IsSet(); ++it)
auto it = queues.begin();
while (it != queues.end() && !shutdown_event.IsSet())
{
auto active = false;
Size num_pending_events{ 0 };
auto erase = false;

it->second->WithUniqueLock([&](KeyQueue& key_queue)
{
active = key_queue.Active;
num_pending_events = key_queue.NumPendingEvents;
if (!key_queue.Active && key_queue.NumPendingEvents == 0)
{
erase = true;
}
});

if (!active && num_pending_events == 0) it = queues.erase(it);
if (erase)
{
it = queues.erase(it);
}
else ++it;
}
});

Expand Down

0 comments on commit 0c45417

Please sign in to comment.