added locked write helper method

This commit is contained in:
Robin Müller 2024-03-19 18:55:13 +01:00
parent 24d41e7863
commit a3eb81f1de
6 changed files with 29 additions and 6 deletions

View File

@ -1,5 +1,6 @@
#include "fsfw/container/SharedRingBuffer.h" #include "fsfw/container/SharedRingBuffer.h"
#include "SharedRingBuffer.h"
#include "fsfw/ipc/MutexFactory.h" #include "fsfw/ipc/MutexFactory.h"
#include "fsfw/ipc/MutexGuard.h" #include "fsfw/ipc/MutexGuard.h"
@ -50,3 +51,22 @@ DynamicFIFO<size_t>* SharedRingBuffer::getReceiveSizesFIFO() {
} }
return receiveSizesFIFO; return receiveSizesFIFO;
} }
ReturnValue_t SharedRingBuffer::lockedWrite(const uint8_t* data, size_t dataLen,
MutexIF::TimeoutType lockType, uint32_t waitTimeMs) {
MutexGuard mg(mutex, lockType, waitTimeMs);
if (availableWriteSpace() < dataLen ||
(receiveSizesFIFO != nullptr && receiveSizesFIFO->full())) {
return returnvalue::FAILED;
}
// The following two operation should not fail..
ReturnValue_t result = writeData(data, dataLen);
if (result != returnvalue::OK) {
return result;
}
if (receiveSizesFIFO != nullptr) {
result = receiveSizesFIFO->insert(dataLen);
if (result != returnvalue::OK) {
return result;
}
}
}

View File

@ -80,6 +80,9 @@ class SharedRingBuffer : public SystemObject, public SimpleRingBuffer {
*/ */
DynamicFIFO<size_t>* getReceiveSizesFIFO(); DynamicFIFO<size_t>* getReceiveSizesFIFO();
ReturnValue_t lockedWrite(const uint8_t* data, size_t dataLen, MutexIF::TimeoutType lockType,
uint32_t waitTimeMs);
private: private:
MutexIF* mutex = nullptr; MutexIF* mutex = nullptr;

View File

@ -3,9 +3,9 @@
#include <atomic> #include <atomic>
#include <condition_variable> #include <condition_variable>
#include <string>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <string>
#include "fsfw/objectmanager/ObjectManagerIF.h" #include "fsfw/objectmanager/ObjectManagerIF.h"
#include "fsfw/tasks/FixedSlotSequence.h" #include "fsfw/tasks/FixedSlotSequence.h"

View File

@ -3,9 +3,9 @@
#include <atomic> #include <atomic>
#include <condition_variable> #include <condition_variable>
#include <string>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <string>
#include "fsfw/objectmanager/ObjectManagerIF.h" #include "fsfw/objectmanager/ObjectManagerIF.h"
#include "fsfw/tasks/PeriodicTaskBase.h" #include "fsfw/tasks/PeriodicTaskBase.h"

View File

@ -3,8 +3,8 @@
#include <fsfw/returnvalues/returnvalue.h> #include <fsfw/returnvalues/returnvalue.h>
#include <thread>
#include <string> #include <string>
#include <thread>
namespace tasks { namespace tasks {