UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TTransactionallySafeSpscQueue< T, AllocatorType > Class Template Referencefinal

#include <TransactionallySafeSpscQueue.h>

Public Types

using ElementType = T
 

Public Member Functions

 UE_NONCOPYABLE (TTransactionallySafeSpscQueue)
 
 TTransactionallySafeSpscQueue ()
 
 ~TTransactionallySafeSpscQueue ()
 
template<typename... ArgTypes>
void Enqueue (ArgTypes &&... Args)
 
TOptional< ElementTypeDequeue ()
 
bool Dequeue (ElementType &OutElem)
 
bool IsEmpty () const
 
ElementTypePeek () const
 

Detailed Description

template<typename T, typename AllocatorType = FMemory>
class TTransactionallySafeSpscQueue< T, AllocatorType >

Fast, transactionally-safe single-producer/single-consumer unbounded concurrent queue. Doesn't free memory until destruction but recycles consumed items. Based on TSpscQueue, which is itself based on http://www.1024cores.net/home/lock-free-algorithms/queues/unbounded-spsc-queue

The transactionally-safe queue uses a mutex to enforce thread safety instead of atomic operations. The difference in performance compared to a TSpscQueue should be negligible unless you are CPU-bound on constantly enqueueing and dequeueing objects as fast as possible.

It is not safe to spin-wait on Dequeue from within an AutoRTFM transaction! The other thread's Enqueue will be blocked on the mutex, so you will deadlock inside the spin-wait. This class works best with the game thread as the producer, and a separate helper thread as the consumer.

Member Typedef Documentation

◆ ElementType

template<typename T , typename AllocatorType = FMemory>
using TTransactionallySafeSpscQueue< T, AllocatorType >::ElementType = T

Constructor & Destructor Documentation

◆ TTransactionallySafeSpscQueue()

template<typename T , typename AllocatorType = FMemory>
TTransactionallySafeSpscQueue< T, AllocatorType >::TTransactionallySafeSpscQueue ( )
inline

◆ ~TTransactionallySafeSpscQueue()

template<typename T , typename AllocatorType = FMemory>
TTransactionallySafeSpscQueue< T, AllocatorType >::~TTransactionallySafeSpscQueue ( )
inline

Member Function Documentation

◆ Dequeue() [1/2]

template<typename T , typename AllocatorType = FMemory>
TOptional< ElementType > TTransactionallySafeSpscQueue< T, AllocatorType >::Dequeue ( )
inline

◆ Dequeue() [2/2]

template<typename T , typename AllocatorType = FMemory>
bool TTransactionallySafeSpscQueue< T, AllocatorType >::Dequeue ( ElementType OutElem)
inline

◆ Enqueue()

template<typename T , typename AllocatorType = FMemory>
template<typename... ArgTypes>
void TTransactionallySafeSpscQueue< T, AllocatorType >::Enqueue ( ArgTypes &&...  Args)
inline

◆ IsEmpty()

template<typename T , typename AllocatorType = FMemory>
bool TTransactionallySafeSpscQueue< T, AllocatorType >::IsEmpty ( ) const
inline

◆ Peek()

template<typename T , typename AllocatorType = FMemory>
ElementType * TTransactionallySafeSpscQueue< T, AllocatorType >::Peek ( ) const
inline

◆ UE_NONCOPYABLE()

template<typename T , typename AllocatorType = FMemory>
TTransactionallySafeSpscQueue< T, AllocatorType >::UE_NONCOPYABLE ( TTransactionallySafeSpscQueue< T, AllocatorType >  )

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