addd new timeout value

This commit is contained in:
Robin Müller 2020-05-29 14:16:44 +02:00
parent 2eba865564
commit 896e7f15dc
3 changed files with 13 additions and 9 deletions

View File

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

View File

@ -3,27 +3,31 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h>
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);

View File

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