using nullptr now

added new distinction between blocking (MAX_TIMEOUT) and polling
(NO_TIMEOUT)
This commit is contained in:
Robin Müller 2020-05-29 14:15:45 +02:00
parent 6a3dc94108
commit f14bacba32
3 changed files with 13 additions and 9 deletions

View File

@ -13,7 +13,7 @@
class MutexIF { class MutexIF {
public: public:
static const uint32_t NO_TIMEOUT; //!< Needs to be defined in implementation. 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; static const uint8_t INTERFACE_ID = CLASS_ID::MUTEX_IF;
/** /**
* The system lacked the necessary resources (other than memory) to initialize another mutex. * The system lacked the necessary resources (other than memory) to initialize another mutex.

View File

@ -3,27 +3,31 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
const uint32_t MutexIF::NO_TIMEOUT = 0; const uint32_t MutexIF::NO_TIMEOUT = 0;
const uint32_t MutexIF::MAX_TIMEOUT = portMAX_DELAY;
Mutex::Mutex() { Mutex::Mutex() {
handle = xSemaphoreCreateMutex(); handle = xSemaphoreCreateMutex();
if(handle == NULL) { if(handle == nullptr) {
sif::error << "Mutex creation failure" << std::endl; sif::error << "Mutex: Creation failure" << std::endl;
} }
} }
Mutex::~Mutex() { Mutex::~Mutex() {
if (handle != 0) { if (handle != nullptr) {
vSemaphoreDelete(handle); vSemaphoreDelete(handle);
} }
} }
ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) {
if (handle == 0) { if (handle == nullptr) {
return MutexIF::MUTEX_NOT_FOUND; return MutexIF::MUTEX_NOT_FOUND;
} }
TickType_t timeout = portMAX_DELAY; TickType_t timeout = MutexIF::NO_TIMEOUT;
if (timeoutMs != NO_TIMEOUT) { if(timeoutMs == MutexIF::MAX_TIMEOUT) {
timeout = MutexIF::MAX_TIMEOUT;
}
else if(timeoutMs > MutexIF::NO_TIMEOUT){
timeout = pdMS_TO_TICKS(timeoutMs); timeout = pdMS_TO_TICKS(timeoutMs);
} }
@ -36,7 +40,7 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) {
} }
ReturnValue_t Mutex::unlockMutex() { ReturnValue_t Mutex::unlockMutex() {
if (handle == 0) { if (handle == nullptr) {
return MutexIF::MUTEX_NOT_FOUND; return MutexIF::MUTEX_NOT_FOUND;
} }
BaseType_t returncode = xSemaphoreGive(handle); BaseType_t returncode = xSemaphoreGive(handle);

View File

@ -18,7 +18,7 @@ class Mutex : public MutexIF {
public: public:
Mutex(); Mutex();
~Mutex(); ~Mutex();
ReturnValue_t lockMutex(uint32_t timeoutMs) override; ReturnValue_t lockMutex(uint32_t timeoutMs = MutexIF::MAX_TIMEOUT) override;
ReturnValue_t unlockMutex() override; ReturnValue_t unlockMutex() override;
private: private:
SemaphoreHandle_t handle; SemaphoreHandle_t handle;