ewmscp  ..
Public Member Functions | Private Attributes | List of all members
waitQueues::ordered< T, ascending, Container > Class Template Reference

#include <waitQueues.h>

Collaboration diagram for waitQueues::ordered< T, ascending, Container >:
[legend]

Public Member Functions

void enqueue (std::unique_ptr< T > &item)
 
template<class ... Types>
void emplace (Types ... args)
 
void signalDone ()
 
void resetDone ()
 
template<typename durationType >
std::unique_ptr< T > dequeue (durationType timeout, bool &timedOut)
 
std::unique_ptr< T > dequeue ()
 
template<typename iterType >
void signalDone (iterType begin, iterType end)
 
template<typename iterType >
std::thread signalDoneThread (iterType begin, iterType end)
 
decltype(queue.size()) size () const
 
decltype(queue.empty()) empty () const
 

Private Attributes

Container queue
 
std::mutex queue_mutex
 
std::condition_variable cv
 

Detailed Description

template<typename T, bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
class waitQueues::ordered< T, ascending, Container >

Definition at line 133 of file waitQueues.h.

Member Function Documentation

◆ dequeue() [1/2]

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
std::unique_ptr<T> waitQueues::ordered< T, ascending, Container >::dequeue ( )
inline

Definition at line 178 of file waitQueues.h.

178  {
179  std::unique_lock<decltype(queue_mutex)> lock(queue_mutex); //(NOLINT clang-analyzer-alpha.core.CastToStruct)
180  while (queue.empty()) {
181  cv.wait(lock);//(NOLINT clang-analyzer-alpha.core.CastToStruct)
182  }
183  auto it = queue.begin();
184  auto item = *it;
185  if (item != nullptr) { // nullptrs are end markers, multiple readers need many of them...
186  queue.erase(it);
187  }
188  return std::unique_ptr<T>(item);
189  }

References waitQueues::ordered< T, ascending, Container >::cv, waitQueues::ordered< T, ascending, Container >::queue, and waitQueues::ordered< T, ascending, Container >::queue_mutex.

◆ dequeue() [2/2]

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
template<typename durationType >
std::unique_ptr<T> waitQueues::ordered< T, ascending, Container >::dequeue ( durationType  timeout,
bool &  timedOut 
)
inline

Definition at line 162 of file waitQueues.h.

162  {
163  std::unique_lock<decltype(queue_mutex)> lock(queue_mutex);
164  while (queue.empty()) {
165  if (cv.wait_for(lock, timeout) == std::cv_status::timeout) {
166  timedOut = true;
167  return nullptr;
168  }
169  }
170  auto it = queue.begin();
171  auto item = *it;
172  if (item != nullptr) { // nullptrs are end markers, multiple readers need many of them...
173  queue.erase(it);
174  }
175  return std::unique_ptr<T>(item);
176  }

References waitQueues::ordered< T, ascending, Container >::cv, waitQueues::ordered< T, ascending, Container >::queue, and waitQueues::ordered< T, ascending, Container >::queue_mutex.

Referenced by o2s().

Here is the caller graph for this function:

◆ emplace()

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
template<class ... Types>
void waitQueues::ordered< T, ascending, Container >::emplace ( Types ...  args)
inline

Definition at line 148 of file waitQueues.h.

148  {
149  std::unique_ptr<T> item(new T(args...));
150  enqueue(item);
151  }

References waitQueues::ordered< T, ascending, Container >::enqueue().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
decltype(queue.empty()) waitQueues::ordered< T, ascending, Container >::empty ( ) const
inline

Definition at line 204 of file waitQueues.h.

204  {
205  return queue.empty();
206  }

References waitQueues::ordered< T, ascending, Container >::queue.

◆ enqueue()

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
void waitQueues::ordered< T, ascending, Container >::enqueue ( std::unique_ptr< T > &  item)
inline

Definition at line 139 of file waitQueues.h.

139  {
140  std::unique_lock<decltype(queue_mutex)> lock(queue_mutex); //(NOLINT clang-analyzer-alpha.core.CastToStruct)
141  if (!queue.empty() && *(queue.crbegin()) == nullptr) {
142  throw std::logic_error("after adding a nullptr no further stuff may be added to a wait queue");
143  }
144  queue.emplace(item.get());
145  item.release();
146  cv.notify_all();
147  }

References waitQueues::ordered< T, ascending, Container >::cv, waitQueues::ordered< T, ascending, Container >::queue, and waitQueues::ordered< T, ascending, Container >::queue_mutex.

Referenced by waitQueues::ordered< T, ascending, Container >::emplace(), main(), and waitQueues::ordered< T, ascending, Container >::signalDone().

Here is the caller graph for this function:

◆ resetDone()

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
void waitQueues::ordered< T, ascending, Container >::resetDone ( )
inline

Definition at line 156 of file waitQueues.h.

156  {
157  std::unique_lock<decltype(queue_mutex)> lock(queue_mutex); //(NOLINT clang-analyzer-alpha.core.CastToStruct)
158  while (!queue.empty() && *(queue.crbegin()) == nullptr) {
159  queue.erase(queue.rbegin());
160  }
161  }

References waitQueues::ordered< T, ascending, Container >::queue, and waitQueues::ordered< T, ascending, Container >::queue_mutex.

◆ signalDone() [1/2]

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
void waitQueues::ordered< T, ascending, Container >::signalDone ( )
inline

Definition at line 152 of file waitQueues.h.

152  {
153  std::unique_ptr<T> end(nullptr);
154  enqueue(end);
155  }

References waitQueues::ordered< T, ascending, Container >::enqueue().

Here is the call graph for this function:

◆ signalDone() [2/2]

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
template<typename iterType >
void waitQueues::ordered< T, ascending, Container >::signalDone ( iterType  begin,
iterType  end 
)
inline

Definition at line 190 of file waitQueues.h.

191  {
192  for (auto it = begin; it != end; ++it) {
193  it->join();
194  }
195  enqueue(nullptr);
196  }

References waitQueues::ordered< T, ascending, Container >::enqueue().

Here is the call graph for this function:

◆ signalDoneThread()

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
template<typename iterType >
std::thread waitQueues::ordered< T, ascending, Container >::signalDoneThread ( iterType  begin,
iterType  end 
)
inline

Definition at line 197 of file waitQueues.h.

198  {
199  return std::thread(&ordered::signalDone<iterType>, this, begin, end);
200  }

◆ size()

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
decltype(queue.size()) waitQueues::ordered< T, ascending, Container >::size ( ) const
inline

Definition at line 201 of file waitQueues.h.

201  {
202  return queue.size();
203  }

References waitQueues::ordered< T, ascending, Container >::queue.

Member Data Documentation

◆ cv

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
std::condition_variable waitQueues::ordered< T, ascending, Container >::cv
private

◆ queue

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
Container waitQueues::ordered< T, ascending, Container >::queue
private

◆ queue_mutex

template<typename T , bool ascending = true, typename Container = std::multiset<T*, itemComparator<T, ascending>>>
std::mutex waitQueues::ordered< T, ascending, Container >::queue_mutex
private

The documentation for this class was generated from the following file:
waitQueues::ordered::queue_mutex
std::mutex queue_mutex
Definition: waitQueues.h:136
waitQueues::ordered::enqueue
void enqueue(std::unique_ptr< T > &item)
Definition: waitQueues.h:139
waitQueues::ordered::cv
std::condition_variable cv
Definition: waitQueues.h:137
waitQueues::ordered::queue
Container queue
Definition: waitQueues.h:135