updated linux implementation

This commit is contained in:
Robin Müller 2020-08-27 17:06:10 +02:00
parent 7723ee13b3
commit 73db79a3fe
5 changed files with 135 additions and 137 deletions

View File

@ -1,5 +1,5 @@
#include <framework/osal/linux/BinarySemaphore.h> #include "../../osal/linux/BinarySemaphore.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include "../../serviceinterface/ServiceInterfaceStream.h"
extern "C" { extern "C" {
#include <errno.h> #include <errno.h>
@ -25,15 +25,16 @@ BinarySemaphore& BinarySemaphore::operator =(
return * this; return * this;
} }
ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) { ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType,
uint32_t timeoutMs) {
int result = 0; int result = 0;
if(timeoutMs == SemaphoreIF::POLLING) { if(timeoutType == TimeoutType::POLLING) {
result = sem_trywait(&handle); result = sem_trywait(&handle);
} }
else if(timeoutMs == SemaphoreIF::BLOCKING) { else if(timeoutType == TimeoutType::BLOCKING) {
result = sem_wait(&handle); result = sem_wait(&handle);
} }
else if(timeoutMs > SemaphoreIF::POLLING){ else if(timeoutType == TimeoutType::WAITING){
timespec timeOut; timespec timeOut;
clock_gettime(CLOCK_REALTIME, &timeOut); clock_gettime(CLOCK_REALTIME, &timeOut);
uint64_t nseconds = timeOut.tv_sec * 1000000000 + timeOut.tv_nsec; uint64_t nseconds = timeOut.tv_sec * 1000000000 + timeOut.tv_nsec;

View File

@ -1,8 +1,8 @@
#ifndef FRAMEWORK_OSAL_LINUX_BINARYSEMPAHORE_H_ #ifndef FRAMEWORK_OSAL_LINUX_BINARYSEMPAHORE_H_
#define FRAMEWORK_OSAL_LINUX_BINARYSEMPAHORE_H_ #define FRAMEWORK_OSAL_LINUX_BINARYSEMPAHORE_H_
#include <framework/returnvalues/HasReturnvaluesIF.h> #include "../../returnvalues/HasReturnvaluesIF.h"
#include <framework/tasks/SemaphoreIF.h> #include "../../tasks/SemaphoreIF.h"
extern "C" { extern "C" {
#include <semaphore.h> #include <semaphore.h>
@ -49,8 +49,8 @@ public:
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout * -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
*/ */
ReturnValue_t acquire(uint32_t timeoutMs = ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
SemaphoreIF::BLOCKING) override; uint32_t timeoutMs = 0) override;
/** /**
* Release the binary semaphore. * Release the binary semaphore.

View File

@ -1,5 +1,5 @@
#include <framework/osal/linux/CountingSemaphore.h> #include "../../osal/linux/CountingSemaphore.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include "../../serviceinterface/ServiceInterfaceStream.h"
CountingSemaphore::CountingSemaphore(const uint8_t maxCount, uint8_t initCount): CountingSemaphore::CountingSemaphore(const uint8_t maxCount, uint8_t initCount):
maxCount(maxCount), initCount(initCount) { maxCount(maxCount), initCount(initCount) {

View File

@ -1,6 +1,6 @@
#ifndef FRAMEWORK_OSAL_LINUX_COUNTINGSEMAPHORE_H_ #ifndef FRAMEWORK_OSAL_LINUX_COUNTINGSEMAPHORE_H_
#define FRAMEWORK_OSAL_LINUX_COUNTINGSEMAPHORE_H_ #define FRAMEWORK_OSAL_LINUX_COUNTINGSEMAPHORE_H_
#include <framework/osal/linux/BinarySemaphore.h> #include "../../osal/linux/BinarySemaphore.h"
/** /**
* @brief Counting semaphores, which can be acquired more than once. * @brief Counting semaphores, which can be acquired more than once.

View File

@ -1,10 +1,7 @@
#include <framework/tasks/SemaphoreFactory.h> #include "../../tasks/SemaphoreFactory.h"
#include <framework/osal/linux/BinarySemaphore.h> #include "../../osal/linux/BinarySemaphore.h"
#include <framework/osal/linux/CountingSemaphore.h> #include "../../osal/linux/CountingSemaphore.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include "../../serviceinterface/ServiceInterfaceStream.h"
const uint32_t SemaphoreIF::POLLING = 0;
const uint32_t SemaphoreIF::BLOCKING = 0xffffffff;
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr; SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;