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

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

#include <QueueMPMC.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

 TicketQueueMPMC (size_t numQueues, allocator_type const &allocator=allocator_type())
 
 TicketQueueMPMC (size_t numQueues, size_type sizePow2, allocator_type const &allocator=allocator_type())
 
 TicketQueueMPMC (TicketQueueMPMC const &other)
 
 TicketQueueMPMC (TicketQueueMPMC &&other)
 
TicketQueueMPMCoperator= (TicketQueueMPMC const &other)
 
TicketQueueMPMCoperator= (TicketQueueMPMC &&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::TicketQueueMPMC< T, TMutex, TAllocator >

A multi-producer, multi-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

◆ TicketQueueMPMC() [1/2]

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

Copy constructor.

Remarks
Not thread-safe.

◆ TicketQueueMPMC() [2/2]

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

Move constructor.

Remarks
Not thread-safe.

Member Function Documentation

◆ capacity()

template<typename T , typename TMutex , typename TAllocator >
TicketQueueMPMC< T, TMutex, TAllocator >::size_type gts::internal::TicketQueueMPMC< 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::TicketQueueMPMC< T, TMutex, TAllocator >::clear

Removes all elements from the queue.

Remarks
Thread-safe.

◆ empty()

template<typename T , typename TMutex , typename TAllocator >
bool gts::internal::TicketQueueMPMC< 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 >
TicketQueueMPMC< T, TMutex, TAllocator >::allocator_type gts::internal::TicketQueueMPMC< T, TMutex, TAllocator >::get_allocator
Returns
This queue's allocator.
Remarks
Thread-safe.

◆ operator=() [1/2]

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

Move assignment.

Remarks
Not thread-safe.

◆ operator=() [2/2]

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

Copy assignment.

Remarks
Not thread-safe.

◆ reserve()

template<typename T , typename TMutex , typename TAllocator >
void gts::internal::TicketQueueMPMC< 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 >
TicketQueueMPMC< T, TMutex, TAllocator >::size_type gts::internal::TicketQueueMPMC< 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::TicketQueueMPMC< 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::TicketQueueMPMC< 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::TicketQueueMPMC< 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.