UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TQueue< T, Mode > Class Template Reference

#include <Queue.h>

Public Types

using FElementType = T
 

Public Member Functions

 TQueue ()
 
 ~TQueue ()
 
 UE_NONCOPYABLE (TQueue)
 
bool Dequeue (FElementType &OutItem)
 
void Empty ()
 
bool Enqueue (const FElementType &Item)
 
bool Enqueue (FElementType &&Item)
 
bool IsEmpty () const
 
bool Peek (FElementType &OutItem) const
 
FElementTypePeek ()
 
UE_FORCEINLINE_HINT const FElementTypePeek () const
 
bool Pop ()
 

Detailed Description

template<typename T, EQueueMode Mode = EQueueMode::Spsc>
class TQueue< T, Mode >

Template for queues.

This template implements an unbounded non-intrusive queue using a lock-free linked list that stores copies of the queued items. The template can operate in three modes: Multiple-producers single-consumer (MPSC), Single-producer single-consumer (SPSC), and Single-threaded.

The queue is thread-safe in both MPSC and SPSC modes. The Dequeue() method ensures thread-safety by writing it in a way that does not depend on possible instruction reordering on the CPU. The Enqueue() method uses an atomic compare-and-swap in multiple-producers scenarios.

The queue is not thread-safe in single-threaded mode, as the name suggests.

Parameters
TThe type of items stored in the queue.
ModeThe queue mode (single-producer, single-consumer by default).

Member Typedef Documentation

◆ FElementType

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
using TQueue< T, Mode >::FElementType = T

Constructor & Destructor Documentation

◆ TQueue()

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
TQueue< T, Mode >::TQueue ( )
inline

Default constructor.

◆ ~TQueue()

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
TQueue< T, Mode >::~TQueue ( )
inline

Destructor.

Member Function Documentation

◆ Dequeue()

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
bool TQueue< T, Mode >::Dequeue ( FElementType OutItem)
inline

Removes and returns the item from the tail of the queue.

Parameters
OutValueWill hold the returned value.
Returns
true if a value was returned, false if the queue was empty.
Note
To be called only from consumer thread.
See also
Empty, Enqueue, IsEmpty, Peek, Pop

◆ Empty()

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
void TQueue< T, Mode >::Empty ( )
inline

Empty the queue, discarding all items.

Note
To be called only from consumer thread.
See also
Dequeue, IsEmpty, Peek, Pop

◆ Enqueue() [1/2]

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
bool TQueue< T, Mode >::Enqueue ( const FElementType Item)
inline

Adds an item to the head of the queue.

Parameters
ItemThe item to add.
Returns
true if the item was added, false otherwise.
Note
To be called only from producer thread(s).
See also
Dequeue, Pop

◆ Enqueue() [2/2]

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
bool TQueue< T, Mode >::Enqueue ( FElementType &&  Item)
inline

Adds an item to the head of the queue.

Parameters
ItemThe item to add.
Returns
true if the item was added, false otherwise.
Note
To be called only from producer thread(s).
See also
Dequeue, Pop

◆ IsEmpty()

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
bool TQueue< T, Mode >::IsEmpty ( ) const
inline

Checks whether the queue is empty.

Returns
true if the queue is empty, false otherwise.
Note
To be called only from consumer thread.
See also
Dequeue, Empty, Peek, Pop

◆ Peek() [1/3]

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
FElementType * TQueue< T, Mode >::Peek ( )
inline

Peek at the queue's tail item without removing it.

This version of Peek allows peeking at a queue of items that do not allow copying, such as TUniquePtr.

Returns
Pointer to the item, or nullptr if queue is empty

◆ Peek() [2/3]

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
UE_FORCEINLINE_HINT const FElementType * TQueue< T, Mode >::Peek ( ) const
inline

◆ Peek() [3/3]

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
bool TQueue< T, Mode >::Peek ( FElementType OutItem) const
inline

Peeks at the queue's tail item without removing it.

Parameters
OutItemWill hold the peeked at item.
Returns
true if an item was returned, false if the queue was empty.
Note
To be called only from consumer thread.
See also
Dequeue, Empty, IsEmpty, Pop

◆ Pop()

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
bool TQueue< T, Mode >::Pop ( )
inline

Removes the item from the tail of the queue.

Returns
true if a value was removed, false if the queue was empty.
Note
To be called only from consumer thread.
See also
Dequeue, Empty, Enqueue, IsEmpty, Peek

◆ UE_NONCOPYABLE()

template<typename T , EQueueMode Mode = EQueueMode::Spsc>
TQueue< T, Mode >::UE_NONCOPYABLE ( TQueue< T, Mode >  )

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