Wait with thread cleanup until the thread has ended

This commit is contained in:
Maschell 2022-10-08 15:43:49 +02:00
parent f5d6c3d508
commit 47b059cb48
4 changed files with 19 additions and 4 deletions

View File

@ -15,6 +15,10 @@ BackgroundThread::BackgroundThread() : BackgroundThreadWrapper(BackgroundThread:
BackgroundThread::~BackgroundThread() {
DEBUG_FUNCTION_LINE("Shutting down FTP Server");
stopThread();
while (!hasThreadStopped()) {
OSSleepTicks(OSMillisecondsToTicks(10));
}
if (this->serverSocket >= 0) {
cleanup_ftp();
network_close(this->serverSocket);

View File

@ -121,7 +121,6 @@ void startServer() {
}
}
void stopServer() {
BackgroundThread::destroyInstance();
if (gMochaPathsWereMounted) {

View File

@ -6,6 +6,7 @@ BackgroundThreadWrapper::BackgroundThreadWrapper(int32_t priority) : CThread(CTh
BackgroundThreadWrapper::~BackgroundThreadWrapper() {
exitThread = 1;
stopThread();
OSMemoryBarrier();
}
@ -18,4 +19,6 @@ void BackgroundThreadWrapper::executeThread() {
break;
}
}
threadEnded = true;
OSMemoryBarrier();
}

View File

@ -12,17 +12,26 @@ public:
protected:
[[nodiscard]] BOOL shouldExit() const {
return (exitThread == 1);
return (exitThread);
}
void setThreadPriority(int32_t priority) override {
CThread::setThreadPriority(priority);
}
void stopThread() {
exitThread = true;
}
bool hasThreadStopped() {
return threadEnded;
}
private:
volatile bool threadEnded = false;
volatile bool exitThread = false;
void executeThread() override;
virtual BOOL whileLoop() = 0;
volatile int32_t exitThread = 0;
};