![]() |
AzerothCore 3.3.5a
OpenSource WoW Emulator
|
C++ implementation of Dmitry Vyukov's lock-free MPSC queue (Intrusive). More...
#include "MPSCQueue.h"
Public Member Functions | |
MPSCQueueIntrusive () | |
Constructs a new MPSCQueueIntrusive object. | |
~MPSCQueueIntrusive () | |
Destroys the MPSCQueueIntrusive 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 | |
MPSCQueueIntrusive (MPSCQueueIntrusive const &)=delete | |
Deleted copy constructor. | |
MPSCQueueIntrusive & | operator= (MPSCQueueIntrusive const &)=delete |
Deleted copy assignment operator. | |
Private Attributes | |
std::aligned_storage_t< sizeof(T), alignof(T)> | _dummy |
Storage for the dummy object. | |
T * | _dummyPtr |
Pointer to the dummy object. | |
std::atomic< T * > | _head |
Atomic pointer to the head node of the queue. | |
std::atomic< T * > | _tail |
Atomic pointer to the tail node of the queue. | |
C++ implementation of Dmitry Vyukov's lock-free MPSC queue (Intrusive).
This queue allows multiple producers to enqueue items concurrently, but only one consumer can dequeue items. The queue is lock-free and intrusive, meaning that the enqueued objects must have an atomic link to the next item in the queue.
T | The type of data that is being enqueued in the queue. |
IntrusiveLink | A member pointer to the atomic link used for linking the nodes. |
|
inline |
Constructs a new MPSCQueueIntrusive object.
Initializes the queue with a dummy node and sets up atomic pointers to the head and tail. The dummy node's atomic link is initialized.
References Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::_dummyPtr.
|
inline |
Destroys the MPSCQueueIntrusive object.
Dequeues all items and deletes them.
References Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::Dequeue().
|
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::MPSCQueueIntrusive< T, IntrusiveLink >::_dummyPtr, Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::_head, Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::_tail, and Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::Enqueue().
Referenced by Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::~MPSCQueueIntrusive().
|
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::MPSCQueueIntrusive< T, IntrusiveLink >::_head.
Referenced by Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::Dequeue().
|
privatedelete |
Deleted copy assignment operator.
|
private |
Storage for the dummy object.
|
private |
Pointer to the dummy object.
Referenced by Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::Dequeue(), and Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::MPSCQueueIntrusive().
|
private |
Atomic pointer to the head node of the queue.
Referenced by Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::Dequeue(), and Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::Enqueue().
|
private |
Atomic pointer to the tail node of the queue.
Referenced by Acore::Impl::MPSCQueueIntrusive< T, IntrusiveLink >::Dequeue().