From 1375dbd4c27dd5b1b420e91458627bf24a05c3ae Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 8 Oct 2022 20:06:18 +0200 Subject: [PATCH] Only shutdown the thread if it's actually running --- src/BackgroundThread.cpp | 12 ++++++++---- src/utils/CThread.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/BackgroundThread.cpp b/src/BackgroundThread.cpp index 54adcc3..7b2a59e 100644 --- a/src/BackgroundThread.cpp +++ b/src/BackgroundThread.cpp @@ -14,10 +14,14 @@ BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread: } BackgroundThread::~BackgroundThread() { - DEBUG_FUNCTION_LINE("Shutting down FTP Server"); - stopThread(); - while (!hasThreadStopped()) { - OSSleepTicks(OSMillisecondsToTicks(10)); + if (!isThreadTerminated()) { + DEBUG_FUNCTION_LINE("Shutting down FTP Server"); + stopThread(); + while (!hasThreadStopped()) { + OSSleepTicks(OSMillisecondsToTicks(10)); + } + } else { + DEBUG_FUNCTION_LINE_WARN("Thread is already terminated"); } if (this->serverSocket >= 0) { cleanup_ftp(); diff --git a/src/utils/CThread.h b/src/utils/CThread.h index 2d89ccd..90b1bfc 100644 --- a/src/utils/CThread.h +++ b/src/utils/CThread.h @@ -89,7 +89,7 @@ public: } //! Check if thread is terminated - [[nodiscard]] virtual BOOL isThreadTerminated() const { + [[nodiscard]] BOOL isThreadTerminated() const { if (pThread) return OSIsThreadTerminated(pThread); return false; }