AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Impl::MPSCQueueNonIntrusive< T > Class Template Reference

#include "MPSCQueue.h"

Classes

struct  Node
 

Public Member Functions

 MPSCQueueNonIntrusive ()
 
 ~MPSCQueueNonIntrusive ()
 
void Enqueue (T *input)
 
bool Dequeue (T *&result)
 

Private Member Functions

 MPSCQueueNonIntrusive (MPSCQueueNonIntrusive const &)=delete
 
MPSCQueueNonIntrusiveoperator= (MPSCQueueNonIntrusive const &)=delete
 

Private Attributes

std::atomic< Node * > _head
 
std::atomic< Node * > _tail
 

Detailed Description

template<typename T>
class Acore::Impl::MPSCQueueNonIntrusive< T >

Constructor & Destructor Documentation

◆ MPSCQueueNonIntrusive() [1/2]

template<typename T >
Acore::Impl::MPSCQueueNonIntrusive< T >::MPSCQueueNonIntrusive ( )
inline
31 : _head(new Node()), _tail(_head.load(std::memory_order_relaxed))
32 {
33 Node* front = _head.load(std::memory_order_relaxed);
34 front->Next.store(nullptr, std::memory_order_relaxed);
35 }
std::atomic< Node * > _head
Definition: MPSCQueue.h:80
std::atomic< Node * > _tail
Definition: MPSCQueue.h:81

References Acore::Impl::MPSCQueueNonIntrusive< T >::_head, and Acore::Impl::MPSCQueueNonIntrusive< T >::Node::Next.

◆ ~MPSCQueueNonIntrusive()

template<typename T >
Acore::Impl::MPSCQueueNonIntrusive< T >::~MPSCQueueNonIntrusive ( )
inline
38 {
39 T* output;
40 while (Dequeue(output))
41 delete output;
42
43 Node* front = _head.load(std::memory_order_relaxed);
44 delete front;
45 }
bool Dequeue(T *&result)
Definition: MPSCQueue.h:54

References Acore::Impl::MPSCQueueNonIntrusive< T >::_head, and Acore::Impl::MPSCQueueNonIntrusive< T >::Dequeue().

◆ MPSCQueueNonIntrusive() [2/2]

template<typename T >
Acore::Impl::MPSCQueueNonIntrusive< T >::MPSCQueueNonIntrusive ( MPSCQueueNonIntrusive< T > const &  )
privatedelete

Member Function Documentation

◆ Dequeue()

template<typename T >
bool Acore::Impl::MPSCQueueNonIntrusive< T >::Dequeue ( T *&  result)
inline
55 {
56 Node* tail = _tail.load(std::memory_order_relaxed);
57 Node* next = tail->Next.load(std::memory_order_acquire);
58 if (!next)
59 return false;
60
61 result = next->Data;
62 _tail.store(next, std::memory_order_release);
63 delete tail;
64 return true;
65 }

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().

◆ Enqueue()

template<typename T >
void Acore::Impl::MPSCQueueNonIntrusive< T >::Enqueue ( T *  input)
inline
48 {
49 Node* node = new Node(input);
50 Node* prevHead = _head.exchange(node, std::memory_order_acq_rel);
51 prevHead->Next.store(node, std::memory_order_release);
52 }

References Acore::Impl::MPSCQueueNonIntrusive< T >::_head, and Acore::Impl::MPSCQueueNonIntrusive< T >::Node::Next.

◆ operator=()

template<typename T >
MPSCQueueNonIntrusive & Acore::Impl::MPSCQueueNonIntrusive< T >::operator= ( MPSCQueueNonIntrusive< T > const &  )
privatedelete

Member Data Documentation

◆ _head

◆ _tail

template<typename T >
std::atomic<Node*> Acore::Impl::MPSCQueueNonIntrusive< T >::_tail
private