Skip to content

Commit

Permalink
Only shutdown the thread if it's actually running
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Oct 8, 2022
1 parent 0941211 commit 1375dbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/BackgroundThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/CThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CThread {
}

//! Check if thread is terminated
[[nodiscard]] virtual BOOL isThreadTerminated() const {
[[nodiscard]] BOOL isThreadTerminated() const {
if (pThread) return OSIsThreadTerminated(pThread);
return false;
}
Expand Down

0 comments on commit 1375dbd

Please sign in to comment.