Loading [MathJax]/extensions/tex2jax.js
TINC
Toolkit for Interactive Computation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
tinc::BufferManager< DataType > Class Template Reference

#include <BufferManager.hpp>

Inheritance diagram for tinc::BufferManager< DataType >:
tinc::DiskBuffer< NetCDFData > tinc::DiskBuffer< std::string > tinc::DiskBuffer< al::Image > tinc::DiskBuffer< nlohmann::json > tinc::DeferredComputation< DataType > tinc::DiskBuffer< DataType > tinc::DiskBufferNetCDFData tinc::DiskBufferText tinc::DiskBufferImage tinc::DiskBufferJson

Public Member Functions

 BufferManager (uint16_t size=2)
 
std::shared_ptr< DataType > get (bool markAsUsed=true)
 Get current buffer for reading. More...
 
std::shared_ptr< DataType > get (bool *isNew)
 Get current buffer for reading checking if data is new. More...
 
std::shared_ptr< DataType > getWritable ()
 Get a pointer to a writable buffer. More...
 
void doneWriting (std::shared_ptr< DataType > buffer)
 Mark a buffer as ready to read. More...
 
bool newDataAvailable ()
 Check if there are buffers that have been written but not read. More...
 

Public Attributes

const int mSize
 

Protected Attributes

std::vector< std::shared_ptr< DataType > > mData
 
std::mutex mDataLock
 
bool mNewData {false}
 
uint16_t mReadBuffer {0}
 
uint16_t mWriteBuffer {1}
 

Detailed Description

template<class DataType>
class tinc::BufferManager< DataType >

The BufferManager class provides a thread safe memory buffer that can do fast reads as it requires only a pointer swap. It provides double buffering by default, but it allows for a larger number of write buffers in cases where concurrent writes would otherwise block the other writes.

Definition at line 48 of file BufferManager.hpp.

Constructor & Destructor Documentation

◆ BufferManager()

template<class DataType >
tinc::BufferManager< DataType >::BufferManager ( uint16_t  size = 2)
inline

Definition at line 52 of file BufferManager.hpp.

Member Function Documentation

◆ doneWriting()

template<class DataType >
void tinc::BufferManager< DataType >::doneWriting ( std::shared_ptr< DataType >  buffer)
inline

Mark a buffer as ready to read.

Parameters
bufferThe buffer previously received from getWritable()

The buffer provided must come from getWritable() otherwise behavior is undefined.

Definition at line 114 of file BufferManager.hpp.

◆ get() [1/2]

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::get ( bool *  isNew)
inline

Get current buffer for reading checking if data is new.

Parameters
isNewthis is set to true if data returned is "new", false otherwise
Returns

Definition at line 76 of file BufferManager.hpp.

◆ get() [2/2]

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::get ( bool  markAsUsed = true)
inline

Get current buffer for reading.

Parameters
markAsUsedif false, the returned buffer keeps its "new" status
Returns
a pointer to the data

Definition at line 63 of file BufferManager.hpp.

◆ getWritable()

template<class DataType >
std::shared_ptr<DataType> tinc::BufferManager< DataType >::getWritable ( )
inline

Get a pointer to a writable buffer.

When done writing this buffer, call doneWriting()

Definition at line 92 of file BufferManager.hpp.

◆ newDataAvailable()

template<class DataType >
bool tinc::BufferManager< DataType >::newDataAvailable ( )
inline

Check if there are buffers that have been written but not read.

Definition at line 124 of file BufferManager.hpp.

Member Data Documentation

◆ mData

template<class DataType >
std::vector<std::shared_ptr<DataType> > tinc::BufferManager< DataType >::mData
protected

Definition at line 130 of file BufferManager.hpp.

◆ mDataLock

template<class DataType >
std::mutex tinc::BufferManager< DataType >::mDataLock
protected

Definition at line 132 of file BufferManager.hpp.

◆ mNewData

template<class DataType >
bool tinc::BufferManager< DataType >::mNewData {false}
protected

Definition at line 133 of file BufferManager.hpp.

◆ mReadBuffer

template<class DataType >
uint16_t tinc::BufferManager< DataType >::mReadBuffer {0}
protected

Definition at line 134 of file BufferManager.hpp.

◆ mSize

template<class DataType >
const int tinc::BufferManager< DataType >::mSize

Definition at line 50 of file BufferManager.hpp.

◆ mWriteBuffer

template<class DataType >
uint16_t tinc::BufferManager< DataType >::mWriteBuffer {1}
protected

Definition at line 135 of file BufferManager.hpp.


The documentation for this class was generated from the following file: