diff options
author | madmaxoft <github@xoft.cz> | 2013-08-11 19:40:15 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-08-11 19:40:15 +0200 |
commit | 2baa6634ec797d4a64c25fca9b5a0451b69bf886 (patch) | |
tree | b56730c231f4da99b2bdd88f5490d292c00e6edd /source | |
parent | Moved MaxPlayers and Description from cWorld to cServer. (diff) | |
download | cuberite-2baa6634ec797d4a64c25fca9b5a0451b69bf886.tar cuberite-2baa6634ec797d4a64c25fca9b5a0451b69bf886.tar.gz cuberite-2baa6634ec797d4a64c25fca9b5a0451b69bf886.tar.bz2 cuberite-2baa6634ec797d4a64c25fca9b5a0451b69bf886.tar.lz cuberite-2baa6634ec797d4a64c25fca9b5a0451b69bf886.tar.xz cuberite-2baa6634ec797d4a64c25fca9b5a0451b69bf886.tar.zst cuberite-2baa6634ec797d4a64c25fca9b5a0451b69bf886.zip |
Diffstat (limited to 'source')
-rw-r--r-- | source/OSSupport/IsThread.cpp | 44 | ||||
-rw-r--r-- | source/OSSupport/IsThread.h | 4 |
2 files changed, 26 insertions, 22 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 } diff --git a/source/OSSupport/IsThread.h b/source/OSSupport/IsThread.h index 2a4451a4a..e795b25a0 100644 --- a/source/OSSupport/IsThread.h +++ b/source/OSSupport/IsThread.h @@ -39,6 +39,9 @@ public: /// Starts the thread; returns without waiting for the actual start bool Start(void); + /// Signals the thread to terminate and waits until it's finished + void Stop(void); + /// Waits for the thread to finish. Doesn't signalize the ShouldTerminate flag bool Wait(void); @@ -70,7 +73,6 @@ private: } #endif // else _WIN32 - } ; |