WIP: somethings wrong.. #19

Closed
muellerr wants to merge 808 commits from source/master into master
3 changed files with 68 additions and 44 deletions
Showing only changes of commit ecd740a101 - Show all commits

View File

@ -24,30 +24,20 @@ public:
return (availableReadData(n) == 0); 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; 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. //One less to avoid ambiguous full/empty problem.
return (((read[n] + size) - write - 1) % size); return (((read[n] + size) - write - 1) % size);
} }
uint32_t getRead(uint8_t n = 0) const { bool overwritesOld() const {
return read[n]; return overwriteOld;
} }
void setRead(uint32_t read, uint8_t n = 0) { size_t maxSize() const {
if (read >= start && read < (start+size)) { return size - 1;
this->read[n] = read;
}
}
uint32_t getWrite() const {
return write;
}
void setWrite(uint32_t write) {
this->write = write;
} }
void clear() { void clear() {
@ -69,13 +59,6 @@ public:
return start; return start;
} }
bool overwritesOld() const {
return overwriteOld;
}
size_t maxSize() const {
return size - 1;
}
protected: protected:
const size_t start; const size_t start;
size_t write; size_t write;
@ -106,6 +89,25 @@ protected:
return HasReturnvaluesIF::RETURN_FAILED; 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_ */ #endif /* FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_ */

View File

@ -2,31 +2,41 @@
#include <framework/ipc/MutexFactory.h> #include <framework/ipc/MutexFactory.h>
#include <framework/ipc/MutexHelper.h> #include <framework/ipc/MutexHelper.h>
SharedRingBuffer::SharedRingBuffer(const size_t size, bool overwriteOld): SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
SimpleRingBuffer(size, overwriteOld) { bool overwriteOld, dur_millis_t mutexTimeout):
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld),
mutexTimeout(mutexTimeout) {
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
} }
SharedRingBuffer::SharedRingBuffer(uint8_t *buffer, const size_t size, SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
bool overwriteOld): SimpleRingBuffer(buffer, size, overwriteOld) { const size_t size, bool overwriteOld, dur_millis_t mutexTimeout):
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld),
mutexTimeout(mutexTimeout) {
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
} }
ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data, ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data,
size_t amount, dur_millis_t timeout) { size_t amount) {
MutexHelper(mutex, timeout); MutexHelper(mutex, mutexTimeout);
return writeData(data,amount); return SimpleRingBuffer::writeData(data,amount);
} }
ReturnValue_t SharedRingBuffer::readDataProtected(uint8_t *data, size_t 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) { size_t *trueAmount) {
MutexHelper(mutex, timeout); MutexHelper(mutex, mutexTimeout);
return readData(data,amount, incrementReadPtr, readRemaining, trueAmount); return SimpleRingBuffer::readData(data,amount, incrementReadPtr,
readRemaining, trueAmount);
} }
ReturnValue_t SharedRingBuffer::deleteDataProtected(size_t amount, ReturnValue_t SharedRingBuffer::deleteDataProtected(size_t amount,
bool deleteRemaining, size_t *trueAmount, dur_millis_t timeout) { bool deleteRemaining, size_t *trueAmount) {
MutexHelper(mutex, timeout); MutexHelper(mutex, mutexTimeout);
return deleteData(amount, deleteRemaining, trueAmount); return SimpleRingBuffer::deleteData(amount, deleteRemaining, trueAmount);
}
size_t SharedRingBuffer::getAvailableReadDataProtected(uint8_t n) const {
MutexHelper(mutex, mutexTimeout);
return ((write + size) - read[n]) % size;
} }

View File

@ -2,9 +2,11 @@
#define FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_ #define FRAMEWORK_CONTAINER_SHAREDRINGBUFFER_H_
#include <framework/container/SimpleRingBuffer.h> #include <framework/container/SimpleRingBuffer.h>
#include <framework/ipc/MutexIF.h> #include <framework/ipc/MutexIF.h>
#include <framework/objectmanager/SystemObject.h>
#include <framework/timemanager/Clock.h> #include <framework/timemanager/Clock.h>
class SharedRingBuffer: public SimpleRingBuffer { class SharedRingBuffer: public SystemObject,
public SimpleRingBuffer {
public: public:
/** /**
* This constructor allocates a new internal buffer with the supplied size. * 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 * If the ring buffer is overflowing at a write operartion, the oldest data
* will be overwritten. * 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. * 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 * If the ring buffer is overflowing at a write operartion, the oldest data
* will be overwritten. * 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, void setMutexTimeout(dur_millis_t newTimeout);
dur_millis_t timeout = 10);
/** 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, 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); bool readRemaining = false, size_t *trueAmount = nullptr);
/** Performs mutex protected SimpleRingBuffer::deleteData call */
ReturnValue_t deleteDataProtected(size_t amount, ReturnValue_t deleteDataProtected(size_t amount,
bool deleteRemaining = false, size_t* trueAmount = nullptr, bool deleteRemaining = false, size_t* trueAmount = nullptr);
dur_millis_t timeout = 10);
size_t getAvailableReadDataProtected (uint8_t n = 0) const;
private: private:
dur_millis_t mutexTimeout;
MutexIF* mutex = nullptr; MutexIF* mutex = nullptr;
}; };