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

#include <CircularQueue.h>

Public Types

using FElementType = T
 

Public Member Functions

 TCircularQueue (uint32 CapacityPlusOne)
 
uint32 Count () const
 
bool Dequeue (FElementType &OutElement)
 
bool Dequeue ()
 
void Empty ()
 
bool Enqueue (const FElementType &Element)
 
bool Enqueue (FElementType &&Element)
 
UE_FORCEINLINE_HINT bool IsEmpty () const
 
bool IsFull () const
 
bool Peek (FElementType &OutItem) const
 
const FElementTypePeek () const
 

Detailed Description

template<typename T>
class TCircularQueue< T >

Implements a lock-free first-in first-out queue using a circular array.

This class is thread safe only in single-producer single-consumer scenarios.

The number of items that can be enqueued is one less than the queue's capacity, because one item will be used for detecting full and empty states.

There is some room for optimization via using fine grained memory fences, but the implications for all of our target platforms need further analysis, so we're using the simpler sequentially consistent model for now.

Parameters
TThe type of elements held in the queue.

Member Typedef Documentation

◆ FElementType

template<typename T >
using TCircularQueue< T >::FElementType = T

Constructor & Destructor Documentation

◆ TCircularQueue()

template<typename T >
TCircularQueue< T >::TCircularQueue ( uint32  CapacityPlusOne)
inlineexplicit

Constructor.

Parameters
CapacityPlusOneThe number of elements that the queue can hold (will be rounded up to the next power of 2).

Member Function Documentation

◆ Count()

template<typename T >
uint32 TCircularQueue< T >::Count ( ) const
inline

Gets the number of elements in the queue.

Can be called from any thread. The result reflects the calling thread's current view. Since no locking is used, different threads may return different results.

Returns
Number of queued elements.

◆ Dequeue() [1/2]

template<typename T >
bool TCircularQueue< T >::Dequeue ( )
inline

Removes an item from the front of the queue.

Returns
true if an element has been removed, false if the queue was empty.
Note
To be called only from consumer thread.

◆ Dequeue() [2/2]

template<typename T >
bool TCircularQueue< T >::Dequeue ( FElementType OutElement)
inline

Removes an item from the front of the queue.

Parameters
OutElementWill contain the element if the queue is not empty.
Returns
true if an element has been returned, false if the queue was empty.
Note
To be called only from consumer thread.

◆ Empty()

template<typename T >
void TCircularQueue< T >::Empty ( )
inline

Empties the queue.

Note
To be called only from consumer thread.
See also
IsEmpty

◆ Enqueue() [1/2]

template<typename T >
bool TCircularQueue< T >::Enqueue ( const FElementType Element)
inline

Adds an item to the end of the queue.

Parameters
ElementThe element to add.
Returns
true if the item was added, false if the queue was full.
Note
To be called only from producer thread.

◆ Enqueue() [2/2]

template<typename T >
bool TCircularQueue< T >::Enqueue ( FElementType &&  Element)
inline

Adds an item to the end of the queue.

Parameters
ElementThe element to add.
Returns
true if the item was added, false if the queue was full.
Note
To be called only from producer thread.

◆ IsEmpty()

template<typename T >
UE_FORCEINLINE_HINT bool TCircularQueue< T >::IsEmpty ( ) const
inline

Checks whether the queue is empty.

Can be called from any thread. The result reflects the calling thread's current view. Since no locking is used, different threads may return different results.

Returns
true if the queue is empty, false otherwise.
See also
Empty, IsFull

◆ IsFull()

template<typename T >
bool TCircularQueue< T >::IsFull ( ) const
inline

Checks whether the queue is full.

Can be called from any thread. The result reflects the calling thread's current view. Since no locking is used, different threads may return different results.

Returns
true if the queue is full, false otherwise.
See also
IsEmpty

◆ Peek() [1/2]

template<typename T >
const FElementType * TCircularQueue< T >::Peek ( ) const
inline

Returns the oldest item in the queue without removing it.

Returns
an FElementType pointer if an item has been returned, nullptr if the queue was empty.
Note
To be called only from consumer thread.
The return value is only valid until Dequeue, Empty, or the destructor has been called.

◆ Peek() [2/2]

template<typename T >
bool TCircularQueue< T >::Peek ( FElementType OutItem) const
inline

Returns the oldest item in the queue without removing it.

Parameters
OutItemWill contain the item if the queue is not empty.
Returns
true if an item has been returned, false if the queue was empty.
Note
To be called only from consumer thread.

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