![]() |
AzerothCore 3.3.5a
OpenSource WoW Emulator
|
C++ implementation of Dmitry Vyukov's lock-free MPSC queue (Non-Intrusive). More...
#include "MPSCQueue.h"
Classes | |
struct | Node |
A structure representing a node in the queue. More... | |
Public Member Functions | |
MPSCQueueNonIntrusive () | |
Constructs a new MPSCQueueNonIntrusive object. | |
~MPSCQueueNonIntrusive () | |
Destroys the MPSCQueueNonIntrusive object. | |
void | Enqueue (T *input) |
Enqueues a new item in the queue. | |
bool | Dequeue (T *&result) |
Dequeues an item from the queue. | |
Private Member Functions | |
MPSCQueueNonIntrusive (MPSCQueueNonIntrusive const &)=delete | |
Deleted copy constructor. | |
MPSCQueueNonIntrusive & | operator= (MPSCQueueNonIntrusive const &)=delete |
Deleted copy assignment operator. | |
Private Attributes | |
std::atomic< Node * > | _head |
Atomic pointer to the head node of the queue. | |
std::atomic< Node * > | _tail |
Atomic pointer to the tail node of the queue. | |
C++ implementation of Dmitry Vyukov's lock-free MPSC queue (Non-Intrusive).
This queue allows multiple producers to enqueue items concurrently, but only one consumer can dequeue items. The queue is lock-free and non-intrusive, meaning it does not modify the data types that are enqueued.
T | The type of data that is being enqueued in the queue. |
|
inline |
Constructs a new MPSCQueueNonIntrusive object.
Initializes the queue with a dummy node and sets up atomic pointers to the head and tail.
< Store with release to ensure visibility
References Acore::Impl::MPSCQueueNonIntrusive< T >::_head, and Acore::Impl::MPSCQueueNonIntrusive< T >::Node::Next.
|
inline |
Destroys the MPSCQueueNonIntrusive object.
Dequeues all items and deletes them, followed by proper cleanup of remaining nodes in the queue.
References Acore::Impl::MPSCQueueNonIntrusive< T >::_head, Acore::Impl::MPSCQueueNonIntrusive< T >::Dequeue(), and Acore::Impl::MPSCQueueNonIntrusive< T >::Node::Next.
|
privatedelete |
Deleted copy constructor.
|
inline |
Dequeues an item from the queue.
This function removes the item at the front of the queue and returns it.
result | Reference to a pointer where the dequeued item will be stored. |
References Acore::Impl::MPSCQueueNonIntrusive< T >::_tail, Acore::Impl::MPSCQueueNonIntrusive< T >::Node::Data, and Acore::Impl::MPSCQueueNonIntrusive< T >::Node::Next.
Referenced by Acore::Impl::MPSCQueueNonIntrusive< T >::~MPSCQueueNonIntrusive().
|
inline |
Enqueues a new item in the queue.
This function adds a new item at the head of the queue.
input | Pointer to the item to be enqueued. |
< Exchange with acquire-release semantics
References Acore::Impl::MPSCQueueNonIntrusive< T >::_head, and Acore::Impl::MPSCQueueNonIntrusive< T >::Node::Next.
|
privatedelete |
Deleted copy assignment operator.
|
private |
Atomic pointer to the head node of the queue.
Referenced by Acore::Impl::MPSCQueueNonIntrusive< T >::Enqueue(), Acore::Impl::MPSCQueueNonIntrusive< T >::MPSCQueueNonIntrusive(), and Acore::Impl::MPSCQueueNonIntrusive< T >::~MPSCQueueNonIntrusive().
|
private |
Atomic pointer to the tail node of the queue.
Referenced by Acore::Impl::MPSCQueueNonIntrusive< T >::Dequeue().