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

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;
} }