1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-31 00:34:20 +00:00

fixed race condition

This commit is contained in:
orignal 2015-01-03 15:20:11 -05:00
parent 729cc4330e
commit 41974b8c75
2 changed files with 30 additions and 24 deletions

View File

@ -85,34 +85,40 @@ namespace client
void ClientDestination::Start () void ClientDestination::Start ()
{ {
m_Pool->SetLocalDestination (this); if (!m_IsRunning)
m_Pool->SetActive (true); {
m_IsRunning = true; m_IsRunning = true;
m_Thread = new std::thread (std::bind (&ClientDestination::Run, this)); m_Pool->SetLocalDestination (this);
m_StreamingDestination->Start (); m_Pool->SetActive (true);
m_Thread = new std::thread (std::bind (&ClientDestination::Run, this));
m_StreamingDestination->Start ();
}
} }
void ClientDestination::Stop () void ClientDestination::Stop ()
{ {
m_StreamingDestination->Stop (); if (m_IsRunning)
if (m_DatagramDestination)
{
auto d = m_DatagramDestination;
m_DatagramDestination = nullptr;
delete d;
}
if (m_Pool)
{ {
m_Pool->SetLocalDestination (nullptr); m_IsRunning = false;
i2p::tunnel::tunnels.StopTunnelPool (m_Pool); m_StreamingDestination->Stop ();
} if (m_DatagramDestination)
m_IsRunning = false; {
m_Service.stop (); auto d = m_DatagramDestination;
if (m_Thread) m_DatagramDestination = nullptr;
{ delete d;
m_Thread->join (); }
delete m_Thread; if (m_Pool)
m_Thread = 0; {
m_Pool->SetLocalDestination (nullptr);
i2p::tunnel::tunnels.StopTunnelPool (m_Pool);
}
m_Service.stop ();
if (m_Thread)
{
m_Thread->join ();
delete m_Thread;
m_Thread = 0;
}
} }
} }

View File

@ -112,7 +112,7 @@ namespace client
private: private:
bool m_IsRunning; volatile bool m_IsRunning;
std::thread * m_Thread; std::thread * m_Thread;
boost::asio::io_service m_Service; boost::asio::io_service m_Service;
boost::asio::io_service::work m_Work; boost::asio::io_service::work m_Work;