using nullptr now
added new distinction between blocking (MAX_TIMEOUT) and polling (NO_TIMEOUT)
This commit is contained in:
parent
6a3dc94108
commit
f14bacba32
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user