From 8f563b7b21af065208e34b1705533bfc700cd9e5 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 14:02:14 +0200 Subject: [PATCH 01/16] added retvals for mutex --- osal/FreeRTOS/Mutex.cpp | 18 ++++++++---------- osal/FreeRTOS/Mutex.h | 25 +++++++++++++++---------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/osal/FreeRTOS/Mutex.cpp b/osal/FreeRTOS/Mutex.cpp index 7c5110915..e304d60e9 100644 --- a/osal/FreeRTOS/Mutex.cpp +++ b/osal/FreeRTOS/Mutex.cpp @@ -1,4 +1,4 @@ -#include "Mutex.h" +#include #include @@ -6,7 +6,9 @@ const uint32_t MutexIF::NO_TIMEOUT = 0; Mutex::Mutex() { handle = xSemaphoreCreateMutex(); - //TODO print error + if(handle == NULL) { + sif::error << "Mutex creation failure" << std::endl; + } } Mutex::~Mutex() { @@ -18,8 +20,7 @@ Mutex::~Mutex() { ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { if (handle == 0) { - //TODO Does not exist - return HasReturnvaluesIF::RETURN_FAILED; + return MutexIF::MUTEX_NOT_FOUND; } TickType_t timeout = portMAX_DELAY; if (timeoutMs != NO_TIMEOUT) { @@ -30,21 +31,18 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { if (returncode == pdPASS) { return HasReturnvaluesIF::RETURN_OK; } else { - //TODO could not be acquired/timeout - return HasReturnvaluesIF::RETURN_FAILED; + return MutexIF::MUTEX_TIMEOUT; } } ReturnValue_t Mutex::unlockMutex() { if (handle == 0) { - //TODO Does not exist - return HasReturnvaluesIF::RETURN_FAILED; + return MutexIF::MUTEX_NOT_FOUND; } BaseType_t returncode = xSemaphoreGive(handle); if (returncode == pdPASS) { return HasReturnvaluesIF::RETURN_OK; } else { - //TODO is not owner - return HasReturnvaluesIF::RETURN_FAILED; + return MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX; } } diff --git a/osal/FreeRTOS/Mutex.h b/osal/FreeRTOS/Mutex.h index 91f295853..e04cd20d2 100644 --- a/osal/FreeRTOS/Mutex.h +++ b/osal/FreeRTOS/Mutex.h @@ -1,22 +1,27 @@ -#ifndef OS_RTEMS_MUTEX_H_ -#define OS_RTEMS_MUTEX_H_ +#ifndef FRAMEWORK_FREERTOS_MUTEX_H_ +#define FRAMEWORK_FREERTOS_MUTEX_H_ #include +#include +#include -#include -#include "semphr.h" - - - +/** + * @brief OS component to implement MUTual EXclusion + * + * @details + * Mutexes are binary semaphores which include a priority inheritance mechanism. + * Documentation: https://www.freertos.org/Real-time-embedded-RTOS-mutexes.html + * @ingroup osal + */ class Mutex : public MutexIF { public: Mutex(); ~Mutex(); - ReturnValue_t lockMutex(uint32_t timeoutMs); - ReturnValue_t unlockMutex(); + ReturnValue_t lockMutex(uint32_t timeoutMs) override; + ReturnValue_t unlockMutex() override; private: SemaphoreHandle_t handle; }; -#endif /* OS_RTEMS_MUTEX_H_ */ +#endif /* FRAMEWORK_FREERTOS_MUTEX_H_ */ -- 2.34.1 From 2eba8655641e0ef51d085f4da52b3a5ecee4b478 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 14:03:39 +0200 Subject: [PATCH 02/16] some minor form corrections --- ipc/MutexHelper.h | 4 ++-- ipc/MutexIF.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ipc/MutexHelper.h b/ipc/MutexHelper.h index f76ccec47..671cd5a6a 100644 --- a/ipc/MutexHelper.h +++ b/ipc/MutexHelper.h @@ -10,11 +10,11 @@ public: internalMutex(mutex) { ReturnValue_t status = mutex->lockMutex(timeoutMs); if(status != HasReturnvaluesIF::RETURN_OK){ - sif::error << "MutexHelper: Lock of Mutex failed " << status << std::endl; + sif::error << "MutexHelper: Lock of Mutex failed " << + status << std::endl; } } - ~MutexHelper() { internalMutex->unlockMutex(); } diff --git a/ipc/MutexIF.h b/ipc/MutexIF.h index 35786d6a3..a4aff1cd8 100644 --- a/ipc/MutexIF.h +++ b/ipc/MutexIF.h @@ -3,6 +3,13 @@ #include +/** + * @brief Common interface for OS Mutex objects which provide MUTual EXclusion. + * + * @details https://en.wikipedia.org/wiki/Lock_(computer_science) + * @ingroup osal + * @ingroup interface + */ class MutexIF { public: static const uint32_t NO_TIMEOUT; //!< Needs to be defined in implementation. -- 2.34.1 From 896e7f15dc9e4e4ababcf1283e5c6be460780d8a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 14:16:44 +0200 Subject: [PATCH 03/16] addd new timeout value --- ipc/MutexIF.h | 2 +- osal/FreeRTOS/Mutex.cpp | 18 +++++++++++------- osal/FreeRTOS/Mutex.h | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ipc/MutexIF.h b/ipc/MutexIF.h index a4aff1cd8..dcb1cf333 100644 --- a/ipc/MutexIF.h +++ b/ipc/MutexIF.h @@ -13,7 +13,7 @@ class MutexIF { public: static const uint32_t NO_TIMEOUT; //!< Needs to be defined in implementation. - + static const uint32_t MAX_TIMEOUT; static const uint8_t INTERFACE_ID = CLASS_ID::MUTEX_IF; /** * The system lacked the necessary resources (other than memory) to initialize another mutex. diff --git a/osal/FreeRTOS/Mutex.cpp b/osal/FreeRTOS/Mutex.cpp index e304d60e9..cc2f865ff 100644 --- a/osal/FreeRTOS/Mutex.cpp +++ b/osal/FreeRTOS/Mutex.cpp @@ -3,27 +3,31 @@ #include const uint32_t MutexIF::NO_TIMEOUT = 0; +const uint32_t MutexIF::MAX_TIMEOUT = portMAX_DELAY; Mutex::Mutex() { handle = xSemaphoreCreateMutex(); - if(handle == NULL) { - sif::error << "Mutex creation failure" << std::endl; + if(handle == nullptr) { + sif::error << "Mutex: Creation failure" << std::endl; } } Mutex::~Mutex() { - if (handle != 0) { + if (handle != nullptr) { vSemaphoreDelete(handle); } } ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { - if (handle == 0) { + if (handle == nullptr) { return MutexIF::MUTEX_NOT_FOUND; } - TickType_t timeout = portMAX_DELAY; - if (timeoutMs != NO_TIMEOUT) { + TickType_t timeout = MutexIF::NO_TIMEOUT; + if(timeoutMs == MutexIF::MAX_TIMEOUT) { + timeout = MutexIF::MAX_TIMEOUT; + } + else if(timeoutMs > MutexIF::NO_TIMEOUT){ timeout = pdMS_TO_TICKS(timeoutMs); } @@ -36,7 +40,7 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { } ReturnValue_t Mutex::unlockMutex() { - if (handle == 0) { + if (handle == nullptr) { return MutexIF::MUTEX_NOT_FOUND; } BaseType_t returncode = xSemaphoreGive(handle); diff --git a/osal/FreeRTOS/Mutex.h b/osal/FreeRTOS/Mutex.h index e04cd20d2..90e824678 100644 --- a/osal/FreeRTOS/Mutex.h +++ b/osal/FreeRTOS/Mutex.h @@ -18,7 +18,7 @@ class Mutex : public MutexIF { public: Mutex(); ~Mutex(); - ReturnValue_t lockMutex(uint32_t timeoutMs) override; + ReturnValue_t lockMutex(uint32_t timeoutMs = MutexIF::MAX_TIMEOUT) override; ReturnValue_t unlockMutex() override; private: SemaphoreHandle_t handle; -- 2.34.1 From 56340bb8b69b6a02e733960693f497b29aa75a17 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 4 Jun 2020 20:12:37 +0200 Subject: [PATCH 04/16] free rtos mutex improvements --- ipc/MutexIF.h | 17 +++++++++++++++-- osal/FreeRTOS/Mutex.cpp | 12 ++++++------ osal/FreeRTOS/Mutex.h | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/ipc/MutexIF.h b/ipc/MutexIF.h index dcb1cf333..29e59e588 100644 --- a/ipc/MutexIF.h +++ b/ipc/MutexIF.h @@ -12,8 +12,21 @@ */ class MutexIF { public: - static const uint32_t NO_TIMEOUT; //!< Needs to be defined in implementation. - static const uint32_t MAX_TIMEOUT; + /** + * @brief Timeout value used for polling lock attempt. + * @details + * If the lock is not successfull, MUTEX_TIMEOUT will be returned + * immediately. Value needs to be defined in implementation. + */ + static const uint32_t POLLING; + /** + * @brief Timeout value used for permanent blocking lock attempt. + * @details + * The task will be blocked (indefinitely) until the mutex is unlocked. + * Value needs to be defined in implementation. + */ + static const uint32_t BLOCKING; + static const uint8_t INTERFACE_ID = CLASS_ID::MUTEX_IF; /** * The system lacked the necessary resources (other than memory) to initialize another mutex. diff --git a/osal/FreeRTOS/Mutex.cpp b/osal/FreeRTOS/Mutex.cpp index cc2f865ff..6d90c3f61 100644 --- a/osal/FreeRTOS/Mutex.cpp +++ b/osal/FreeRTOS/Mutex.cpp @@ -2,8 +2,8 @@ #include -const uint32_t MutexIF::NO_TIMEOUT = 0; -const uint32_t MutexIF::MAX_TIMEOUT = portMAX_DELAY; +const uint32_t MutexIF::POLLING = 0; +const uint32_t MutexIF::BLOCKING = portMAX_DELAY; Mutex::Mutex() { handle = xSemaphoreCreateMutex(); @@ -23,11 +23,11 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { if (handle == nullptr) { return MutexIF::MUTEX_NOT_FOUND; } - TickType_t timeout = MutexIF::NO_TIMEOUT; - if(timeoutMs == MutexIF::MAX_TIMEOUT) { - timeout = MutexIF::MAX_TIMEOUT; + TickType_t timeout = MutexIF::POLLING; + if(timeoutMs == MutexIF::BLOCKING) { + timeout = MutexIF::BLOCKING; } - else if(timeoutMs > MutexIF::NO_TIMEOUT){ + else if(timeoutMs > MutexIF::POLLING){ timeout = pdMS_TO_TICKS(timeoutMs); } diff --git a/osal/FreeRTOS/Mutex.h b/osal/FreeRTOS/Mutex.h index 90e824678..d6e0aab9e 100644 --- a/osal/FreeRTOS/Mutex.h +++ b/osal/FreeRTOS/Mutex.h @@ -18,7 +18,7 @@ class Mutex : public MutexIF { public: Mutex(); ~Mutex(); - ReturnValue_t lockMutex(uint32_t timeoutMs = MutexIF::MAX_TIMEOUT) override; + ReturnValue_t lockMutex(uint32_t timeoutMs = MutexIF::BLOCKING) override; ReturnValue_t unlockMutex() override; private: SemaphoreHandle_t handle; -- 2.34.1 From 869700e6f52eca5efe8b1c5a20e5923730b51d8e Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 4 Jun 2020 20:20:38 +0200 Subject: [PATCH 05/16] added mutex IF timeout name --- datapool/DataPool.cpp | 2 +- events/EventManager.cpp | 2 +- health/HealthTable.cpp | 12 ++++++------ internalError/InternalErrorReporter.cpp | 18 +++++++++--------- osal/FreeRTOS/Clock.cpp | 4 ++-- osal/linux/Mutex.cpp | 8 ++++++-- storagemanager/PoolManager.h | 6 +++--- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/datapool/DataPool.cpp b/datapool/DataPool.cpp index 70a2a3fb5..2c226c54f 100644 --- a/datapool/DataPool.cpp +++ b/datapool/DataPool.cpp @@ -61,7 +61,7 @@ ReturnValue_t DataPool::freeDataPoolLock() { } ReturnValue_t DataPool::lockDataPool() { - ReturnValue_t status = mutex->lockMutex(MutexIF::NO_TIMEOUT); + ReturnValue_t status = mutex->lockMutex(MutexIF::BLOCKING); if ( status != RETURN_OK ) { sif::error << "DataPool::DataPool: lock of mutex failed with error code: " << status << std::endl; } diff --git a/events/EventManager.cpp b/events/EventManager.cpp index 0f1511e4b..c7d9cf8fb 100644 --- a/events/EventManager.cpp +++ b/events/EventManager.cpp @@ -147,7 +147,7 @@ void EventManager::printEvent(EventMessage* message) { #endif void EventManager::lockMutex() { - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); } void EventManager::unlockMutex() { diff --git a/health/HealthTable.cpp b/health/HealthTable.cpp index a575b2828..d0e5485af 100644 --- a/health/HealthTable.cpp +++ b/health/HealthTable.cpp @@ -26,7 +26,7 @@ ReturnValue_t HealthTable::registerObject(object_id_t object, void HealthTable::setHealth(object_id_t object, HasHealthIF::HealthState newState) { - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); HealthMap::iterator iter = healthMap.find(object); if (iter != healthMap.end()) { iter->second = newState; @@ -36,7 +36,7 @@ void HealthTable::setHealth(object_id_t object, HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) { HasHealthIF::HealthState state = HasHealthIF::HEALTHY; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); HealthMap::iterator iter = healthMap.find(object); if (iter != healthMap.end()) { state = iter->second; @@ -46,7 +46,7 @@ HasHealthIF::HealthState HealthTable::getHealth(object_id_t object) { } uint32_t HealthTable::getPrintSize() { - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); uint32_t size = healthMap.size() * 5 + 2; mutex->unlockMutex(); return size; @@ -54,7 +54,7 @@ uint32_t HealthTable::getPrintSize() { bool HealthTable::hasHealth(object_id_t object) { bool exits = false; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); HealthMap::iterator iter = healthMap.find(object); if (iter != healthMap.end()) { exits = true; @@ -64,7 +64,7 @@ bool HealthTable::hasHealth(object_id_t object) { } void HealthTable::printAll(uint8_t* pointer, uint32_t maxSize) { - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); uint32_t size = 0; uint16_t count = healthMap.size(); ReturnValue_t result = SerializeAdapter::serialize(&count, @@ -85,7 +85,7 @@ void HealthTable::printAll(uint8_t* pointer, uint32_t maxSize) { ReturnValue_t HealthTable::iterate( std::pair *value, bool reset) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); if (reset) { mapIterator = healthMap.begin(); } diff --git a/internalError/InternalErrorReporter.cpp b/internalError/InternalErrorReporter.cpp index 9a8ede002..dbcd26221 100644 --- a/internalError/InternalErrorReporter.cpp +++ b/internalError/InternalErrorReporter.cpp @@ -54,7 +54,7 @@ void InternalErrorReporter::lostTm() { uint32_t InternalErrorReporter::getAndResetQueueHits() { uint32_t value; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); value = queueHits; queueHits = 0; mutex->unlockMutex(); @@ -63,21 +63,21 @@ uint32_t InternalErrorReporter::getAndResetQueueHits() { uint32_t InternalErrorReporter::getQueueHits() { uint32_t value; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); value = queueHits; mutex->unlockMutex(); return value; } void InternalErrorReporter::incrementQueueHits() { - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); queueHits++; mutex->unlockMutex(); } uint32_t InternalErrorReporter::getAndResetTmHits() { uint32_t value; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); value = tmHits; tmHits = 0; mutex->unlockMutex(); @@ -86,14 +86,14 @@ uint32_t InternalErrorReporter::getAndResetTmHits() { uint32_t InternalErrorReporter::getTmHits() { uint32_t value; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); value = tmHits; mutex->unlockMutex(); return value; } void InternalErrorReporter::incrementTmHits() { - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); tmHits++; mutex->unlockMutex(); } @@ -104,7 +104,7 @@ void InternalErrorReporter::storeFull() { uint32_t InternalErrorReporter::getAndResetStoreHits() { uint32_t value; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); value = storeHits; storeHits = 0; mutex->unlockMutex(); @@ -113,14 +113,14 @@ uint32_t InternalErrorReporter::getAndResetStoreHits() { uint32_t InternalErrorReporter::getStoreHits() { uint32_t value; - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); value = storeHits; mutex->unlockMutex(); return value; } void InternalErrorReporter::incrementStoreHits() { - mutex->lockMutex(MutexIF::NO_TIMEOUT); + mutex->lockMutex(MutexIF::BLOCKING); storeHits++; mutex->unlockMutex(); } diff --git a/osal/FreeRTOS/Clock.cpp b/osal/FreeRTOS/Clock.cpp index cffc2125e..589f44d52 100644 --- a/osal/FreeRTOS/Clock.cpp +++ b/osal/FreeRTOS/Clock.cpp @@ -154,7 +154,7 @@ ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) { if (checkOrCreateClockMutex() != HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_FAILED; } - ReturnValue_t result = timeMutex->lockMutex(MutexIF::NO_TIMEOUT); + ReturnValue_t result = timeMutex->lockMutex(MutexIF::BLOCKING); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -169,7 +169,7 @@ ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) { if (timeMutex == NULL) { return HasReturnvaluesIF::RETURN_FAILED; } - ReturnValue_t result = timeMutex->lockMutex(MutexIF::NO_TIMEOUT); + ReturnValue_t result = timeMutex->lockMutex(MutexIF::BLOCKING); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/osal/linux/Mutex.cpp b/osal/linux/Mutex.cpp index 36bb3ce43..62fbccd79 100644 --- a/osal/linux/Mutex.cpp +++ b/osal/linux/Mutex.cpp @@ -2,7 +2,8 @@ #include #include -const uint32_t MutexIF::NO_TIMEOUT = 0; +const uint32_t MutexIF::POLLING = 0; +const uint32_t MutexIF::NO_TIMEOUT = 0xffffffff; uint8_t Mutex::count = 0; @@ -39,7 +40,10 @@ Mutex::~Mutex() { ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { int status = 0; - if (timeoutMs != MutexIF::NO_TIMEOUT) { + if(timeoutMs == MutexIF::POLLING) { + status = pthread_mutex_trylock(&mutex); + } + else if (timeoutMs != MutexIF::BLOCKING) { timespec timeOut; clock_gettime(CLOCK_REALTIME, &timeOut); uint64_t nseconds = timeOut.tv_sec * 1000000000 + timeOut.tv_nsec; diff --git a/storagemanager/PoolManager.h b/storagemanager/PoolManager.h index 68a7addc1..5fd9b5f72 100644 --- a/storagemanager/PoolManager.h +++ b/storagemanager/PoolManager.h @@ -49,7 +49,7 @@ public: template inline ReturnValue_t PoolManager::reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault) { - MutexHelper mutexHelper(mutex,MutexIF::NO_TIMEOUT); + MutexHelper mutexHelper(mutex,MutexIF::BLOCKING); ReturnValue_t status = LocalPool::reserveSpace(size,address,ignoreFault); return status; } @@ -70,7 +70,7 @@ template inline ReturnValue_t PoolManager::deleteData( store_address_t packet_id) { // debug << "PoolManager( " << translateObject(getObjectId()) << " )::deleteData from store " << packet_id.pool_index << ". id is " << packet_id.packet_index << std::endl; - MutexHelper mutexHelper(mutex,MutexIF::NO_TIMEOUT); + MutexHelper mutexHelper(mutex,MutexIF::BLOCKING); ReturnValue_t status = LocalPool::deleteData(packet_id); return status; } @@ -78,7 +78,7 @@ inline ReturnValue_t PoolManager::deleteData( template inline ReturnValue_t PoolManager::deleteData(uint8_t* buffer, uint32_t size, store_address_t* storeId) { - MutexHelper mutexHelper(mutex,MutexIF::NO_TIMEOUT); + MutexHelper mutexHelper(mutex,MutexIF::BLOCKING); ReturnValue_t status = LocalPool::deleteData(buffer, size, storeId); return status; } -- 2.34.1 From fbf804cdca0c13e0d272af81f09493550f1ee13d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 4 Jun 2020 20:25:15 +0200 Subject: [PATCH 06/16] linux changes for mutex --- osal/linux/Clock.cpp | 4 ++-- osal/linux/Mutex.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/osal/linux/Clock.cpp b/osal/linux/Clock.cpp index e24a4fe4b..53a597d67 100644 --- a/osal/linux/Clock.cpp +++ b/osal/linux/Clock.cpp @@ -170,7 +170,7 @@ ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) { if(checkOrCreateClockMutex()!=HasReturnvaluesIF::RETURN_OK){ return HasReturnvaluesIF::RETURN_FAILED; } - ReturnValue_t result = timeMutex->lockMutex(MutexIF::NO_TIMEOUT); + ReturnValue_t result = timeMutex->lockMutex(MutexIF::BLOCKING); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } @@ -185,7 +185,7 @@ ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) { if(timeMutex==NULL){ return HasReturnvaluesIF::RETURN_FAILED; } - ReturnValue_t result = timeMutex->lockMutex(MutexIF::NO_TIMEOUT); + ReturnValue_t result = timeMutex->lockMutex(MutexIF::BLOCKING); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } diff --git a/osal/linux/Mutex.cpp b/osal/linux/Mutex.cpp index 62fbccd79..169ac3543 100644 --- a/osal/linux/Mutex.cpp +++ b/osal/linux/Mutex.cpp @@ -3,7 +3,7 @@ #include const uint32_t MutexIF::POLLING = 0; -const uint32_t MutexIF::NO_TIMEOUT = 0xffffffff; +const uint32_t MutexIF::BLOCKING = 0xffffffff; uint8_t Mutex::count = 0; @@ -43,7 +43,10 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { if(timeoutMs == MutexIF::POLLING) { status = pthread_mutex_trylock(&mutex); } - else if (timeoutMs != MutexIF::BLOCKING) { + else if (timeoutMs == MutexIF::BLOCKING) { + status = pthread_mutex_lock(&mutex); + } + else { timespec timeOut; clock_gettime(CLOCK_REALTIME, &timeOut); uint64_t nseconds = timeOut.tv_sec * 1000000000 + timeOut.tv_nsec; @@ -51,9 +54,8 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { timeOut.tv_sec = nseconds / 1000000000; timeOut.tv_nsec = nseconds - timeOut.tv_sec * 1000000000; status = pthread_mutex_timedlock(&mutex, &timeOut); - } else { - status = pthread_mutex_lock(&mutex); } + switch (status) { case EINVAL: //The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority ceiling. -- 2.34.1 From 03e9362825e474b26fe79fc9405104496bdac221 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 5 Jun 2020 20:42:39 +0200 Subject: [PATCH 07/16] mutex helper special output for timeout fail --- ipc/MutexHelper.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ipc/MutexHelper.h b/ipc/MutexHelper.h index 671cd5a6a..20760b32f 100644 --- a/ipc/MutexHelper.h +++ b/ipc/MutexHelper.h @@ -9,8 +9,12 @@ public: MutexHelper(MutexIF* mutex, uint32_t timeoutMs) : internalMutex(mutex) { ReturnValue_t status = mutex->lockMutex(timeoutMs); - if(status != HasReturnvaluesIF::RETURN_OK){ - sif::error << "MutexHelper: Lock of Mutex failed " << + if(status == MutexIF::MUTEX_TIMEOUT) { + sif::error << "MutexHelper: Lock of mutex failed with timeout of" + << timeoutMs << " milliseconds!" << std::endl; + } + else if(status != HasReturnvaluesIF::RETURN_OK){ + sif::error << "MutexHelper: Lock of Mutex failed with code " << status << std::endl; } } -- 2.34.1 From 20abb810f2ba16ab9781e07bd0c06c7fde4e9efb Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 8 Jun 2020 14:11:38 +0200 Subject: [PATCH 08/16] i hope this is correct --- osal/rtems/Mutex.cpp | 3 ++- osal/rtems/Mutex.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/osal/rtems/Mutex.cpp b/osal/rtems/Mutex.cpp index d094e1dce..0c1675b1c 100644 --- a/osal/rtems/Mutex.cpp +++ b/osal/rtems/Mutex.cpp @@ -1,7 +1,8 @@ #include "Mutex.h" #include -const uint32_t MutexIF::NO_TIMEOUT = RTEMS_NO_TIMEOUT; +const uint32_t MutexIF::BLOCKING = RTEMS_NO_TIMEOUT; +const uint32_t MutexIF::POLLING = RTEMS_NO_WAIT; uint8_t Mutex::count = 0; Mutex::Mutex() : diff --git a/osal/rtems/Mutex.h b/osal/rtems/Mutex.h index 19b34e7f2..486055bad 100644 --- a/osal/rtems/Mutex.h +++ b/osal/rtems/Mutex.h @@ -1,5 +1,5 @@ -#ifndef OS_RTEMS_MUTEX_H_ -#define OS_RTEMS_MUTEX_H_ +#ifndef FRAMEWORK_OSAL_RTEMS_MUTEX_H_ +#define FRAMEWORK_OSAL_RTEMS_MUTEX_H_ #include #include "RtemsBasic.h" -- 2.34.1 From b5567e8aae90e5f87e6d94b45b9c51889387bb41 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 9 Jun 2020 13:26:27 +0200 Subject: [PATCH 09/16] rtems mutex update --- osal/rtems/Mutex.cpp | 17 +++++++++++++++-- osal/rtems/Mutex.h | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/osal/rtems/Mutex.cpp b/osal/rtems/Mutex.cpp index 0c1675b1c..5487a5039 100644 --- a/osal/rtems/Mutex.cpp +++ b/osal/rtems/Mutex.cpp @@ -1,7 +1,7 @@ #include "Mutex.h" #include -const uint32_t MutexIF::BLOCKING = RTEMS_NO_TIMEOUT; +const uint32_t MutexIF::BLOCKING = RTEMS_WAIT; const uint32_t MutexIF::POLLING = RTEMS_NO_WAIT; uint8_t Mutex::count = 0; @@ -26,7 +26,20 @@ Mutex::~Mutex() { } ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { - rtems_status_code status = rtems_semaphore_obtain(mutexId, RTEMS_WAIT, timeoutMs); + if(timeoutMs == MutexIF::BLOCKING) { + rtems_status_code status = rtems_semaphore_obtain(mutexId, + RTEMS_WAIT, timeoutMs); + } + else if(timeoutMs == MutexIF::POLLING) { + timeoutMs = RTEMS_NO_TIMEOUT; + rtems_status_code status = rtems_semaphore_obtain(mutexId, + RTEMS_NO_WAIT, timeoutMs); + } + else { + rtems_status_code status = rtems_semaphore_obtain(mutexId, + RTEMS_NO_WAIT, timeoutMs); + } + switch(status){ case RTEMS_SUCCESSFUL: //semaphore obtained successfully diff --git a/osal/rtems/Mutex.h b/osal/rtems/Mutex.h index 486055bad..4aa25e40e 100644 --- a/osal/rtems/Mutex.h +++ b/osal/rtems/Mutex.h @@ -8,7 +8,7 @@ class Mutex : public MutexIF { public: Mutex(); ~Mutex(); - ReturnValue_t lockMutex(uint32_t timeoutMs); + ReturnValue_t lockMutex(uint32_t timeoutMs = MutexIF::BLOCKING); ReturnValue_t unlockMutex(); private: rtems_id mutexId; -- 2.34.1 From 7b3fddfd429a02f6dedaad4e33a7c0a308f540d4 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 7 Aug 2020 22:10:58 +0200 Subject: [PATCH 10/16] implemented mutex if changes --- ipc/MutexHelper.h | 5 +++-- ipc/MutexIF.h | 38 ++++++++++++++++++++------------------ osal/FreeRTOS/Mutex.cpp | 17 ++++++++--------- osal/FreeRTOS/Mutex.h | 4 +++- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/ipc/MutexHelper.h b/ipc/MutexHelper.h index 20760b32f..fc6e38bfe 100644 --- a/ipc/MutexHelper.h +++ b/ipc/MutexHelper.h @@ -8,9 +8,10 @@ class MutexHelper { public: MutexHelper(MutexIF* mutex, uint32_t timeoutMs) : internalMutex(mutex) { - ReturnValue_t status = mutex->lockMutex(timeoutMs); + ReturnValue_t status = mutex->lockMutex(MutexIF::TimeoutType::WAITING, + timeoutMs); if(status == MutexIF::MUTEX_TIMEOUT) { - sif::error << "MutexHelper: Lock of mutex failed with timeout of" + sif::error << "MutexHelper: Lock of mutex failed with timeout of " << timeoutMs << " milliseconds!" << std::endl; } else if(status != HasReturnvaluesIF::RETURN_OK){ diff --git a/ipc/MutexIF.h b/ipc/MutexIF.h index 29e59e588..b0096a343 100644 --- a/ipc/MutexIF.h +++ b/ipc/MutexIF.h @@ -5,27 +5,31 @@ /** * @brief Common interface for OS Mutex objects which provide MUTual EXclusion. - * * @details https://en.wikipedia.org/wiki/Lock_(computer_science) * @ingroup osal * @ingroup interface */ class MutexIF { public: - /** - * @brief Timeout value used for polling lock attempt. - * @details - * If the lock is not successfull, MUTEX_TIMEOUT will be returned - * immediately. Value needs to be defined in implementation. - */ - static const uint32_t POLLING; - /** - * @brief Timeout value used for permanent blocking lock attempt. - * @details - * The task will be blocked (indefinitely) until the mutex is unlocked. - * Value needs to be defined in implementation. - */ - static const uint32_t BLOCKING; + /** + * Different types of timeout for the mutex lock. + */ + enum TimeoutType { + POLLING, //!< If mutex is not available, return immediately + WAITING, //!< Wait a specified time for the mutex to become available + BLOCKING //!< Block indefinitely until the mutex becomes available. + }; + + /** + * Lock the mutex. The timeout value will only be used for + * TimeoutType::WAITING + * @param timeoutType + * @param timeoutMs + * @return + */ + virtual ReturnValue_t lockMutex(TimeoutType timeoutType = + TimeoutType::BLOCKING, uint32_t timeoutMs = 0) = 0; + virtual ReturnValue_t unlockMutex() = 0; static const uint8_t INTERFACE_ID = CLASS_ID::MUTEX_IF; /** @@ -77,9 +81,7 @@ public: */ static const ReturnValue_t MUTEX_DESTROYED_WHILE_WAITING = MAKE_RETURN_CODE(12); - virtual ~MutexIF() {} - virtual ReturnValue_t lockMutex(uint32_t timeoutMs) = 0; - virtual ReturnValue_t unlockMutex() = 0; + virtual ~MutexIF() {} }; diff --git a/osal/FreeRTOS/Mutex.cpp b/osal/FreeRTOS/Mutex.cpp index 6d90c3f61..764b0ae09 100644 --- a/osal/FreeRTOS/Mutex.cpp +++ b/osal/FreeRTOS/Mutex.cpp @@ -2,13 +2,10 @@ #include -const uint32_t MutexIF::POLLING = 0; -const uint32_t MutexIF::BLOCKING = portMAX_DELAY; - Mutex::Mutex() { handle = xSemaphoreCreateMutex(); if(handle == nullptr) { - sif::error << "Mutex: Creation failure" << std::endl; + sif::error << "Mutex::Mutex(FreeRTOS): Creation failure" << std::endl; } } @@ -19,15 +16,17 @@ Mutex::~Mutex() { } -ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { +ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, + uint32_t timeoutMs) { if (handle == nullptr) { return MutexIF::MUTEX_NOT_FOUND; } - TickType_t timeout = MutexIF::POLLING; - if(timeoutMs == MutexIF::BLOCKING) { - timeout = MutexIF::BLOCKING; + // If the timeout type is BLOCKING, this will be the correct value. + uint32_t timeout = portMAX_DELAY; + if(timeoutType == TimeoutType::POLLING) { + timeout = 0; } - else if(timeoutMs > MutexIF::POLLING){ + else if(timeoutType == TimeoutType::WAITING){ timeout = pdMS_TO_TICKS(timeoutMs); } diff --git a/osal/FreeRTOS/Mutex.h b/osal/FreeRTOS/Mutex.h index d6e0aab9e..2a4fae26d 100644 --- a/osal/FreeRTOS/Mutex.h +++ b/osal/FreeRTOS/Mutex.h @@ -18,8 +18,10 @@ class Mutex : public MutexIF { public: Mutex(); ~Mutex(); - ReturnValue_t lockMutex(uint32_t timeoutMs = MutexIF::BLOCKING) override; + ReturnValue_t lockMutex(TimeoutType timeoutType, + uint32_t timeoutMs) override; ReturnValue_t unlockMutex() override; + private: SemaphoreHandle_t handle; }; -- 2.34.1 From caeb2f9dd639cddd9674f2b0c5cc32887a4db041 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 7 Aug 2020 22:16:10 +0200 Subject: [PATCH 11/16] mutex api changes --- ipc/MutexHelper.h | 5 +++-- osal/linux/Mutex.cpp | 41 ++++++++++++++++++++++++----------------- osal/linux/Mutex.h | 10 +++++++--- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/ipc/MutexHelper.h b/ipc/MutexHelper.h index fc6e38bfe..52ce51e3a 100644 --- a/ipc/MutexHelper.h +++ b/ipc/MutexHelper.h @@ -6,9 +6,10 @@ class MutexHelper { public: - MutexHelper(MutexIF* mutex, uint32_t timeoutMs) : + MutexHelper(MutexIF* mutex, MutexIF::TimeoutType timeoutType = + MutexIF::TimeoutType::BLOCKING, uint32_t timeoutMs = 0) : internalMutex(mutex) { - ReturnValue_t status = mutex->lockMutex(MutexIF::TimeoutType::WAITING, + ReturnValue_t status = mutex->lockMutex(timeoutType, timeoutMs); if(status == MutexIF::MUTEX_TIMEOUT) { sif::error << "MutexHelper: Lock of mutex failed with timeout of " diff --git a/osal/linux/Mutex.cpp b/osal/linux/Mutex.cpp index 169ac3543..03789e625 100644 --- a/osal/linux/Mutex.cpp +++ b/osal/linux/Mutex.cpp @@ -2,8 +2,6 @@ #include #include -const uint32_t MutexIF::POLLING = 0; -const uint32_t MutexIF::BLOCKING = 0xffffffff; uint8_t Mutex::count = 0; @@ -26,7 +24,9 @@ Mutex::Mutex() { sif::error << "Mutex: creation with name, id " << mutex.__data.__count << ", " << " failed with " << strerror(status) << std::endl; } - //After a mutex attributes object has been used to initialize one or more mutexes, any function affecting the attributes object (including destruction) shall not affect any previously initialized mutexes. + // After a mutex attributes object has been used to initialize one or more + // mutexes, any function affecting the attributes object + // (including destruction) shall not affect any previously initialized mutexes. status = pthread_mutexattr_destroy(&mutexAttr); if (status != 0) { sif::error << "Mutex: Attribute destroy failed with " << strerror(status) << std::endl; @@ -38,15 +38,13 @@ Mutex::~Mutex() { pthread_mutex_destroy(&mutex); } -ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { +ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) { int status = 0; - if(timeoutMs == MutexIF::POLLING) { - status = pthread_mutex_trylock(&mutex); + + if(timeoutType == TimeoutType::POLLING) { + status = pthread_mutex_trylock(&mutex); } - else if (timeoutMs == MutexIF::BLOCKING) { - status = pthread_mutex_lock(&mutex); - } - else { + else if (timeoutType == TimeoutType::WAITING) { timespec timeOut; clock_gettime(CLOCK_REALTIME, &timeOut); uint64_t nseconds = timeOut.tv_sec * 1000000000 + timeOut.tv_nsec; @@ -55,25 +53,34 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { timeOut.tv_nsec = nseconds - timeOut.tv_sec * 1000000000; status = pthread_mutex_timedlock(&mutex, &timeOut); } + else if(timeoutType == TimeoutType::BLOCKING) { + status = pthread_mutex_lock(&mutex); + } switch (status) { case EINVAL: - //The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority ceiling. + // The mutex was created with the protocol attribute having the value + // PTHREAD_PRIO_PROTECT and the calling thread's priority is higher + // than the mutex's current priority ceiling. return WRONG_ATTRIBUTE_SETTING; - //The process or thread would have blocked, and the abs_timeout parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million. - //The value specified by mutex does not refer to an initialized mutex object. + // The process or thread would have blocked, and the abs_timeout + // parameter specified a nanoseconds field value less than zero or + // greater than or equal to 1000 million. + // The value specified by mutex does not refer to an initialized mutex object. //return MUTEX_NOT_FOUND; case EBUSY: - //The mutex could not be acquired because it was already locked. + // The mutex could not be acquired because it was already locked. return MUTEX_ALREADY_LOCKED; case ETIMEDOUT: - //The mutex could not be locked before the specified timeout expired. + // The mutex could not be locked before the specified timeout expired. return MUTEX_TIMEOUT; case EAGAIN: - //The mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded. + // The mutex could not be acquired because the maximum number of + // recursive locks for mutex has been exceeded. return MUTEX_MAX_LOCKS; case EDEADLK: - //A deadlock condition was detected or the current thread already owns the mutex. + // A deadlock condition was detected or the current thread + // already owns the mutex. return CURR_THREAD_ALREADY_OWNS_MUTEX; case 0: //Success diff --git a/osal/linux/Mutex.h b/osal/linux/Mutex.h index d02d008fe..26420c2eb 100644 --- a/osal/linux/Mutex.h +++ b/osal/linux/Mutex.h @@ -1,14 +1,18 @@ -#ifndef OS_RTEMS_MUTEX_H_ -#define OS_RTEMS_MUTEX_H_ +#ifndef OS_LINUX_MUTEX_H_ +#define OS_LINUX_MUTEX_H_ #include + +extern "C" { #include +} + class Mutex : public MutexIF { public: Mutex(); virtual ~Mutex(); - virtual ReturnValue_t lockMutex(uint32_t timeoutMs); + virtual ReturnValue_t lockMutex(TimeoutType timeoutType, uint32_t timeoutMs); virtual ReturnValue_t unlockMutex(); private: pthread_mutex_t mutex; -- 2.34.1 From 54825dca6b3c63259a4eb1a45878358e5ae1192d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 7 Aug 2020 22:19:13 +0200 Subject: [PATCH 12/16] periodic posix task hotfix --- osal/linux/PeriodicPosixTask.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osal/linux/PeriodicPosixTask.cpp b/osal/linux/PeriodicPosixTask.cpp index c05f1030c..548590aca 100644 --- a/osal/linux/PeriodicPosixTask.cpp +++ b/osal/linux/PeriodicPosixTask.cpp @@ -22,7 +22,7 @@ void* PeriodicPosixTask::taskEntryPoint(void* arg) { } ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object, - bool addTaskIF) { + bool addTaskIF) { ExecutableObjectIF* newObject = objectManager->get( object); if (newObject == nullptr) { @@ -30,9 +30,7 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object, } objectList.push_back(newObject); - if(setTaskIF) { - newObject->setTaskIF(this); - } + newObject->setTaskIF(this); return HasReturnvaluesIF::RETURN_OK; } -- 2.34.1 From a4626aeac0682b07b5fee7ee2c4fa94d5322d1b8 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 25 Aug 2020 12:04:59 +0200 Subject: [PATCH 13/16] made rtems adaption --- osal/rtems/Mutex.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/osal/rtems/Mutex.cpp b/osal/rtems/Mutex.cpp index 685145349..f1c888267 100644 --- a/osal/rtems/Mutex.cpp +++ b/osal/rtems/Mutex.cpp @@ -25,12 +25,13 @@ Mutex::~Mutex() { } } -ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { - if(timeoutMs == MutexIF::BLOCKING) { +ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType = + TimeoutType::BLOCKING, uint32_t timeoutMs) { + if(timeoutMs == MutexIF::TimeoutType::BLOCKING) { rtems_status_code status = rtems_semaphore_obtain(mutexId, RTEMS_WAIT, timeoutMs); } - else if(timeoutMs == MutexIF::POLLING) { + else if(timeoutMs == MutexIF::TimeoutType::POLLING) { timeoutMs = RTEMS_NO_TIMEOUT; rtems_status_code status = rtems_semaphore_obtain(mutexId, RTEMS_NO_WAIT, timeoutMs); -- 2.34.1 From 49a36d6fdc9d635946e6eb307ac771aa1ce01266 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 25 Aug 2020 12:06:39 +0200 Subject: [PATCH 14/16] removed definitions --- osal/rtems/Mutex.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/osal/rtems/Mutex.cpp b/osal/rtems/Mutex.cpp index f1c888267..31acdb3c4 100644 --- a/osal/rtems/Mutex.cpp +++ b/osal/rtems/Mutex.cpp @@ -1,8 +1,6 @@ #include "Mutex.h" #include "../../serviceinterface/ServiceInterfaceStream.h" -const uint32_t MutexIF::BLOCKING = RTEMS_WAIT; -const uint32_t MutexIF::POLLING = RTEMS_NO_WAIT; uint8_t Mutex::count = 0; Mutex::Mutex() : -- 2.34.1 From ab4c65c87ae719143697de99d5a5b26c302d4e68 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 25 Aug 2020 12:08:12 +0200 Subject: [PATCH 15/16] added header file changes --- osal/rtems/Mutex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osal/rtems/Mutex.h b/osal/rtems/Mutex.h index 624b556f8..723682104 100644 --- a/osal/rtems/Mutex.h +++ b/osal/rtems/Mutex.h @@ -8,7 +8,7 @@ class Mutex : public MutexIF { public: Mutex(); ~Mutex(); - ReturnValue_t lockMutex(uint32_t timeoutMs = MutexIF::BLOCKING); + ReturnValue_t lockMutex(TimeoutType timeoutType, uint32_t timeoutMs = 0); ReturnValue_t unlockMutex(); private: rtems_id mutexId; -- 2.34.1 From 74dea921e027f1ab6798a58b1b5e7e7cec6c7b01 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 25 Aug 2020 12:10:28 +0200 Subject: [PATCH 16/16] made fixes --- osal/rtems/Mutex.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osal/rtems/Mutex.cpp b/osal/rtems/Mutex.cpp index 31acdb3c4..9553ac79c 100644 --- a/osal/rtems/Mutex.cpp +++ b/osal/rtems/Mutex.cpp @@ -27,16 +27,16 @@ ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType = TimeoutType::BLOCKING, uint32_t timeoutMs) { if(timeoutMs == MutexIF::TimeoutType::BLOCKING) { rtems_status_code status = rtems_semaphore_obtain(mutexId, - RTEMS_WAIT, timeoutMs); + RTEMS_WAIT, RTEMS_NO_TIMEOUT); } else if(timeoutMs == MutexIF::TimeoutType::POLLING) { timeoutMs = RTEMS_NO_TIMEOUT; rtems_status_code status = rtems_semaphore_obtain(mutexId, - RTEMS_NO_WAIT, timeoutMs); + RTEMS_NO_WAIT, 0); } else { rtems_status_code status = rtems_semaphore_obtain(mutexId, - RTEMS_NO_WAIT, timeoutMs); + RTEMS_WAIT, timeoutMs); } switch(status){ -- 2.34.1