mirror of
https://github.com/wiiu-env/wiiload_plugin.git
synced 2024-11-22 02:29:15 +01:00
Fix joining the thread
This commit is contained in:
parent
ca47e10a0c
commit
a8a3287ebf
16
src/main.cpp
16
src/main.cpp
@ -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();
|
||||
}
|
@ -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 (isThreadSuspended()) {
|
||||
resumeThread();
|
||||
}
|
||||
OSJoinThread(pThread, nullptr);
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE_WARN("Thread \"%s\" has already been terminated!!!", pThreadName.c_str());
|
||||
}
|
||||
//! wait for thread to finish
|
||||
if (pThread && !(iAttributes & eAttributeDetach)) {
|
||||
if (isThreadSuspended()) {
|
||||
resumeThread();
|
||||
}
|
||||
OSJoinThread(pThread, nullptr);
|
||||
}
|
||||
|
||||
//! 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user