free rtos mutex improvements

This commit is contained in:
Robin Müller 2020-06-04 20:12:37 +02:00
parent 896e7f15dc
commit 56340bb8b6
3 changed files with 22 additions and 9 deletions

View File

@ -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.

View File

@ -2,8 +2,8 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h>
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);
}

View File

@ -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;