NebulaStream
0.6.213
NebulaStream is a data and application management framework for the internet of things
|
#include <MMapCircularBuffer.hpp>
Public Member Functions | |
MMapCircularBuffer (size_t capacity) | |
~MMapCircularBuffer () | |
reader | read () |
writer | write () |
size_t | size () const |
size_t | capacity () const |
bool | full () const |
bool | empty () const |
A CircularBuffer which efficiently allows a writer to append data to the buffer which a reader can consume from the Buffer, after the writer commits its changes, during destruction. This variant exploits virtual mapped memory to create the illusion of a continuous ring of memory. The API exposes a writer, which reserves memory for writing and commits written memory using RAII. The reader allows a consumer to peek into the data, before consuming it.
This buffer is not thread safe! More over it is not allowed to have a reader and a writer at the same time.
|
explicit |
We create a anomynous memory segement, by creating an inmemory File, resizing it to the capacity. The memory segment is mapped into the processes address space twice. That way there exists now two distinct memory addresses that refer to the same memory. A write to address 0 will be equivalent to a write to address capacity. This allows to create the illusion of a ring in memory. Reads and writes that would previously need to account for a wrap around can now be contigous. This illusion is maintained by wrapping the read and write index during reads.
References data, and NES_ASSERT.
MMapCircularBuffer::~MMapCircularBuffer | ( | ) |
References data.
size_t MMapCircularBuffer::capacity | ( | ) | const |
Gets the total capacity of the buffer. Capacity is always a multiple of the getpagesize()
.
Referenced by NES::TEST_F().
bool MMapCircularBuffer::empty | ( | ) | const |
References size().
Referenced by NES::TEST_F().
bool MMapCircularBuffer::full | ( | ) | const |
References size().
Referenced by NES::TEST_F().
MMapCircularBuffer::reader MMapCircularBuffer::read | ( | ) |
Returns a view of the readable memory. Calling consume will consume the memory once the destructor of the reader is called.
References data, NES_ASSERT, NES_TRACE, size(), and SPAN_TYPE.
Referenced by NES::TEST_F().
size_t MMapCircularBuffer::size | ( | ) | const |
Gets the current size of the buffer
Referenced by empty(), full(), read(), NES::TEST_F(), and write().
MMapCircularBuffer::writer MMapCircularBuffer::write | ( | ) |
Returns a view of the writeable memory. Calling consume will mark the memory as used once the destructor of the writer is called.
References data, NES_ASSERT, NES_TRACE, size(), and SPAN_TYPE.
Referenced by NES::TEST_F().