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 */
ON_APPLICATION_START() {
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");
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() {
DEBUG_FUNCTION_LINE("Stop wiiload thread");
DEBUG_FUNCTION_LINE("Stop wiiload thread!");
if (thread != nullptr) {
delete thread;
thread = nullptr;
}
DEBUG_FUNCTION_LINE_VERBOSE("Done!");
deinitLogging();
}

View File

@ -100,20 +100,12 @@ public:
//! Shutdown thread
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
if (!skipJoin && pThread && !(iAttributes & eAttributeDetach)) {
if (!OSIsThreadTerminated(pThread)) {
if (pThread && !(iAttributes & eAttributeDetach)) {
if (isThreadSuspended()) {
resumeThread();
}
OSJoinThread(pThread, nullptr);
} else {
DEBUG_FUNCTION_LINE_WARN("Thread \"%s\" has already been terminated!!!", pThreadName.c_str());
}
}
}
//! free the thread stack buffer
@ -137,7 +129,6 @@ public:
eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10
};
bool skipJoin = false;
private:
static int threadCallback(int argc, const char **argv) {