summaryrefslogtreecommitdiff
path: root/src/threading
diff options
context:
space:
mode:
authorSebastien Marie <semarie@users.noreply.github.com>2020-09-10 12:19:18 +0200
committerGitHub <noreply@github.com>2020-09-10 12:19:18 +0200
commit3fb1f45301880a3aa901b752af1ecc912efe5915 (patch)
tree58545af949274d8d7560337755760b3eb5019a1b /src/threading
parent0683bea283d456253de343f37720789382ece6b2 (diff)
downloadminetest-3fb1f45301880a3aa901b752af1ecc912efe5915.tar.gz
minetest-3fb1f45301880a3aa901b752af1ecc912efe5915.tar.bz2
minetest-3fb1f45301880a3aa901b752af1ecc912efe5915.zip
Remove Thread::kill() and related unittest (#10317)
Closes: #6065
Diffstat (limited to 'src/threading')
-rw-r--r--src/threading/thread.cpp54
-rw-r--r--src/threading/thread.h8
2 files changed, 22 insertions, 40 deletions
diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp
index e19e6ae60..5cfc60995 100644
--- a/src/threading/thread.cpp
+++ b/src/threading/thread.cpp
@@ -73,7 +73,28 @@ Thread::Thread(const std::string &name) :
Thread::~Thread()
{
- kill();
+ // kill the thread if running
+ if (!m_running) {
+ wait();
+ } else {
+
+ m_running = false;
+
+#if defined(_WIN32)
+ // See https://msdn.microsoft.com/en-us/library/hh920601.aspx#thread__native_handle_method
+ TerminateThread((HANDLE) m_thread_obj->native_handle(), 0);
+ CloseHandle((HANDLE) m_thread_obj->native_handle());
+#else
+ // We need to pthread_kill instead on Android since NDKv5's pthread
+ // implementation is incomplete.
+# ifdef __ANDROID__
+ pthread_kill(getThreadHandle(), SIGKILL);
+# else
+ pthread_cancel(getThreadHandle());
+# endif
+ wait();
+#endif
+ }
// Make sure start finished mutex is unlocked before it's destroyed
if (m_start_finished_mutex.try_lock())
@@ -138,37 +159,6 @@ bool Thread::wait()
}
-bool Thread::kill()
-{
- if (!m_running) {
- wait();
- return false;
- }
-
- m_running = false;
-
-#if defined(_WIN32)
- // See https://msdn.microsoft.com/en-us/library/hh920601.aspx#thread__native_handle_method
- TerminateThread((HANDLE) m_thread_obj->native_handle(), 0);
- CloseHandle((HANDLE) m_thread_obj->native_handle());
-#else
- // We need to pthread_kill instead on Android since NDKv5's pthread
- // implementation is incomplete.
-# ifdef __ANDROID__
- pthread_kill(getThreadHandle(), SIGKILL);
-# else
- pthread_cancel(getThreadHandle());
-# endif
- wait();
-#endif
-
- m_retval = nullptr;
- m_joinable = false;
- m_request_stop = false;
-
- return true;
-}
-
bool Thread::getReturnValue(void **ret)
{
diff --git a/src/threading/thread.h b/src/threading/thread.h
index 3946335f5..45fb171da 100644
--- a/src/threading/thread.h
+++ b/src/threading/thread.h
@@ -75,14 +75,6 @@ public:
bool stop();
/*
- * Immediately terminates the thread.
- * This should be used with extreme caution, as the thread will not have
- * any opportunity to release resources it may be holding (such as memory
- * or locks).
- */
- bool kill();
-
- /*
* Waits for thread to finish.
* Note: This does not stop a thread, you have to do this on your own.
* Returns false immediately if the thread is not started or has been waited