Only shutdown the thread if it's actually running

This commit is contained in:
Maschell 2022-10-08 20:06:18 +02:00
parent 09412116ad
commit 1375dbd4c2
2 changed files with 9 additions and 5 deletions

View File

@ -14,10 +14,14 @@ BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread:
} }
BackgroundThread::~BackgroundThread() { BackgroundThread::~BackgroundThread() {
DEBUG_FUNCTION_LINE("Shutting down FTP Server"); if (!isThreadTerminated()) {
stopThread(); DEBUG_FUNCTION_LINE("Shutting down FTP Server");
while (!hasThreadStopped()) { stopThread();
OSSleepTicks(OSMillisecondsToTicks(10)); while (!hasThreadStopped()) {
OSSleepTicks(OSMillisecondsToTicks(10));
}
} else {
DEBUG_FUNCTION_LINE_WARN("Thread is already terminated");
} }
if (this->serverSocket >= 0) { if (this->serverSocket >= 0) {
cleanup_ftp(); cleanup_ftp();

View File

@ -89,7 +89,7 @@ public:
} }
//! Check if thread is terminated //! Check if thread is terminated
[[nodiscard]] virtual BOOL isThreadTerminated() const { [[nodiscard]] BOOL isThreadTerminated() const {
if (pThread) return OSIsThreadTerminated(pThread); if (pThread) return OSIsThreadTerminated(pThread);
return false; return false;
} }