TCircularQueue

Syntax

template<typename ElementType>
class TCircularQueue

Remarks

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.

Constructors

Name Description

Public function

TCircularQueue

(
    uint32 CapacityPlusOne
)

Default constructor.

Functions

Name Description

Public function Const

uint32

 

Count()

Gets the number of elements in the queue.

Public function

bool

 

Dequeue

(
    ElementType& OutElement
)

Removes an item from the front of the queue.

To be called only from consumer thread.

Public function

void

 

Empty()

Empties the queue.

To be called only from consumer thread.

Public function

bool

 

Enqueue

(
    const ElementType& Element
)

Adds an item to the end of the queue.

To be called only from producer thread.

Public function

bool

 

Enqueue

(
    ElementType&& Element
)

Adds an item to the end of the queue.

To be called only from producer thread.

Public function Const

bool

 

IsEmpty()

Checks whether the queue is empty.

Public function Const

bool

 

IsFull()

Checks whether the queue is full.

Public function

bool

 

Peek

(
    ElementType& OutItem
)

Returns the oldest item in the queue without removing it.

References

Module

Core

Header

Runtime/Core/Public/Containers/CircularQueue.h