diff --git a/mutex.cpp b/mutex.cpp index 85ada58..225c1a4 100644 --- a/mutex.cpp +++ b/mutex.cpp @@ -6,7 +6,7 @@ using namespace iflytop; /******************************************************************************* * zmutex * *******************************************************************************/ -zmutex::zmutex() {} +zmutex::zmutex(const char* name) { this->name = name; } zmutex::~zmutex() { vSemaphoreDelete(recursiveMutex); } void zmutex::init() { recursiveMutex = xSemaphoreCreateRecursiveMutex(); @@ -15,7 +15,9 @@ void zmutex::init() { bool zmutex::isInit() { return recursiveMutex != NULL; } void zmutex::lock() { // ZASSERT(recursiveMutex != NULL); + if (recursiveMutex == NULL) { + ZLOGE(TAG, "%s recursiveMutex NULL, init it", name); ZASSERT(recursiveMutex != NULL); } xSemaphoreTakeRecursive(recursiveMutex, portMAX_DELAY); diff --git a/mutex.hpp b/mutex.hpp index 63d223f..2292f5f 100644 --- a/mutex.hpp +++ b/mutex.hpp @@ -5,9 +5,10 @@ namespace iflytop { class zmutex { public: SemaphoreHandle_t recursiveMutex; + const char* name = nullptr; public: - zmutex(); + zmutex(const char* name); ~zmutex(); void init(); diff --git a/zadc.hpp b/zadc.hpp index a666d55..ff56a6a 100644 --- a/zadc.hpp +++ b/zadc.hpp @@ -14,7 +14,7 @@ class ZADC { int32_t m_samplingTime = ADC_SAMPLETIME_480CYCLES; bool inited = false; - zmutex m_mutex; + zmutex m_mutex = {"ZADC"}; int32_t m_cacheVal = 0; const char* m_name = "not set"; diff --git a/zspi.hpp b/zspi.hpp index f29c219..e6b8d14 100644 --- a/zspi.hpp +++ b/zspi.hpp @@ -9,7 +9,7 @@ namespace iflytop { class ZSPI { private: SPI_HandleTypeDef *m_hspi = NULL; - zmutex m_mutex; + zmutex m_mutex= {"ZSPI"}; public: ZSPI(){};