ring buffer base calls made protected
This commit is contained in:
parent
6f50356964
commit
ecd740a101
@ -24,30 +24,20 @@ public:
|
||||
return (availableReadData(n) == 0);
|
||||
}
|
||||
|
||||
uint32_t availableReadData(uint8_t n = 0) const {
|
||||
size_t availableReadData(uint8_t n = 0) const {
|
||||
return ((write + size) - read[n]) % size;
|
||||
}
|
||||
uint32_t availableWriteSpace(uint8_t n = 0) const {
|
||||
size_t availableWriteSpace(uint8_t n = 0) const {
|
||||
//One less to avoid ambiguous full/empty problem.
|
||||
return (((read[n] + size) - write - 1) % size);
|
||||
}
|
||||
|
||||
uint32_t getRead(uint8_t n = 0) const {
|
||||
return read[n];
|
||||
bool overwritesOld() const {
|
||||
return overwriteOld;
|
||||
}
|
||||
|
||||
void setRead(uint32_t read, uint8_t n = 0) {
|
||||
if (read >= start && read < (start+size)) {
|
||||
this->read[n] = read;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getWrite() const {
|
||||
return write;
|
||||
}
|
||||
|
||||
void setWrite(uint32_t write) {
|
||||
this->write = write;
|
||||
size_t maxSize() const {
|
||||
return size - 1;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
@ -69,13 +59,6 @@ public:
|
||||
return start;
|
||||
}
|
||||
|
||||
bool overwritesOld() const {
|
||||
return overwriteOld;
|
||||
}
|
||||
|
||||
size_t maxSize() const {
|
||||
return size - 1;
|
||||
}
|
||||
protected:
|
||||
const size_t start;
|
||||
size_t write;
|
||||
@ -106,6 +89,25 @@ protected:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t getRead(uint8_t n = 0) const {
|
||||
return read[n];
|
||||
}
|
||||
|
||||
void setRead(uint32_t read, uint8_t n = 0) {
|
||||
if (read >= start && read < (start+size)) {
|
||||
this->read[n] = read;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getWrite() const {
|
||||
return write;
|
||||
}
|
||||
|
||||
void setWrite(uint32_t write) {
|
||||
this->write = write;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_ */
|
||||
|
@ -2,31 +2,41 @@
|
||||
#include <framework/ipc/MutexFactory.h>
|
||||
#include <framework/ipc/MutexHelper.h>
|
||||
|
||||
SharedRingBuffer::SharedRingBuffer(const size_t size, bool overwriteOld):
|
||||
SimpleRingBuffer(size, overwriteOld) {
|
||||
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
|
||||
bool overwriteOld, dur_millis_t mutexTimeout):
|
||||
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld),
|
||||
mutexTimeout(mutexTimeout) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
SharedRingBuffer::SharedRingBuffer(uint8_t *buffer, const size_t size,
|
||||
bool overwriteOld): SimpleRingBuffer(buffer, size, overwriteOld) {
|
||||
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) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data,
|
||||
size_t amount, dur_millis_t timeout) {
|
||||
MutexHelper(mutex, timeout);
|
||||
return writeData(data,amount);
|
||||
size_t amount) {
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return SimpleRingBuffer::writeData(data,amount);
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::readDataProtected(uint8_t *data, size_t amount,
|
||||
dur_millis_t timeout, bool incrementReadPtr, bool readRemaining,
|
||||
bool incrementReadPtr, bool readRemaining,
|
||||
size_t *trueAmount) {
|
||||
MutexHelper(mutex, timeout);
|
||||
return readData(data,amount, incrementReadPtr, readRemaining, trueAmount);
|
||||
MutexHelper(mutex, mutexTimeout);
|
||||
return SimpleRingBuffer::readData(data,amount, incrementReadPtr,
|
||||
readRemaining, trueAmount);
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::deleteDataProtected(size_t amount,
|
||||
bool deleteRemaining, size_t *trueAmount, dur_millis_t timeout) {
|
||||
MutexHelper(mutex, timeout);
|
||||
return deleteData(amount, deleteRemaining, trueAmount);
|
||||
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;
|
||||
}
|
||||
|
@ -2,9 +2,11 @@
|
||||
#define FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_
|
||||
#include <framework/container/SimpleRingBuffer.h>
|
||||
#include <framework/ipc/MutexIF.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/timemanager/Clock.h>
|
||||
|
||||
class SharedRingBuffer: public SimpleRingBuffer {
|
||||
class SharedRingBuffer: public SystemObject,
|
||||
public SimpleRingBuffer {
|
||||
public:
|
||||
/**
|
||||
* This constructor allocates a new internal buffer with the supplied size.
|
||||
@ -13,7 +15,8 @@ public:
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
*/
|
||||
SharedRingBuffer(const size_t size, bool overwriteOld);
|
||||
SharedRingBuffer(object_id_t objectId, const size_t size,
|
||||
bool overwriteOld, dur_millis_t mutexTimeout = 10);
|
||||
|
||||
/**
|
||||
* This constructor takes an external buffer with the specified size.
|
||||
@ -23,17 +26,26 @@ public:
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
*/
|
||||
SharedRingBuffer(uint8_t* buffer, const size_t size, bool overwriteOld);
|
||||
SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const size_t size,
|
||||
bool overwriteOld, dur_millis_t mutexTimeout = 10);
|
||||
|
||||
ReturnValue_t writeDataProtected(const uint8_t* data, size_t amount,
|
||||
dur_millis_t timeout = 10);
|
||||
void setMutexTimeout(dur_millis_t newTimeout);
|
||||
|
||||
/** Performs mutex protected SimpleRingBuffer::writeData call */
|
||||
ReturnValue_t writeDataProtected(const uint8_t* data, size_t amount);
|
||||
|
||||
/** Performs mutex protected SimpleRingBuffer::readData call */
|
||||
ReturnValue_t readDataProtected(uint8_t *data, size_t amount,
|
||||
dur_millis_t timeout = 10, bool incrementReadPtr = false,
|
||||
bool incrementReadPtr = false,
|
||||
bool readRemaining = false, size_t *trueAmount = nullptr);
|
||||
|
||||
/** Performs mutex protected SimpleRingBuffer::deleteData call */
|
||||
ReturnValue_t deleteDataProtected(size_t amount,
|
||||
bool deleteRemaining = false, size_t* trueAmount = nullptr,
|
||||
dur_millis_t timeout = 10);
|
||||
bool deleteRemaining = false, size_t* trueAmount = nullptr);
|
||||
|
||||
size_t getAvailableReadDataProtected (uint8_t n = 0) const;
|
||||
private:
|
||||
dur_millis_t mutexTimeout;
|
||||
MutexIF* mutex = nullptr;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user