tweaked factory to have configurability
This commit is contained in:
parent
b4065c7764
commit
eabee85ba9
@ -6,3 +6,16 @@ CountingSemaphoreUsingTask::CountingSemaphoreUsingTask(uint8_t count,
|
|||||||
count(count), initCount(initCount) {
|
count(count), initCount(initCount) {
|
||||||
handle = TaskManagement::getCurrentTaskHandle();
|
handle = TaskManagement::getCurrentTaskHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphoreUsingTask::acquire(
|
||||||
|
uint32_t timeoutMs) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphoreUsingTask::release() {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounter() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -13,8 +13,9 @@ class CountingSemaphoreUsingTask: public SemaphoreIF {
|
|||||||
public:
|
public:
|
||||||
CountingSemaphoreUsingTask(uint8_t count, uint8_t initCount);
|
CountingSemaphoreUsingTask(uint8_t count, uint8_t initCount);
|
||||||
|
|
||||||
ReturnValue_t acquire(uint32_t timeoutMs);
|
ReturnValue_t acquire(uint32_t timeoutMs) override;
|
||||||
ReturnValue_t release();
|
ReturnValue_t release() override;
|
||||||
|
uint8_t getSemaphoreCounter() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TaskHandle_t handle;
|
TaskHandle_t handle;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include <framework/osal/FreeRTOS/BinarySemaphore.h>
|
#include <framework/osal/FreeRTOS/BinarySemaphore.h>
|
||||||
|
#include <framework/osal/FreeRTOS/BinSemaphUsingTask.h>
|
||||||
#include <framework/osal/FreeRTOS/CountingSemaphore.h>
|
#include <framework/osal/FreeRTOS/CountingSemaphore.h>
|
||||||
|
#include <framework/osal/FreeRTOS/CountingSemaphUsingTask.h>
|
||||||
#include <framework/tasks/SemaphoreFactory.h>
|
#include <framework/tasks/SemaphoreFactory.h>
|
||||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
|
|
||||||
@ -7,6 +9,9 @@ SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
|
|||||||
const uint32_t SemaphoreIF::NO_TIMEOUT = 0;
|
const uint32_t SemaphoreIF::NO_TIMEOUT = 0;
|
||||||
const uint32_t SemaphoreIF::MAX_TIMEOUT = portMAX_DELAY;
|
const uint32_t SemaphoreIF::MAX_TIMEOUT = portMAX_DELAY;
|
||||||
|
|
||||||
|
static const uint32_t USE_REGULAR_SEMAPHORES = 0;
|
||||||
|
static const uint32_t USE_TASK_NOTIFICATIONS = 1;
|
||||||
|
|
||||||
SemaphoreFactory::SemaphoreFactory() {
|
SemaphoreFactory::SemaphoreFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,13 +27,34 @@ SemaphoreFactory* SemaphoreFactory::instance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) {
|
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) {
|
||||||
|
if(argument == USE_REGULAR_SEMAPHORES) {
|
||||||
return new BinarySemaphore();
|
return new BinarySemaphore();
|
||||||
}
|
}
|
||||||
|
else if(argument == USE_TASK_NOTIFICATIONS) {
|
||||||
|
return new BinarySemaphoreUsingTask();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
|
||||||
|
"binary semaphore" << std::endl;
|
||||||
|
return new BinarySemaphore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SemaphoreIF* SemaphoreFactory::createCountingSemaphore(uint8_t count,
|
SemaphoreIF* SemaphoreFactory::createCountingSemaphore(uint8_t count,
|
||||||
uint8_t initCount, uint32_t argument) {
|
uint8_t initCount, uint32_t argument) {
|
||||||
|
if(argument == USE_REGULAR_SEMAPHORES) {
|
||||||
return new CountingSemaphore(count, initCount);
|
return new CountingSemaphore(count, initCount);
|
||||||
}
|
}
|
||||||
|
else if(argument == USE_TASK_NOTIFICATIONS) {
|
||||||
|
return new CountingSemaphoreUsingTask(count, initCount);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
|
||||||
|
"binary semaphore" << std::endl;
|
||||||
|
return new CountingSemaphore(count, initCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {
|
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {
|
||||||
delete semaphore;
|
delete semaphore;
|
||||||
|
Loading…
Reference in New Issue
Block a user