Browse Source

fixed race condtion #350

pull/352/head
orignal 9 years ago
parent
commit
85830d5076
  1. 8
      Transports.cpp

8
Transports.cpp

@ -69,21 +69,21 @@ namespace transport
std::shared_ptr<i2p::crypto::DHKeys> DHKeysPairSupplier::Acquire () std::shared_ptr<i2p::crypto::DHKeys> DHKeysPairSupplier::Acquire ()
{ {
if (!m_Queue.empty ())
{ {
std::unique_lock<std::mutex> l(m_AcquiredMutex); std::unique_lock<std::mutex> l(m_AcquiredMutex);
if (!m_Queue.empty ())
{
auto pair = m_Queue.front (); auto pair = m_Queue.front ();
m_Queue.pop (); m_Queue.pop ();
m_Acquired.notify_one (); m_Acquired.notify_one ();
return pair; return pair;
} }
else // queue is empty, create new }
{ // queue is empty, create new
auto pair = std::make_shared<i2p::crypto::DHKeys> (); auto pair = std::make_shared<i2p::crypto::DHKeys> ();
pair->GenerateKeys (); pair->GenerateKeys ();
return pair; return pair;
} }
}
void DHKeysPairSupplier::Return (std::shared_ptr<i2p::crypto::DHKeys> pair) void DHKeysPairSupplier::Return (std::shared_ptr<i2p::crypto::DHKeys> pair)
{ {

Loading…
Cancel
Save