From 826f4ce29c22a000da949d9a3efa3b6c5dd4f4d2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 4 Nov 2022 11:16:22 +0100 Subject: [PATCH] add lock, use generic sem interface --- linux/devices/ploc/PlocSupvHelper.cpp | 16 ++++++++++------ linux/devices/ploc/PlocSupvHelper.h | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/linux/devices/ploc/PlocSupvHelper.cpp b/linux/devices/ploc/PlocSupvHelper.cpp index 24f436aa..a7245cc1 100644 --- a/linux/devices/ploc/PlocSupvHelper.cpp +++ b/linux/devices/ploc/PlocSupvHelper.cpp @@ -3,6 +3,7 @@ #include #include // Contains file controls like O_RDWR #include +#include #include #include @@ -27,6 +28,9 @@ using namespace returnvalue; PlocSupvHelper::PlocSupvHelper(object_id_t objectId) : SystemObject(objectId), ringBuf(4096, true) { spParams.maxSize = sizeof(commandBuffer); resetSpParams(); + semaphore = SemaphoreFactory::instance()->createBinarySemaphore(); + semaphore->acquire(); + lock = MutexFactory::instance()->createMutex(); } PlocSupvHelper::~PlocSupvHelper() {} @@ -44,11 +48,11 @@ ReturnValue_t PlocSupvHelper::initialize() { ReturnValue_t PlocSupvHelper::performOperation(uint8_t operationCode) { ReturnValue_t result = returnvalue::OK; - semaphore.acquire(); + semaphore->acquire(); while (true) { switch (internalState) { case InternalState::IDLE: { - semaphore.acquire(); + semaphore->acquire(); break; } case InternalState::UPDATE: { @@ -164,7 +168,7 @@ ReturnValue_t PlocSupvHelper::performUpdate(const supv::UpdateParams& params) { update.sequenceCount = params.seqCount; internalState = InternalState::UPDATE; uartComIF->flushUartTxAndRxBuf(comCookie); - semaphore.release(); + semaphore->release(); return result; } @@ -183,13 +187,13 @@ ReturnValue_t PlocSupvHelper::performMemCheck(uint8_t memoryId, uint32_t startAd update.crcShouldBeChecked = checkCrc; internalState = InternalState::CHECK_MEMORY; uartComIF->flushUartTxAndRxBuf(comCookie); - semaphore.release(); + semaphore->release(); return returnvalue::OK; } void PlocSupvHelper::initiateUpdateContinuation() { internalState = InternalState::CONTINUE_UPDATE; - semaphore.release(); + semaphore->release(); } ReturnValue_t PlocSupvHelper::startEventBufferRequest(std::string path) { @@ -205,7 +209,7 @@ ReturnValue_t PlocSupvHelper::startEventBufferRequest(std::string path) { eventBufferReq.path = path; internalState = InternalState::REQUEST_EVENT_BUFFER; uartComIF->flushUartTxAndRxBuf(comCookie); - semaphore.release(); + semaphore->release(); return returnvalue::OK; } diff --git a/linux/devices/ploc/PlocSupvHelper.h b/linux/devices/ploc/PlocSupvHelper.h index 4e1c4c17..809dfd5b 100644 --- a/linux/devices/ploc/PlocSupvHelper.h +++ b/linux/devices/ploc/PlocSupvHelper.h @@ -186,6 +186,8 @@ class PlocSupvHelper : public DeviceCommunicationIF, struct Update update; + SemaphoreIF* semaphore; + MutexIF* lock; int serialPort = 0; struct termios tty = {}; @@ -202,7 +204,6 @@ class PlocSupvHelper : public DeviceCommunicationIF, InternalState internalState = InternalState::IDLE; - BinarySemaphore semaphore; #ifdef XIPHOS_Q7S SdCardManager* sdcMan = nullptr; #endif