TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ProducerConsumerQueue< T > Class Template Reference

#include <ProducerConsumerQueue.h>

Public Member Functions

 ProducerConsumerQueue ()
 
void Push (const T &value)
 
bool Empty ()
 
bool Pop (T &value)
 
void WaitAndPop (T &value)
 
void Cancel ()
 

Private Member Functions

template<typename E = T>
std::enable_if
< std::is_pointer< E >::value >
::type 
DeleteQueuedObject (E &obj)
 
template<typename E = T>
std::enable_if
<!std::is_pointer< E >::value >
::type 
DeleteQueuedObject (E const &)
 

Private Attributes

std::mutex _queueLock
 
std::queue< T > _queue
 
std::condition_variable _condition
 
std::atomic< bool_shutdown
 

Constructor & Destructor Documentation

template<typename T>
ProducerConsumerQueue< T >::ProducerConsumerQueue ( )
inline
38 : _shutdown(false) { }
std::atomic< bool > _shutdown
Definition: ProducerConsumerQueue.h:34

Member Function Documentation

template<typename T>
void ProducerConsumerQueue< T >::Cancel ( )
inline
87  {
88  std::unique_lock<std::mutex> lock(_queueLock);
89 
90  while (!_queue.empty())
91  {
92  T& value = _queue.front();
93 
94  DeleteQueuedObject(value);
95 
96  _queue.pop();
97  }
98 
99  _shutdown = true;
100 
101  _condition.notify_all();
102  }
std::condition_variable _condition
Definition: ProducerConsumerQueue.h:33
std::mutex _queueLock
Definition: ProducerConsumerQueue.h:31
std::queue< T > _queue
Definition: ProducerConsumerQueue.h:32
std::enable_if< std::is_pointer< E >::value >::type DeleteQueuedObject(E &obj)
Definition: ProducerConsumerQueue.h:106
std::atomic< bool > _shutdown
Definition: ProducerConsumerQueue.h:34
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the caller graph for this function:

template<typename T>
template<typename E = T>
std::enable_if<std::is_pointer<E>::value>::type ProducerConsumerQueue< T >::DeleteQueuedObject ( E &  obj)
inlineprivate
106 { delete obj; }

+ Here is the caller graph for this function:

template<typename T>
template<typename E = T>
std::enable_if<!std::is_pointer<E>::value>::type ProducerConsumerQueue< T >::DeleteQueuedObject ( E const )
inlineprivate
109 { }
template<typename T>
bool ProducerConsumerQueue< T >::Empty ( )
inline
49  {
50  std::lock_guard<std::mutex> lock(_queueLock);
51 
52  return _queue.empty();
53  }
std::mutex _queueLock
Definition: ProducerConsumerQueue.h:31
std::queue< T > _queue
Definition: ProducerConsumerQueue.h:32

+ Here is the caller graph for this function:

template<typename T>
bool ProducerConsumerQueue< T >::Pop ( T &  value)
inline
56  {
57  std::lock_guard<std::mutex> lock(_queueLock);
58 
59  if (_queue.empty() || _shutdown)
60  return false;
61 
62  value = _queue.front();
63 
64  _queue.pop();
65 
66  return true;
67  }
std::mutex _queueLock
Definition: ProducerConsumerQueue.h:31
std::queue< T > _queue
Definition: ProducerConsumerQueue.h:32
std::atomic< bool > _shutdown
Definition: ProducerConsumerQueue.h:34
const FieldDescriptor value
Definition: descriptor.h:1522
template<typename T>
void ProducerConsumerQueue< T >::Push ( const T &  value)
inline
41  {
42  std::lock_guard<std::mutex> lock(_queueLock);
43  _queue.push(std::move(value));
44 
45  _condition.notify_one();
46  }
std::condition_variable _condition
Definition: ProducerConsumerQueue.h:33
std::mutex _queueLock
Definition: ProducerConsumerQueue.h:31
std::queue< T > _queue
Definition: ProducerConsumerQueue.h:32
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the caller graph for this function:

template<typename T>
void ProducerConsumerQueue< T >::WaitAndPop ( T &  value)
inline
70  {
71  std::unique_lock<std::mutex> lock(_queueLock);
72 
73  // we could be using .wait(lock, predicate) overload here but it is broken
74  // https://connect.microsoft.com/VisualStudio/feedback/details/1098841
75  while (_queue.empty() && !_shutdown)
76  _condition.wait(lock);
77 
78  if (_queue.empty() || _shutdown)
79  return;
80 
81  value = _queue.front();
82 
83  _queue.pop();
84  }
std::condition_variable _condition
Definition: ProducerConsumerQueue.h:33
std::mutex _queueLock
Definition: ProducerConsumerQueue.h:31
std::queue< T > _queue
Definition: ProducerConsumerQueue.h:32
std::atomic< bool > _shutdown
Definition: ProducerConsumerQueue.h:34
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the caller graph for this function:

Member Data Documentation

template<typename T>
std::condition_variable ProducerConsumerQueue< T >::_condition
private
template<typename T>
std::queue<T> ProducerConsumerQueue< T >::_queue
private
template<typename T>
std::mutex ProducerConsumerQueue< T >::_queueLock
private
template<typename T>
std::atomic<bool> ProducerConsumerQueue< T >::_shutdown
private

The documentation for this class was generated from the following file: