mirror of
https://github.com/wiiu-env/wiiload_plugin.git
synced 2024-11-22 10:39:16 +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 */
|
/* Entry point */
|
||||||
ON_APPLICATION_START() {
|
ON_APPLICATION_START() {
|
||||||
initLogging();
|
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");
|
DEBUG_FUNCTION_LINE("Start wiiload thread");
|
||||||
thread = new TcpReceiver(4299);
|
thread = new TcpReceiver(4299);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ON_APPLICATION_REQUESTS_EXIT() {
|
ON_APPLICATION_REQUESTS_EXIT() {
|
||||||
DEBUG_FUNCTION_LINE("Stop wiiload thread");
|
DEBUG_FUNCTION_LINE("Stop wiiload thread");
|
||||||
stopThread();
|
if (thread != nullptr) {
|
||||||
|
delete thread;
|
||||||
|
thread = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
deinitLogging();
|
deinitLogging();
|
||||||
}
|
}
|
@ -100,8 +100,11 @@ 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 (pThread && !(iAttributes & eAttributeDetach)) {
|
if (!skipJoin && pThread && !(iAttributes & eAttributeDetach)) {
|
||||||
if (!OSIsThreadTerminated(pThread)) {
|
if (!OSIsThreadTerminated(pThread)) {
|
||||||
if (isThreadSuspended()) {
|
if (isThreadSuspended()) {
|
||||||
resumeThread();
|
resumeThread();
|
||||||
@ -111,6 +114,8 @@ public:
|
|||||||
DEBUG_FUNCTION_LINE_WARN("Thread \"%s\" has already been terminated!!!", pThreadName.c_str());
|
DEBUG_FUNCTION_LINE_WARN("Thread \"%s\" has already been terminated!!!", pThreadName.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//! free the thread stack buffer
|
//! free the thread stack buffer
|
||||||
if (pThreadStack) {
|
if (pThreadStack) {
|
||||||
free(pThreadStack);
|
free(pThreadStack);
|
||||||
@ -132,6 +137,7 @@ 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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user