mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-12-23 03:11:49 +01:00
Wait with thread cleanup until the thread has ended
This commit is contained in:
parent
f5d6c3d508
commit
47b059cb48
@ -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);
|
||||
|
@ -121,7 +121,6 @@ void startServer() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void stopServer() {
|
||||
BackgroundThread::destroyInstance();
|
||||
if (gMochaPathsWereMounted) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user