Navigation
API > API/Runtime > API/Runtime/Core
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 two modes: Multiple-producers single-consumer (MPSC) and Single-producer single-consumer (SPSC).
The queue is thread-safe in both 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.
| Name | TQueue |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Containers/Queue.h |
| Include Path | #include "Containers/Queue.h" |
Syntax
template<typename T, EQueueMode Mode>
class TQueue
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TQueue () |
Default constructor. | Containers/Queue.h | |
| Containers/Queue.h | |||
| Containers/Queue.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TQueue() |
Destructor. | Containers/Queue.h |
Structs
| Name | Remarks |
|---|---|
| TNode |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| FElementType | T | Containers/Queue.h | |
| TNodeVolatilePtr | std::conditional_t< Mode==EQueueMode::SingleThreaded, TNode *, TNode *volatile > | Containers/Queue.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Head | TNodeVolatilePtr | Holds a pointer to the head of the list. | Containers/Queue.h | |
| Tail | TNode * | Holds a pointer to the tail of the list. | Containers/Queue.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
bool Dequeue
(
FElementType& OutItem |
Removes and returns the item from the tail of the queue.To be called only from consumer thread. | Containers/Queue.h | |
void Empty () |
Empty the queue, discarding all items.To be called only from consumer thread. | Containers/Queue.h | |
bool Enqueue
(
const FElementType& Item |
Adds an item to the head of the queue.To be called only from producer thread(s). | Containers/Queue.h | |
bool Enqueue
(
FElementType&& Item |
Adds an item to the head of the queue.To be called only from producer thread(s). | Containers/Queue.h | |
bool IsEmpty () |
Checks whether the queue is empty.To be called only from consumer thread. | Containers/Queue.h | |
FElementType * Peek () |
Peek at the queue's tail item without removing it. | Containers/Queue.h | |
const FElementType * Peek () |
Containers/Queue.h | ||
bool Peek
(
FElementType& OutItem |
Peeks at the queue's tail item without removing it.To be called only from consumer thread. | Containers/Queue.h | |
bool Pop () |
Removes the item from the tail of the queue.To be called only from consumer thread. | Containers/Queue.h |