Improved threading performance by reducing thread-hopping in queue locks (cs unlocked before event set)
git-svn-id: http://mc-server.googlecode.com/svn/trunk@341 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
a4503ddb77
commit
5d0da9a2c0
@ -199,6 +199,7 @@ int cWorldStorage::GetSaveQueueLength(void)
|
||||
void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate)
|
||||
{
|
||||
// Queues the chunk for loading; if not loaded, the chunk will be generated
|
||||
{
|
||||
cCSLock Lock(m_CSQueues);
|
||||
|
||||
// Check if already in the queue:
|
||||
@ -210,6 +211,8 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, boo
|
||||
}
|
||||
}
|
||||
m_LoadQueue.push_back(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate));
|
||||
}
|
||||
|
||||
m_Event.Set();
|
||||
}
|
||||
|
||||
@ -218,10 +221,12 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, boo
|
||||
|
||||
|
||||
void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
|
||||
{
|
||||
{
|
||||
cCSLock Lock(m_CSQueues);
|
||||
m_SaveQueue.remove (cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); // Don't add twice
|
||||
m_SaveQueue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ));
|
||||
}
|
||||
m_Event.Set();
|
||||
}
|
||||
|
||||
@ -239,6 +244,7 @@ void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
|
||||
continue;
|
||||
}
|
||||
m_LoadQueue.erase(itr);
|
||||
Lock.Unlock();
|
||||
m_evtRemoved.Set();
|
||||
return;
|
||||
} // for itr - m_LoadQueue[]
|
||||
@ -249,9 +255,11 @@ void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
|
||||
|
||||
|
||||
void cWorldStorage::UnqueueSave(const cChunkCoords & a_Chunk)
|
||||
{
|
||||
{
|
||||
cCSLock Lock(m_CSQueues);
|
||||
m_SaveQueue.remove(a_Chunk);
|
||||
}
|
||||
m_evtRemoved.Set();
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,7 @@ void cChunkGenerator::Stop(void)
|
||||
|
||||
|
||||
void cChunkGenerator::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
|
||||
{
|
||||
{
|
||||
cCSLock Lock(m_CS);
|
||||
|
||||
@ -102,6 +103,7 @@ void cChunkGenerator::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
|
||||
LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (%i)", a_ChunkX, a_ChunkZ, m_Queue.size());
|
||||
}
|
||||
m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ));
|
||||
}
|
||||
|
||||
m_Event.Set();
|
||||
}
|
||||
|
@ -713,10 +713,12 @@ void cServer::cNotifyWriteThread::Execute(void)
|
||||
|
||||
|
||||
void cServer::cNotifyWriteThread::NotifyClientWrite(const cClientHandle * a_Client)
|
||||
{
|
||||
{
|
||||
cCSLock Lock(m_CS);
|
||||
m_Clients.remove(const_cast<cClientHandle *>(a_Client)); // Put it there only once
|
||||
m_Clients.push_back(const_cast<cClientHandle *>(a_Client));
|
||||
}
|
||||
m_Event.Set();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user