From 7b571bc007202e1fd1a2691c5fd7d6befe8d45d5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 2 Mar 2023 15:38:20 +0100 Subject: [PATCH] refactore more lock handling --- fsfw | 2 +- linux/devices/Max31865RtdPolling.cpp | 14 +++++++------- linux/devices/Max31865RtdPolling.h | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/fsfw b/fsfw index f8409754..245886c5 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit f84097543e59a3564eae4ac19b7118102728c8a9 +Subproject commit 245886c55500b9e70ba71eab68c46d44af9f6836 diff --git a/linux/devices/Max31865RtdPolling.cpp b/linux/devices/Max31865RtdPolling.cpp index e59c2ef2..3071975d 100644 --- a/linux/devices/Max31865RtdPolling.cpp +++ b/linux/devices/Max31865RtdPolling.cpp @@ -19,7 +19,7 @@ static constexpr uint8_t BASE_CFG = Max31865RtdPolling::Max31865RtdPolling(object_id_t objectId, SpiComIF* lowLevelComIF, GpioIF* gpioIF) : SystemObject(objectId), rtds(EiveMax31855::NUM_RTDS), comIF(lowLevelComIF), gpioIF(gpioIF) { - readerMutex = MutexFactory::instance()->createMutex(); + readerLock = MutexFactory::instance()->createMutex(); } ReturnValue_t Max31865RtdPolling::performOperation(uint8_t operationCode) { @@ -63,7 +63,7 @@ bool Max31865RtdPolling::periodicInitHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicInitHandling: Mutex lock failed" << std::endl; return false; @@ -119,7 +119,7 @@ ReturnValue_t Max31865RtdPolling::periodicReadReqHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicReadReqHandling: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -144,7 +144,7 @@ ReturnValue_t Max31865RtdPolling::periodicReadHandling() { if (rtd == nullptr) { continue; } - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::periodicReadHandling: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -200,7 +200,7 @@ ReturnValue_t Max31865RtdPolling::initializeInterface(CookieIF* cookie) { throw std::invalid_argument("Invalid RTD index"); } rtds[rtdCookie->idx] = rtdCookie; - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (dbLen == 0) { dbLen = rtdCookie->db.getSerializedSize(); } @@ -216,7 +216,7 @@ ReturnValue_t Max31865RtdPolling::sendMessage(CookieIF* cookie, const uint8_t* s if (sendLen < 1) { return returnvalue::OK; } - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { sif::warning << "Max31865RtdReader::sendMessage: Mutex lock failed" << std::endl; return returnvalue::FAILED; @@ -312,7 +312,7 @@ ReturnValue_t Max31865RtdPolling::requestReceiveMessage(CookieIF* cookie, size_t ReturnValue_t Max31865RtdPolling::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) { - MutexGuard mg(readerMutex); + MutexGuard mg(readerLock); if (mg.getLockResult() != returnvalue::OK) { // TODO: Emit warning return returnvalue::FAILED; diff --git a/linux/devices/Max31865RtdPolling.h b/linux/devices/Max31865RtdPolling.h index a34c8e53..da27de68 100644 --- a/linux/devices/Max31865RtdPolling.h +++ b/linux/devices/Max31865RtdPolling.h @@ -48,7 +48,10 @@ class Max31865RtdPolling : public SystemObject, std::vector rtds; std::array cmdBuf = {}; size_t dbLen = 0; - MutexIF* readerMutex; + MutexIF* readerLock; + static constexpr MutexIF::TimeoutType LOCK_TYPE = MutexIF::TimeoutType::WAITING; + static constexpr uint32_t LOCK_TIMEOUT = 20; + static constexpr char LOCK_CTX[] = "Max31865RtdPolling"; SpiComIF* comIF; GpioIF* gpioIF;