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,
|
|
|
|
bool overwriteOld, dur_millis_t mutexTimeout):
|
|
|
|
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld),
|
|
|
|
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,
|
|
|
|
const size_t size, bool overwriteOld, dur_millis_t mutexTimeout):
|
|
|
|
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld),
|
|
|
|
mutexTimeout(mutexTimeout) {
|
2020-07-09 14:26:15 +02:00
|
|
|
mutex = MutexFactory::instance()->createMutex();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|