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

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

#include <QueueMPSC.h>

Inherits gts::AlignedAllocator< GTS_NO_SHARING_CACHE_LINE_SIZE >.

Public Types

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

Public Member Functions

 TicketQueueMPSC (size_t numQueues, allocator_type const &allocator=allocator_type())
 
 TicketQueueMPSC (size_t numQueues, size_type sizePow2, allocator_type const &allocator=allocator_type())
 
 TicketQueueMPSC (TicketQueueMPSC const &other)
 
 TicketQueueMPSC (TicketQueueMPSC &&other)
 
TicketQueueMPSCoperator= (TicketQueueMPSC const &other)
 
TicketQueueMPSCoperator= (TicketQueueMPSC &&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 (size_type ticket, const value_type &val)
 
bool tryPush (size_type ticket, value_type &&val)
 
bool tryPop (size_type ticket, value_type &out)
 

Detailed Description

template<typename T, typename TMutex = UnfairSpinMutex<>, typename TAllocator = AlignedAllocator<GTS_NO_SHARING_CACHE_LINE_SIZE>>
class gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >

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

  • Unbound.
  • Linearizable.
  • Contiguous memory.
    Template Parameters
    TThe type stored in the container.
    TMutexThe mutex type that guards access to the container.
    TAllocatorThe allocator used for T.
    TSizeThe integral type used for the container size.

Constructor & Destructor Documentation

◆ TicketQueueMPSC() [1/2]

template<typename T , typename TMutex , typename TAllocator >
gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::TicketQueueMPSC ( TicketQueueMPSC< T, TMutex, TAllocator > const &  other)

Copy constructor.

Remarks
Not thread-safe.

◆ TicketQueueMPSC() [2/2]

template<typename T , typename TMutex , typename TAllocator >
gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::TicketQueueMPSC ( TicketQueueMPSC< T, TMutex, TAllocator > &&  other)

Move constructor.

Remarks
Not thread-safe.

Member Function Documentation

◆ capacity()

template<typename T , typename TMutex , typename TAllocator >
TicketQueueMPSC< T, TMutex, TAllocator >::size_type gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::capacity
Returns
The capacity of the queue.
Remarks
Thread-safe, but may return a previous value of capacity.

◆ clear()

template<typename T , typename TMutex , typename TAllocator >
void gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::clear

Removes all elements from the queue.

Remarks
Thread-safe.

◆ empty()

template<typename T , typename TMutex , typename TAllocator >
bool gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::empty
Returns
True of the queue is empty, false otherwise.
Remarks
Thread-safe.

◆ get_allocator()

template<typename T , typename TMutex , typename TAllocator >
TicketQueueMPSC< T, TMutex, TAllocator >::allocator_type gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::get_allocator
Returns
This queue's allocator.
Remarks
Thread-safe.

◆ operator=() [1/2]

template<typename T , typename TMutex , typename TAllocator >
TicketQueueMPSC< T, TMutex, TAllocator > & gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::operator= ( TicketQueueMPSC< T, TMutex, TAllocator > &&  other)

Move assignment.

Remarks
Not thread-safe.

◆ operator=() [2/2]

template<typename T , typename TMutex , typename TAllocator >
TicketQueueMPSC< T, TMutex, TAllocator > & gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::operator= ( TicketQueueMPSC< T, TMutex, TAllocator > const &  other)

Copy assignment.

Remarks
Not thread-safe.

◆ reserve()

template<typename T , typename TMutex , typename TAllocator >
void gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::reserve ( size_type  sizePow2)

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

Remarks
Thread-safe.

◆ size()

template<typename T , typename TMutex , typename TAllocator >
TicketQueueMPSC< T, TMutex, TAllocator >::size_type gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::size
Returns
The number of elements in the queue.
Remarks
Thread-safe.

◆ tryPop()

template<typename T , typename TMutex , typename TAllocator >
bool gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::tryPop ( size_type  ticket,
value_type &  out 
)

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

Returns
True if the pop succeeded, false otherwise.
Remarks
Thread-safe.

◆ tryPush() [1/2]

template<typename T , typename TMutex , typename TAllocator >
bool gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::tryPush ( size_type  ticket,
const value_type &  val 
)

Copies 'val' into the queue.

Returns
True if the pop push, false otherwise.
Remarks
Thread-safe.

◆ tryPush() [2/2]

template<typename T , typename TMutex , typename TAllocator >
bool gts::internal::TicketQueueMPSC< T, TMutex, TAllocator >::tryPush ( size_type  ticket,
value_type &&  val 
)

Moves 'val' into the queue.

Returns
True if the pop push, false otherwise.
Remarks
Thread-safe.