Games Task Scheduler (GTS)
A multi-processor scheduling framework for games engines
gts::QueueSPSC< T, TAllocator > Class Template Reference

A single-producer, single-consumer queue. Properties: More...

#include <QueueSPSC.h>

Inherits gts::AlignedAllocator< GTS_NO_SHARING_CACHE_LINE_SIZE >.

Public Types

using value_type = T
 
using size_type = size_t
 
using allocator_type = TAllocator
 

Public Member Functions

 QueueSPSC (allocator_type const &allocator=allocator_type())
 
 ~QueueSPSC ()
 
 QueueSPSC (QueueSPSC const &other)
 
 QueueSPSC (QueueSPSC &&other)
 
QueueSPSCoperator= (QueueSPSC const &other)
 
QueueSPSCoperator= (QueueSPSC &&other)
 
bool empty () const
 
size_type size () const
 
size_type capacity () const
 
allocator_type get_allocator () const
 
void reserve (size_type sizePow2)
 
void clear ()
 
bool tryPush (const value_type &val)
 
bool tryPush (value_type &&val)
 
bool tryPop (value_type &out)
 
template<typename... TArgs>
bool _insert (TArgs &&... args)
 

Detailed Description

template<typename T, typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
class gts::QueueSPSC< T, TAllocator >

A single-producer, single-consumer queue. Properties:

  • Wait-free.
  • Unbound.
  • Linearizable.
    Template Parameters
    TThe type stored in the container.
    TAllocatorThe allocator used by the storage backing.

Constructor & Destructor Documentation

◆ QueueSPSC() [1/3]

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
gts::QueueSPSC< T, TAllocator >::QueueSPSC ( allocator_type const &  allocator = allocator_type())
explicit

Constructs an empty container with the given 'allocator'.

Remarks
Thread-safe.

◆ ~QueueSPSC()

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
QueueSPSC::~QueueSPSC ( )

Destructs the container. The destructors of the elements are called and the used storage is deallocated.

Remarks
Not thread-safe.

◆ QueueSPSC() [2/3]

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
QueueSPSC::QueueSPSC ( QueueSPSC< T, TAllocator > const &  other)

Copy constructor. Constructs the container with the copy of the contents of 'other'.

Remarks
Not thread-safe.

◆ QueueSPSC() [3/3]

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
QueueSPSC::QueueSPSC ( QueueSPSC< T, TAllocator > &&  other)

Move constructor. Constructs the container with the contents of other using move semantics. After the move, other is invalid.

Remarks
Not thread-safe.

Member Function Documentation

◆ capacity()

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
QueueSPSC< T, TAllocator >::size_type QueueSPSC::capacity ( ) const
Returns
The capacity of the queue.
Remarks
Not thread-safe.

◆ clear()

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void QueueSPSC::clear ( )

Removes all elements from the queue.

Remarks
Not thread-safe.

◆ empty()

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
bool QueueSPSC::empty ( ) const
Returns
True of the queue is empty, false otherwise.
Remarks
Not thread-safe.

◆ get_allocator()

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
QueueSPSC< T, TAllocator >::allocator_type QueueSPSC::get_allocator ( ) const
Returns
This queue's allocator.
Remarks
Thread-safe.

◆ operator=() [1/2]

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
QueueSPSC< T, TAllocator > & QueueSPSC::operator= ( QueueSPSC< T, TAllocator > &&  other)

Move assignment operator. Replaces the contents with those of other using move semantics. After the move, other is invalid.

Remarks
Not thread-safe.

◆ operator=() [2/2]

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
QueueSPSC< T, TAllocator > & QueueSPSC::operator= ( QueueSPSC< T, TAllocator > const &  other)

Copy assignment operator. Replaces the contents with a copy of the contents of 'other'.

Remarks
Not thread-safe.

◆ reserve()

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
void gts::QueueSPSC< T, TAllocator >::reserve ( size_type  sizePow2)

Increases the capacity of the queue. Does nothing if 'sizePow2' < capacity.

Remarks
Not thread-safe.

◆ size()

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
QueueSPSC< T, TAllocator >::size_type QueueSPSC::size ( ) const
Returns
The number of elements in the queue.
Remarks
Not thread-safe.

◆ tryPop()

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
bool QueueSPSC::tryPop ( value_type &  out)

Pops an element from the queue and copies it into 'out'.

Returns
True if the pop succeeded, false otherwise.
Remarks
Single consumer thread-safe.

◆ tryPush() [1/2]

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
bool QueueSPSC::tryPush ( const value_type &  val)

Copies 'val' to the back of the queue.

Returns
True if the push, false otherwise.
Remarks
Single producer thread-safe.

◆ tryPush() [2/2]

template<typename T , typename TAllocator = gts::AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
bool QueueSPSC::tryPush ( value_type &&  val)

Moves 'val' to the back of the queue.

Returns
True if the push, false otherwise.
Remarks
Single producer thread-safe.