fixed race condition

This commit is contained in:
orignal 2014-10-04 16:27:21 -04:00
parent 9a617297f2
commit 9750fb73b5
2 changed files with 40 additions and 21 deletions

View File

@ -102,7 +102,7 @@ namespace data
{
try
{
I2NPMessage * msg = m_Queue.GetNextWithTimeout (10000); // 10 sec
I2NPMessage * msg = m_Queue.GetNextWithTimeout (30000); // 30 sec
if (msg)
{
while (msg)

View File

@ -38,19 +38,24 @@ namespace stream
Stream::~Stream ()
{
Close ();
m_ReceiveTimer.cancel ();
m_ResendTimer.cancel ();
while (!m_ReceiveQueue.empty ())
{
auto packet = m_ReceiveQueue.front ();
m_ReceiveQueue.pop ();
delete packet;
}
for (auto it: m_SavedPackets)
delete it;
m_ReceiveTimer.cancel ();
for (auto it: m_SentPackets)
delete it;
m_SentPackets.clear ();
m_ResendTimer.cancel ();
for (auto it: m_SavedPackets)
delete it;
m_SavedPackets.clear ();
Close ();
}
void Stream::HandleNextPacket (Packet * packet)
@ -387,10 +392,13 @@ namespace stream
if (packet)
{
SendPackets (std::vector<Packet *> { packet });
bool isEmpty = m_SentPackets.empty ();
m_SentPackets.insert (packet);
if (isEmpty)
ScheduleResend ();
if (m_IsOpen)
{
bool isEmpty = m_SentPackets.empty ();
m_SentPackets.insert (packet);
if (isEmpty)
ScheduleResend ();
}
return true;
}
else
@ -565,8 +573,12 @@ namespace stream
StreamingDestination::~StreamingDestination ()
{
for (auto it: m_Streams)
delete it.second;
{
std::unique_lock<std::mutex> l(m_StreamsMutex);
for (auto it: m_Streams)
delete it.second;
m_Streams.clear ();
}
if (m_Pool)
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
delete m_LeaseSet;
@ -621,8 +633,12 @@ namespace stream
if (stream)
{
std::unique_lock<std::mutex> l(m_StreamsMutex);
m_Streams.erase (stream->GetRecvStreamID ());
delete stream;
auto it = m_Streams.find (stream->GetRecvStreamID ());
if (it != m_Streams.end ())
{
m_Streams.erase (it);
delete stream;
}
}
}
@ -738,9 +754,12 @@ namespace stream
auto it = m_Destinations.find (destination->GetIdentHash ());
if (it != m_Destinations.end ())
{
delete it->second;
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations.erase (it);
auto d = it->second;
{
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations.erase (it);
}
delete d;
}
}