mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-12-23 11:21: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() {
|
BackgroundThread::~BackgroundThread() {
|
||||||
DEBUG_FUNCTION_LINE("Shutting down FTP Server");
|
DEBUG_FUNCTION_LINE("Shutting down FTP Server");
|
||||||
|
stopThread();
|
||||||
|
while (!hasThreadStopped()) {
|
||||||
|
OSSleepTicks(OSMillisecondsToTicks(10));
|
||||||
|
}
|
||||||
if (this->serverSocket >= 0) {
|
if (this->serverSocket >= 0) {
|
||||||
cleanup_ftp();
|
cleanup_ftp();
|
||||||
network_close(this->serverSocket);
|
network_close(this->serverSocket);
|
||||||
|
@ -121,7 +121,6 @@ void startServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void stopServer() {
|
void stopServer() {
|
||||||
BackgroundThread::destroyInstance();
|
BackgroundThread::destroyInstance();
|
||||||
if (gMochaPathsWereMounted) {
|
if (gMochaPathsWereMounted) {
|
||||||
|
@ -6,6 +6,7 @@ BackgroundThreadWrapper::BackgroundThreadWrapper(int32_t priority) : CThread(CTh
|
|||||||
|
|
||||||
BackgroundThreadWrapper::~BackgroundThreadWrapper() {
|
BackgroundThreadWrapper::~BackgroundThreadWrapper() {
|
||||||
exitThread = 1;
|
exitThread = 1;
|
||||||
|
stopThread();
|
||||||
OSMemoryBarrier();
|
OSMemoryBarrier();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,4 +19,6 @@ void BackgroundThreadWrapper::executeThread() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
threadEnded = true;
|
||||||
|
OSMemoryBarrier();
|
||||||
}
|
}
|
||||||
|
@ -12,17 +12,26 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] BOOL shouldExit() const {
|
[[nodiscard]] BOOL shouldExit() const {
|
||||||
return (exitThread == 1);
|
return (exitThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setThreadPriority(int32_t priority) override {
|
void setThreadPriority(int32_t priority) override {
|
||||||
CThread::setThreadPriority(priority);
|
CThread::setThreadPriority(priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stopThread() {
|
||||||
|
exitThread = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasThreadStopped() {
|
||||||
|
return threadEnded;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
volatile bool threadEnded = false;
|
||||||
|
volatile bool exitThread = false;
|
||||||
|
|
||||||
void executeThread() override;
|
void executeThread() override;
|
||||||
|
|
||||||
virtual BOOL whileLoop() = 0;
|
virtual BOOL whileLoop() = 0;
|
||||||
|
|
||||||
volatile int32_t exitThread = 0;
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user