From 0a7b0b245aedd1c53279296dfe67040591119195 Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 5 Oct 2022 18:45:17 +0200 Subject: [PATCH] Only join the thread if it has not been terminated yet --- src/utils/CThread.h | 11 +++++++---- src/utils/logger.h | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/utils/CThread.h b/src/utils/CThread.h index af3b100..4ddc75b 100644 --- a/src/utils/CThread.h +++ b/src/utils/CThread.h @@ -102,11 +102,14 @@ public: void shutdownThread() { //! wait for thread to finish if (pThread && !(iAttributes & eAttributeDetach)) { - if (isThreadSuspended()) { - resumeThread(); + 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); } //! free the thread stack buffer if (pThreadStack) { diff --git a/src/utils/logger.h b/src/utils/logger.h index 54a7642..ecb1dfe 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -38,6 +38,7 @@ extern "C" { #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) LOG(WHBLogWritef, FMT, ##ARGS) #define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS) +#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##WARN ## ", "", FMT, ##ARGS) #define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS); @@ -52,6 +53,7 @@ extern "C" { #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS) +#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##WARN ## ", "\n", FMT, ##ARGS) #define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS);