fsfw/container/SharedRingBuffer.cpp

50 lines
1.8 KiB
C++
Raw Normal View History

2020-07-09 14:26:15 +02:00
#include <framework/container/SharedRingBuffer.h>
#include <framework/ipc/MutexFactory.h>
#include <framework/ipc/MutexHelper.h>
2020-07-09 15:47:50 +02:00
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
2020-08-04 02:25:10 +02:00
bool overwriteOld, size_t maxExcessBytes, dur_millis_t mutexTimeout):
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld,
maxExcessBytes), mutexTimeout(mutexTimeout) {
2020-07-09 14:26:15 +02:00
mutex = MutexFactory::instance()->createMutex();
}
2020-07-09 15:47:50 +02:00
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
2020-08-04 02:25:10 +02:00
const size_t size, bool overwriteOld, size_t maxExcessBytes,
dur_millis_t mutexTimeout):
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld,
maxExcessBytes), mutexTimeout(mutexTimeout) {
2020-07-09 14:26:15 +02:00
mutex = MutexFactory::instance()->createMutex();
}
2020-08-04 02:25:10 +02:00
ReturnValue_t SharedRingBuffer::getFreeElementProtected(uint8_t** writePtr,
size_t amount) {
MutexHelper(mutex, mutexTimeout);
return SimpleRingBuffer::getFreeElement(writePtr,amount);
}
2020-07-09 14:26:15 +02:00
ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data,
2020-07-09 15:47:50 +02:00
size_t amount) {
MutexHelper(mutex, mutexTimeout);
return SimpleRingBuffer::writeData(data,amount);
2020-07-09 14:26:15 +02:00
}
ReturnValue_t SharedRingBuffer::readDataProtected(uint8_t *data, size_t amount,
2020-07-09 15:47:50 +02:00
bool incrementReadPtr, bool readRemaining,
2020-07-09 14:26:15 +02:00
size_t *trueAmount) {
2020-07-09 15:47:50 +02:00
MutexHelper(mutex, mutexTimeout);
return SimpleRingBuffer::readData(data,amount, incrementReadPtr,
readRemaining, trueAmount);
2020-07-09 14:26:15 +02:00
}
ReturnValue_t SharedRingBuffer::deleteDataProtected(size_t amount,
2020-07-09 15:47:50 +02:00
bool deleteRemaining, size_t *trueAmount) {
MutexHelper(mutex, mutexTimeout);
return SimpleRingBuffer::deleteData(amount, deleteRemaining, trueAmount);
}
size_t SharedRingBuffer::getAvailableReadDataProtected(uint8_t n) const {
MutexHelper(mutex, mutexTimeout);
return ((write + size) - read[n]) % size;
2020-07-09 14:26:15 +02:00
}