mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
fixed race condtion #350
This commit is contained in:
parent
c053bebccd
commit
85830d5076
@ -69,20 +69,20 @@ 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);
|
||||||
auto pair = m_Queue.front ();
|
if (!m_Queue.empty ())
|
||||||
m_Queue.pop ();
|
{
|
||||||
m_Acquired.notify_one ();
|
auto pair = m_Queue.front ();
|
||||||
return pair;
|
m_Queue.pop ();
|
||||||
|
m_Acquired.notify_one ();
|
||||||
|
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…
x
Reference in New Issue
Block a user