Fixed a possible crash in ChunkSender - a client would be reported as removed but still would be in the internal queue.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@438 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
ce053d1b9b
commit
fcb9b281e0
@ -105,6 +105,7 @@ void cChunkSender::RemoveClient(cClientHandle * a_Client)
|
|||||||
}
|
}
|
||||||
++itr;
|
++itr;
|
||||||
} // for itr - m_SendChunks[]
|
} // for itr - m_SendChunks[]
|
||||||
|
m_RemoveCount++;
|
||||||
}
|
}
|
||||||
m_evtQueue.Set();
|
m_evtQueue.Set();
|
||||||
m_evtRemoved.Wait(); // Wait for removal confirmation
|
m_evtRemoved.Wait(); // Wait for removal confirmation
|
||||||
@ -121,8 +122,13 @@ void cChunkSender::Execute(void)
|
|||||||
cCSLock Lock(m_CS);
|
cCSLock Lock(m_CS);
|
||||||
while (m_ChunksReady.empty() && m_SendChunks.empty())
|
while (m_ChunksReady.empty() && m_SendChunks.empty())
|
||||||
{
|
{
|
||||||
|
int RemoveCount = m_RemoveCount;
|
||||||
|
m_RemoveCount = 0;
|
||||||
cCSUnlock Unlock(Lock);
|
cCSUnlock Unlock(Lock);
|
||||||
m_evtRemoved.Set(); // Notify that the removed clients are safe to be deleted
|
for (int i = 0; i < RemoveCount; i++)
|
||||||
|
{
|
||||||
|
m_evtRemoved.Set(); // Notify that the removed clients are safe to be deleted
|
||||||
|
}
|
||||||
m_evtQueue.Wait();
|
m_evtQueue.Wait();
|
||||||
if (m_ShouldTerminate)
|
if (m_ShouldTerminate)
|
||||||
{
|
{
|
||||||
@ -148,7 +154,14 @@ void cChunkSender::Execute(void)
|
|||||||
|
|
||||||
SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkY, Chunk.m_ChunkZ, Chunk.m_Client);
|
SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkY, Chunk.m_ChunkZ, Chunk.m_Client);
|
||||||
}
|
}
|
||||||
m_evtRemoved.Set(); // Notify that the removed clients are safe to be deleted
|
Lock.Lock();
|
||||||
|
int RemoveCount = m_RemoveCount;
|
||||||
|
m_RemoveCount = 0;
|
||||||
|
Lock.Unlock();
|
||||||
|
for (int i = 0; i < RemoveCount; i++)
|
||||||
|
{
|
||||||
|
m_evtRemoved.Set(); // Notify that the removed clients are safe to be deleted
|
||||||
|
}
|
||||||
} // while (!mShouldTerminate)
|
} // while (!mShouldTerminate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ protected:
|
|||||||
sSendChunkList m_SendChunks;
|
sSendChunkList m_SendChunks;
|
||||||
cEvent m_evtQueue; // Set when anything is added to m_ChunksReady
|
cEvent m_evtQueue; // Set when anything is added to m_ChunksReady
|
||||||
cEvent m_evtRemoved; // Set when removed clients are safe to be deleted
|
cEvent m_evtRemoved; // Set when removed clients are safe to be deleted
|
||||||
|
int m_RemoveCount; // Number of threads waiting for a client removal (m_evtRemoved needs to be set this many times)
|
||||||
|
|
||||||
// Data about the chunk that is being sent:
|
// Data about the chunk that is being sent:
|
||||||
// NOTE that m_BlockData[] is inherited from the cChunkDataCollector
|
// NOTE that m_BlockData[] is inherited from the cChunkDataCollector
|
||||||
|
Loading…
Reference in New Issue
Block a user