added retvals for mutex
This commit is contained in:
parent
cb14ec15b5
commit
8f563b7b21
@ -1,4 +1,4 @@
|
||||
#include "Mutex.h"
|
||||
#include <framework/osal/FreeRTOS/Mutex.h>
|
||||
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 <framework/ipc/MutexIF.h>
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user