Navigation
API > API/Runtime > API/Runtime/Core
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.
| Name | TTransactionallySafeSpscQueue |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Containers/TransactionallySafeSpscQueue.h |
| Include Path | #include "Containers/TransactionallySafeSpscQueue.h" |
Syntax
template<typename T, typename AllocatorType>
class TTransactionallySafeSpscQueue
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Containers/TransactionallySafeSpscQueue.h | |||
| Containers/TransactionallySafeSpscQueue.h | |||
| Containers/TransactionallySafeSpscQueue.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
~TTransactionallySafeSpscQueue() |
Containers/TransactionallySafeSpscQueue.h |
Structs
| Name | Remarks |
|---|---|
| FNode |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| ElementType | T | Containers/TransactionallySafeSpscQueue.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| First | FNode * | Containers/TransactionallySafeSpscQueue.h | ||
| Head | FNode * | Producer part accessed only by producer | Containers/TransactionallySafeSpscQueue.h | |
| Mutex | UE::FTransactionallySafeMutex | This mutex guards all accesses to this structure or to FNode::Next. | Containers/TransactionallySafeSpscQueue.h | |
| Tail | FNode * | Consumer part accessed mainly by consumer, infrequently by producer | Containers/TransactionallySafeSpscQueue.h | |
| TailCopy | FNode * | Containers/TransactionallySafeSpscQueue.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Returns NullOpt if the queue is empty. | Containers/TransactionallySafeSpscQueue.h | ||
bool Dequeue
(
ElementType& OutElem |
Containers/TransactionallySafeSpscQueue.h | ||
void Enqueue
(
ArgTypes&&... Args |
Containers/TransactionallySafeSpscQueue.h | ||
bool IsEmpty() |
Containers/TransactionallySafeSpscQueue.h | ||
ElementType * Peek () |
As there can be only one consumer, a consumer can safely "peek" the tail of the queue. | Containers/TransactionallySafeSpscQueue.h |
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Containers/TransactionallySafeSpscQueue.h | |||
| Containers/TransactionallySafeSpscQueue.h |