Fix joining the thread

This commit is contained in:
Maschell 2022-10-06 23:07:36 +02:00
parent ca47e10a0c
commit a8a3287ebf
2 changed files with 11 additions and 24 deletions

View File

@ -28,23 +28,19 @@ INITIALIZE_PLUGIN() {
/* Entry point */ /* Entry point */
ON_APPLICATION_START() { ON_APPLICATION_START() {
initLogging(); initLogging();
if (thread != nullptr) {
DEBUG_FUNCTION_LINE_WARN("The wiiload thread is still allocated but not running.");
thread->skipJoin = true;
delete thread;
thread = nullptr;
}
DEBUG_FUNCTION_LINE("Start wiiload thread"); DEBUG_FUNCTION_LINE("Start wiiload thread");
thread = new TcpReceiver(4299); thread = new (std::nothrow) TcpReceiver(4299);
if (thread == nullptr) {
DEBUG_FUNCTION_LINE_ERR("Failed to create wiiload thread");
}
} }
ON_APPLICATION_ENDS() { ON_APPLICATION_ENDS() {
DEBUG_FUNCTION_LINE("Stop wiiload thread"); DEBUG_FUNCTION_LINE("Stop wiiload thread!");
if (thread != nullptr) { if (thread != nullptr) {
delete thread; delete thread;
thread = nullptr; thread = nullptr;
} }
DEBUG_FUNCTION_LINE_VERBOSE("Done!");
deinitLogging(); deinitLogging();
} }

View File

@ -100,20 +100,12 @@ public:
//! Shutdown thread //! Shutdown thread
void shutdownThread() { void shutdownThread() {
if (skipJoin) {
DEBUG_FUNCTION_LINE_WARN("Skip joining the thread \"%s\", it's not running.", pThreadName.c_str());
} else {
//! wait for thread to finish //! wait for thread to finish
if (!skipJoin && pThread && !(iAttributes & eAttributeDetach)) { if (pThread && !(iAttributes & eAttributeDetach)) {
if (!OSIsThreadTerminated(pThread)) {
if (isThreadSuspended()) { if (isThreadSuspended()) {
resumeThread(); resumeThread();
} }
OSJoinThread(pThread, nullptr); OSJoinThread(pThread, nullptr);
} else {
DEBUG_FUNCTION_LINE_WARN("Thread \"%s\" has already been terminated!!!", pThreadName.c_str());
}
}
} }
//! free the thread stack buffer //! free the thread stack buffer
@ -137,7 +129,6 @@ public:
eAttributeDetach = 0x08, eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10 eAttributePinnedAff = 0x10
}; };
bool skipJoin = false;
private: private:
static int threadCallback(int argc, const char **argv) { static int threadCallback(int argc, const char **argv) {