proxygen
BaselinePQ< T, PriorityQueue, Mutex > Class Template Reference

Public Member Functions

template<typename... PQArgs, typename = decltype(PriorityQueue(std::declval<PQArgs>()...))>
 BaselinePQ (size_t maxSize=0, PQArgs...args)
 
bool empty () const
 
size_t size () const
 
bool try_push (const T &val)
 
bool try_pop (T &val)
 
bool try_peek (T &val)
 

Private Attributes

Mutex m_
 
size_t maxSize_
 
PriorityQueue pq_
 
std::condition_variable notempty_
 
std::condition_variable notfull_
 

Detailed Description

template<typename T, typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
class BaselinePQ< T, PriorityQueue, Mutex >

Baseline implementation represents a conventional single-lock implementation that supports cond var blocking.

Definition at line 46 of file FlatCombiningPriorityQueueTest.cpp.

Constructor & Destructor Documentation

template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
template<typename... PQArgs, typename = decltype(PriorityQueue(std::declval<PQArgs>()...))>
BaselinePQ< T, PriorityQueue, Mutex >::BaselinePQ ( size_t  maxSize = 0,
PQArgs...  args 
)
inlineexplicit

Definition at line 51 of file FlatCombiningPriorityQueueTest.cpp.

52  : maxSize_(maxSize), pq_(std::forward<PQArgs>(args)...) {}

Member Function Documentation

template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
bool BaselinePQ< T, PriorityQueue, Mutex >::empty ( ) const
inline

Definition at line 54 of file FlatCombiningPriorityQueueTest.cpp.

References g(), BaselinePQ< T, PriorityQueue, Mutex >::m_, and BaselinePQ< T, PriorityQueue, Mutex >::pq_.

54  {
55  std::lock_guard<Mutex> g(m_);
56  return pq_.empty();
57  }
g_t g(f_t)
template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
size_t BaselinePQ< T, PriorityQueue, Mutex >::size ( ) const
inline

Definition at line 59 of file FlatCombiningPriorityQueueTest.cpp.

References g(), BaselinePQ< T, PriorityQueue, Mutex >::m_, and BaselinePQ< T, PriorityQueue, Mutex >::pq_.

Referenced by run_once().

59  {
60  std::lock_guard<Mutex> g(m_);
61  return pq_.size();
62  }
g_t g(f_t)
template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
bool BaselinePQ< T, PriorityQueue, Mutex >::try_peek ( T val)
inline

Definition at line 90 of file FlatCombiningPriorityQueueTest.cpp.

References g(), BaselinePQ< T, PriorityQueue, Mutex >::m_, and BaselinePQ< T, PriorityQueue, Mutex >::pq_.

90  {
91  std::lock_guard<Mutex> g(m_);
92  if (!pq_.empty()) {
93  val = pq_.top();
94  return true;
95  }
96  return false;
97  }
double val
Definition: String.cpp:273
g_t g(f_t)
template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
bool BaselinePQ< T, PriorityQueue, Mutex >::try_pop ( T val)
inline

Definition at line 79 of file FlatCombiningPriorityQueueTest.cpp.

References g(), BaselinePQ< T, PriorityQueue, Mutex >::m_, BaselinePQ< T, PriorityQueue, Mutex >::notfull_, and BaselinePQ< T, PriorityQueue, Mutex >::pq_.

Referenced by test().

79  {
80  std::lock_guard<Mutex> g(m_);
81  if (!pq_.empty()) {
82  val = pq_.top();
83  pq_.pop();
84  notfull_.notify_one();
85  return true;
86  }
87  return false;
88  }
double val
Definition: String.cpp:273
std::condition_variable notfull_
g_t g(f_t)
template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
bool BaselinePQ< T, PriorityQueue, Mutex >::try_push ( const T val)
inline

Definition at line 64 of file FlatCombiningPriorityQueueTest.cpp.

References g(), BaselinePQ< T, PriorityQueue, Mutex >::m_, BaselinePQ< T, PriorityQueue, Mutex >::maxSize_, BaselinePQ< T, PriorityQueue, Mutex >::notempty_, and BaselinePQ< T, PriorityQueue, Mutex >::pq_.

Referenced by test().

64  {
65  std::lock_guard<Mutex> g(m_);
66  if (maxSize_ > 0 && pq_.size() == maxSize_) {
67  return false;
68  }
69  DCHECK(maxSize_ == 0 || pq_.size() < maxSize_);
70  try {
71  pq_.push(val);
72  notempty_.notify_one();
73  return true;
74  } catch (const std::bad_alloc&) {
75  return false;
76  }
77  }
double val
Definition: String.cpp:273
std::condition_variable notempty_
g_t g(f_t)

Member Data Documentation

template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
size_t BaselinePQ< T, PriorityQueue, Mutex >::maxSize_
private
template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
std::condition_variable BaselinePQ< T, PriorityQueue, Mutex >::notempty_
private
template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
std::condition_variable BaselinePQ< T, PriorityQueue, Mutex >::notfull_
private
template<typename T , typename PriorityQueue = std::priority_queue<T>, typename Mutex = std::mutex>
PriorityQueue BaselinePQ< T, PriorityQueue, Mutex >::pq_
private

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