From f8b2cd99a652def42f44efd82a77d90ff3d074de Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 31 Aug 2012 11:40:54 +0000 Subject: [PATCH] Fixed one possibility of a deadlock in cClientHandle::SendChunkData() git-svn-id: http://mc-server.googlecode.com/svn/trunk@809 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cClientHandle.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 0877dba2c..4db64cfde 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -90,6 +90,7 @@ cClientHandle::cClientHandle(const cSocket & a_Socket, int a_ViewDistance) , m_TimeLastPacket(cWorld::GetTime()) , m_bKeepThreadGoing(true) , m_Ping(1000) + , m_PingID(1) , m_State(csConnected) , m_LastStreamedChunkX(0x7fffffff) // bogus chunk coords to force streaming upon login , m_LastStreamedChunkZ(0x7fffffff) @@ -1350,21 +1351,23 @@ void cClientHandle::SendChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializ { // Check chunks being sent, erase them from m_ChunksToSend: bool Found = false; - cCSLock Lock(m_CSChunkLists); - for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr) { - if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) + cCSLock Lock(m_CSChunkLists); + for (cChunkCoordsList::iterator itr = m_ChunksToSend.begin(); itr != m_ChunksToSend.end(); ++itr) { - m_ChunksToSend.erase(itr); - - // TODO: _X: Decouple this from packet sending, it creates a deadlock possibility - // -- postpone till Tick() instead, using a bool flag - CheckIfWorldDownloaded(); - - Found = true; - break; - } - } // for itr - m_ChunksToSend[] + if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ)) + { + m_ChunksToSend.erase(itr); + + // TODO: _X: Decouple this from packet sending, it creates a deadlock possibility + // -- postpone till Tick() instead, using a bool flag + CheckIfWorldDownloaded(); + + Found = true; + break; + } + } // for itr - m_ChunksToSend[] + } if (!Found) { // This just sometimes happens. If you have a reliably replicatable situation for this, go ahead and fix it