tweaked factory to have configurability

This commit is contained in:
Robin Müller 2020-05-27 19:56:02 +02:00
parent b4065c7764
commit eabee85ba9
3 changed files with 44 additions and 4 deletions

View File

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

View File

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

View File

@ -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,12 +27,33 @@ SemaphoreFactory* SemaphoreFactory::instance() {
} }
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) { SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) {
return new BinarySemaphore(); if(argument == USE_REGULAR_SEMAPHORES) {
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) {
return new CountingSemaphore(count, initCount); if(argument == USE_REGULAR_SEMAPHORES) {
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) {