From 6b475792a4a7c57a5006a010c554dda8b31d41b7 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 4 Aug 2020 02:25:10 +0200 Subject: [PATCH] shared ring buffer continued --- container/SharedRingBuffer.cpp | 19 +++++++++++++------ container/SharedRingBuffer.h | 9 +++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/container/SharedRingBuffer.cpp b/container/SharedRingBuffer.cpp index 64cbc669..86277a80 100644 --- a/container/SharedRingBuffer.cpp +++ b/container/SharedRingBuffer.cpp @@ -3,19 +3,26 @@ #include SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size, - bool overwriteOld, dur_millis_t mutexTimeout): - SystemObject(objectId), SimpleRingBuffer(size, overwriteOld), - mutexTimeout(mutexTimeout) { + bool overwriteOld, size_t maxExcessBytes, dur_millis_t mutexTimeout): + SystemObject(objectId), SimpleRingBuffer(size, overwriteOld, + maxExcessBytes), mutexTimeout(mutexTimeout) { mutex = MutexFactory::instance()->createMutex(); } 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) { + const size_t size, bool overwriteOld, size_t maxExcessBytes, + dur_millis_t mutexTimeout): + SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld, + maxExcessBytes), mutexTimeout(mutexTimeout) { mutex = MutexFactory::instance()->createMutex(); } +ReturnValue_t SharedRingBuffer::getFreeElementProtected(uint8_t** writePtr, + size_t amount) { + MutexHelper(mutex, mutexTimeout); + return SimpleRingBuffer::getFreeElement(writePtr,amount); +} + ReturnValue_t SharedRingBuffer::writeDataProtected(const uint8_t *data, size_t amount) { MutexHelper(mutex, mutexTimeout); diff --git a/container/SharedRingBuffer.h b/container/SharedRingBuffer.h index f7d3bc3c..7fed7b22 100644 --- a/container/SharedRingBuffer.h +++ b/container/SharedRingBuffer.h @@ -17,7 +17,8 @@ public: * will be overwritten. */ SharedRingBuffer(object_id_t objectId, const size_t size, - bool overwriteOld, dur_millis_t mutexTimeout = 10); + bool overwriteOld, size_t maxExcessBytes, + dur_millis_t mutexTimeout = 10); /** * This constructor takes an external buffer with the specified size. @@ -28,10 +29,14 @@ public: * will be overwritten. */ SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const size_t size, - bool overwriteOld, dur_millis_t mutexTimeout = 10); + bool overwriteOld, size_t maxExcessBytes, + dur_millis_t mutexTimeout = 10); void setMutexTimeout(dur_millis_t newTimeout); + /** Performs mutex protected SimpleRingBuffer::getFreeElement call */ + ReturnValue_t getFreeElementProtected(uint8_t** writePtr, size_t amount); + /** Performs mutex protected SimpleRingBuffer::writeData call */ ReturnValue_t writeDataProtected(const uint8_t* data, size_t amount);