1
0
Fork 0

Fix race condition

This commit is contained in:
tycho 2015-12-19 21:48:19 +00:00 committed by Mattes D
parent bb79b5f436
commit d4289eee3c
2 changed files with 4 additions and 2 deletions

View File

@ -119,7 +119,7 @@ void cSpawnPrepare::PreparedChunkCallback(int a_ChunkX, int a_ChunkZ)
float PercentDone = static_cast<float>(m_NumPrepared * 100) / m_MaxIdx;
float ChunkSpeed = static_cast<float>((m_NumPrepared - m_LastReportChunkCount) * 1000) / std::chrono::duration_cast<std::chrono::milliseconds>(Now - m_LastReportTime).count();
LOG("Preparing spawn (%s): %.02f%% (%d/%d; %.02f chunks / sec)",
m_World.GetName().c_str(), PercentDone, m_NumPrepared, m_MaxIdx, ChunkSpeed
m_World.GetName().c_str(), PercentDone, m_NumPrepared.load(std::memory_order_seq_cst), m_MaxIdx, ChunkSpeed
);
m_LastReportTime = Now;
m_LastReportChunkCount = m_NumPrepared;

View File

@ -1,6 +1,8 @@
#pragma once
#include <atomic>
class cWorld;
@ -25,7 +27,7 @@ protected:
int m_MaxIdx;
/** Total number of chunks already finished preparing. Preparation finishes when this number reaches m_MaxIdx. */
int m_NumPrepared;
std::atomic<int> m_NumPrepared;
/** Event used to signal that the preparation is finished. */
cEvent m_EvtFinished;