The Open Master Hearing Aid (openMHA)
openMHA
Open community platform for hearing aid algorithm research
|
A lock-free FIFO class for transferring data from a producer thread to a consumer thread. More...
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... | |
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.
|
inlineexplicit |
Create FIFO with fixed buffer size.
All (initially unused) instances of T are initialized as copies of t
|
inlineoverridevirtual |
Write specified ammount of data to the fifo.
Must only be called by the writer thread.
data | Pointer to source data. |
count | Number of instances to copy. |
MHA_Error | when there is not enough space available. |
Reimplemented from mha_fifo_t< T >.
|
inlineoverridevirtual |
Read data from fifo.
Must only be called by the reader thread.
outbuf | Pointer to the target buffer. |
count | Number of instances to copy. |
MHA_Error | when there is not enough data available. |
Reimplemented from mha_fifo_t< T >.
|
inlineoverridevirtual |
get_fill_count() must only be called by the reader thread
Reimplemented from mha_fifo_t< T >.
|
inlineoverridevirtual |
get_available_space() must only be called by the writer thread
Reimplemented from mha_fifo_t< T >.
|
private |
atomic copy of the write_ptr, only modified by the producer thread
|
private |
atomic copy of the read ptr, only modified by the consumer thread