summaryrefslogtreecommitdiffstats
path: root/Tools/AnvilStats/Processor.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-08-27 11:32:51 +0200
committerMattes D <github@xoft.cz>2014-08-27 11:32:51 +0200
commit3da27fb7a3f45bc5a82bba13e9b836c8b3dca6a5 (patch)
treef5ababf68358785f38268f7b21442b0f7c13790b /Tools/AnvilStats/Processor.cpp
parentAnvilStats: Rewritten to use CMake. (diff)
parentAnvilStats: Fixed thread start race condition. (diff)
downloadcuberite-3da27fb7a3f45bc5a82bba13e9b836c8b3dca6a5.tar
cuberite-3da27fb7a3f45bc5a82bba13e9b836c8b3dca6a5.tar.gz
cuberite-3da27fb7a3f45bc5a82bba13e9b836c8b3dca6a5.tar.bz2
cuberite-3da27fb7a3f45bc5a82bba13e9b836c8b3dca6a5.tar.lz
cuberite-3da27fb7a3f45bc5a82bba13e9b836c8b3dca6a5.tar.xz
cuberite-3da27fb7a3f45bc5a82bba13e9b836c8b3dca6a5.tar.zst
cuberite-3da27fb7a3f45bc5a82bba13e9b836c8b3dca6a5.zip
Diffstat (limited to '')
-rw-r--r--Tools/AnvilStats/Processor.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/Tools/AnvilStats/Processor.cpp b/Tools/AnvilStats/Processor.cpp
index a16f78c18..6c4bb0ad5 100644
--- a/Tools/AnvilStats/Processor.cpp
+++ b/Tools/AnvilStats/Processor.cpp
@@ -28,6 +28,7 @@ cProcessor::cThread::cThread(cCallback & a_Callback, cProcessor & a_ParentProces
m_Callback(a_Callback),
m_ParentProcessor(a_ParentProcessor)
{
+ LOG("Created a new thread: %p", this);
super::Start();
}
@@ -35,11 +36,20 @@ cProcessor::cThread::cThread(cCallback & a_Callback, cProcessor & a_ParentProces
+void cProcessor::cThread::WaitForStart(void)
+{
+ m_HasStarted.Wait();
+}
+
+
+
+
+
void cProcessor::cThread::Execute(void)
{
- LOG("Started a new thread: %d", cIsThread::GetCurrentID());
+ LOG("Started a new thread: %p, ID %d", this, cIsThread::GetCurrentID());
- m_ParentProcessor.m_ThreadsHaveStarted.Set();
+ m_HasStarted.Set();
for (;;)
{
@@ -52,7 +62,7 @@ void cProcessor::cThread::Execute(void)
ProcessFile(FileName);
} // for-ever
- LOG("Thread %d terminated", cIsThread::GetCurrentID());
+ LOG("Thread %p (ID %d) terminated", this, cIsThread::GetCurrentID());
}
@@ -522,20 +532,18 @@ void cProcessor::ProcessWorld(const AString & a_WorldFolder, cCallbackFactory &
#endif // _DEBUG
//*/
+ // Start all the threads:
for (int i = 0; i < NumThreads; i++)
{
cCallback * Callback = a_CallbackFactory.GetNewCallback();
m_Threads.push_back(new cThread(*Callback, *this));
}
- // Wait for the first thread to start processing:
- m_ThreadsHaveStarted.Wait();
-
- // Wait for all threads to finish
- // simply by calling each thread's destructor sequentially
+ // Wait for all threads to finish:
LOG("Waiting for threads to finish");
for (cThreads::iterator itr = m_Threads.begin(), end = m_Threads.end(); itr != end; ++itr)
{
+ (*itr)->WaitForStart();
delete *itr;
} // for itr - m_Threads[]
LOG("Processor finished");