The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
mha_fifo_lf_t< T > Class Template Reference

A lock-free FIFO class for transferring data from a producer thread to a consumer thread. More...

Inheritance diagram for mha_fifo_lf_t< T >:
Inheritance graph

Public Member Functions

virtual void write (const T *data, unsigned count) override
 Write specified ammount of data to the fifo. More...
 
virtual void read (T *outbuf, unsigned count) override
 Read data from fifo. More...
 
virtual unsigned get_fill_count () const override
 get_fill_count() must only be called by the reader thread More...
 
virtual unsigned get_available_space () const override
 get_available_space() must only be called by the writer thread More...
 
 mha_fifo_lf_t (unsigned max_fill_count, const T &t=T())
 Create FIFO with fixed buffer size. More...
 
- Public Member Functions inherited from mha_fifo_t< T >
virtual unsigned get_max_fill_count () const
 The capacity of this fifo. More...
 
 mha_fifo_t (unsigned max_fill_count, const T &t=T())
 Create FIFO with fixed buffer size, where all (initially unused) instances of T are initialized as copies of t. More...
 
virtual ~mha_fifo_t ()=default
 Make destructor virtual. More...
 
 mha_fifo_t (const mha_fifo_t &)=delete
 Copy constructor. More...
 
 mha_fifo_t (mha_fifo_t &&)=delete
 Move constructor. More...
 
mha_fifo_t< T > & operator= (const mha_fifo_t< T > &)=delete
 Assignment operator. More...
 
mha_fifo_t< T > & operator= (mha_fifo_t< T > &&)=delete
 Move assignment operator. More...
 

Private Attributes

std::atomic< const T * > atomic_write_ptr
 atomic copy of the write_ptr, only modified by the producer thread More...
 
std::atomic< const T * > atomic_read_ptr
 atomic copy of the read ptr, only modified by the consumer thread More...
 

Additional Inherited Members

- Public Types inherited from mha_fifo_t< T >
typedef std::vector< T >::value_type value_type
 The data type exchanged by this fifo. More...
 
- Protected Member Functions inherited from mha_fifo_t< T >
void clear ()
 Empty the fifo at once. More...
 
const T * get_write_ptr () const
 read-only access to the write pointer for derived classes More...
 
const T * get_read_ptr () const
 read-only access to read pointer for derived classes More...
 
unsigned get_fill_count (const T *wp, const T *rp) const
 Compute fill count from given write pointer and read pointer. More...
 

Detailed Description

template<class T>
class mha_fifo_lf_t< T >

A lock-free FIFO class for transferring data from a producer thread to a consumer thread.

Inherits basic functionality from mha_fifo_t, adds release-acquire semantics to ensure consumer that the fill count or free space deduced from read and write pointers is consistent with the actual data. Copying, moving, and assignment of FIFO are forbidden by base class.

Constructor & Destructor Documentation

◆ mha_fifo_lf_t()

template<class T >
mha_fifo_lf_t< T >::mha_fifo_lf_t ( unsigned  max_fill_count,
const T &  t = T() 
)
inlineexplicit

Create FIFO with fixed buffer size.

All (initially unused) instances of T are initialized as copies of t

Member Function Documentation

◆ write()

template<class T >
virtual void mha_fifo_lf_t< T >::write ( const T *  data,
unsigned  count 
)
inlineoverridevirtual

Write specified ammount of data to the fifo.

Must only be called by the writer thread.

Parameters
dataPointer to source data.
countNumber of instances to copy.
Exceptions
MHA_Errorwhen there is not enough space available.

Reimplemented from mha_fifo_t< T >.

◆ read()

template<class T >
virtual void mha_fifo_lf_t< T >::read ( T *  outbuf,
unsigned  count 
)
inlineoverridevirtual

Read data from fifo.

Must only be called by the reader thread.

Parameters
outbufPointer to the target buffer.
countNumber of instances to copy.
Exceptions
MHA_Errorwhen there is not enough data available.

Reimplemented from mha_fifo_t< T >.

◆ get_fill_count()

template<class T >
virtual unsigned mha_fifo_lf_t< T >::get_fill_count ( ) const
inlineoverridevirtual

get_fill_count() must only be called by the reader thread

Reimplemented from mha_fifo_t< T >.

◆ get_available_space()

template<class T >
virtual unsigned mha_fifo_lf_t< T >::get_available_space ( ) const
inlineoverridevirtual

get_available_space() must only be called by the writer thread

Reimplemented from mha_fifo_t< T >.

Member Data Documentation

◆ atomic_write_ptr

template<class T >
std::atomic<const T *> mha_fifo_lf_t< T >::atomic_write_ptr
private

atomic copy of the write_ptr, only modified by the producer thread

◆ atomic_read_ptr

template<class T >
std::atomic<const T *> mha_fifo_lf_t< T >::atomic_read_ptr
private

atomic copy of the read ptr, only modified by the consumer thread


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