summaryrefslogtreecommitdiffstats
path: root/source/OSSupport/IsThread.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2013-08-15 10:56:52 +0200
committerMattes D <github@xoft.cz>2013-08-15 10:56:52 +0200
commit1a52e89177a907b5d23d3e72f78d30a333da4bfe (patch)
tree8f2783d06d423361b02457c77f90d6ec874a5191 /source/OSSupport/IsThread.cpp
parentMerge pull request #91 from tigerw/master (diff)
parentAdded simple deadlock detection code. (diff)
downloadcuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.gz
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.bz2
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.lz
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.xz
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.tar.zst
cuberite-1a52e89177a907b5d23d3e72f78d30a333da4bfe.zip
Diffstat (limited to 'source/OSSupport/IsThread.cpp')
-rw-r--r--source/OSSupport/IsThread.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/source/OSSupport/IsThread.cpp b/source/OSSupport/IsThread.cpp
index 257c5c876..45e329a68 100644
--- a/source/OSSupport/IsThread.cpp
+++ b/source/OSSupport/IsThread.cpp
@@ -116,36 +116,38 @@ bool cIsThread::Start(void)
+void cIsThread::Stop(void)
+{
+ if (m_Handle == NULL)
+ {
+ return;
+ }
+ m_ShouldTerminate = true;
+ Wait();
+}
+
+
+
+
+
bool cIsThread::Wait(void)
{
- #ifdef _WIN32
+ if (m_Handle == NULL)
+ {
+ return true;
+ }
+ LOGD("Waiting for thread %s to finish", m_ThreadName.c_str());
- if (m_Handle == NULL)
- {
- return true;
- }
- // Cannot log, logger may already be stopped:
- // LOG("Waiting for thread \"%s\" to terminate.", m_ThreadName.c_str());
+ #ifdef _WIN32
int res = WaitForSingleObject(m_Handle, INFINITE);
m_Handle = NULL;
- // Cannot log, logger may already be stopped:
- // LOG("Thread \"%s\" %s terminated, GLE = %d", m_ThreadName.c_str(), (res == WAIT_OBJECT_0) ? "" : "not", GetLastError());
+ LOGD("Thread %s finished", m_ThreadName.c_str());
return (res == WAIT_OBJECT_0);
-
#else // _WIN32
-
- if (!m_HasStarted)
- {
- return true;
- }
- // Cannot log, logger may already be stopped:
- // LOG("Waiting for thread \"%s\" to terminate.", m_ThreadName.c_str());
int res = pthread_join(m_Handle, NULL);
- m_HasStarted = false;
- // Cannot log, logger may already be stopped:
- // LOG("Thread \"%s\" %s terminated, errno = %d", m_ThreadName.c_str(), (res == 0) ? "" : "not", errno);
+ m_Handle = NULL;
+ LOGD("Thread %s finished", m_ThreadName.c_str());
return (res == 0);
-
#endif // else _WIN32
}