mirror of
https://github.com/wiiu-env/wiiload_plugin.git
synced 2024-11-22 02:29:15 +01:00
Fix potential softlock that could happen if the thread was canceled but is not (marked as) terminated
This commit is contained in:
parent
352946fbf2
commit
7f963d1900
21
src/main.cpp
21
src/main.cpp
@ -24,25 +24,26 @@ INITIALIZE_PLUGIN() {
|
||||
}
|
||||
}
|
||||
|
||||
void stopThread() {
|
||||
if (thread != nullptr) {
|
||||
delete thread;
|
||||
thread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Entry point */
|
||||
ON_APPLICATION_START() {
|
||||
initLogging();
|
||||
stopThread();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
ON_APPLICATION_REQUESTS_EXIT() {
|
||||
DEBUG_FUNCTION_LINE("Stop wiiload thread");
|
||||
stopThread();
|
||||
if (thread != nullptr) {
|
||||
delete thread;
|
||||
thread = nullptr;
|
||||
}
|
||||
|
||||
deinitLogging();
|
||||
}
|
@ -100,17 +100,22 @@ public:
|
||||
|
||||
//! Shutdown thread
|
||||
void shutdownThread() {
|
||||
//! wait for thread to finish
|
||||
if (pThread && !(iAttributes & eAttributeDetach)) {
|
||||
if (!OSIsThreadTerminated(pThread)) {
|
||||
if (isThreadSuspended()) {
|
||||
resumeThread();
|
||||
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 (isThreadSuspended()) {
|
||||
resumeThread();
|
||||
}
|
||||
OSJoinThread(pThread, nullptr);
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE_WARN("Thread \"%s\" has already been terminated!!!", pThreadName.c_str());
|
||||
}
|
||||
OSJoinThread(pThread, nullptr);
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE_WARN("Thread \"%s\" has already been terminated!!!", pThreadName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//! free the thread stack buffer
|
||||
if (pThreadStack) {
|
||||
free(pThreadStack);
|
||||
@ -132,6 +137,7 @@ public:
|
||||
eAttributeDetach = 0x08,
|
||||
eAttributePinnedAff = 0x10
|
||||
};
|
||||
bool skipJoin = false;
|
||||
|
||||
private:
|
||||
static int threadCallback(int argc, const char **argv) {
|
||||
|
Loading…
Reference in New Issue
Block a user