Foundation
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Foundation::Atomics::SPSCQueue< T > Class Template Reference

Atomic, bounded single-producer single-consumer FIFO ring buffer with a fixed maximum size. More...

#include <Queue.hpp>

Public Member Functions

 SPSCQueue (size_t size, Allocator *alloc)
 Construct the SPSC Queue.
 
template<typename U >
bool Push (U &&data)
 Try to push data into the queue.
 
bool Pop (T &out)
 Try to pop data from the queue.
 

Private Attributes

const size_t mModulo
 
Vector< TmBuffer
 
Atomic< size_tmRead {}
 
Atomic< size_tmWrite {}
 
size_t mReadCached {}
 
size_t mWriteCached {}
 

Detailed Description

template<typename T>
class Foundation::Atomics::SPSCQueue< T >

Atomic, bounded single-producer single-consumer FIFO ring buffer with a fixed maximum size.

Template Parameters
TData type.

Constructor & Destructor Documentation

◆ SPSCQueue()

template<typename T >
Foundation::Atomics::SPSCQueue< T >::SPSCQueue ( size_t  size,
Allocator alloc 
)
inline

Construct the SPSC Queue.

Parameters
sizeBounded size of the queue. Must be a power of two.
allocAllocator to use for internal storage.

Member Function Documentation

◆ Pop()

template<typename T >
bool Foundation::Atomics::SPSCQueue< T >::Pop ( T out)
inline

Try to pop data from the queue.

Note
Caller MUST guarantee there is only one concurrent thread calling pop.
Parameters
outReference to receive the popped data. This is only valid if the function returns true. The values are move-constructed from the queue.
Returns
True is successful, false if the queue is empty.

◆ Push()

template<typename T >
template<typename U >
bool Foundation::Atomics::SPSCQueue< T >::Push ( U &&  data)
inline

Try to push data into the queue.

Note
Caller MUST guarantee there is only one concurrent thread calling push.
Parameters
dataThe data to push.
Returns
Whether the push was successful. Returns false if the queue is full.

Member Data Documentation

◆ mBuffer

template<typename T >
Vector<T> Foundation::Atomics::SPSCQueue< T >::mBuffer
private

◆ mModulo

template<typename T >
const size_t Foundation::Atomics::SPSCQueue< T >::mModulo
private

◆ mRead

template<typename T >
Atomic<size_t> Foundation::Atomics::SPSCQueue< T >::mRead {}
private

◆ mReadCached

template<typename T >
size_t Foundation::Atomics::SPSCQueue< T >::mReadCached {}
private

◆ mWrite

template<typename T >
Atomic<size_t> Foundation::Atomics::SPSCQueue< T >::mWrite {}
private

◆ mWriteCached

template<typename T >
size_t Foundation::Atomics::SPSCQueue< T >::mWriteCached {}
private

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