1 #ifndef theplu_yat_utility_priority_queue
2 #define theplu_yat_utility_priority_queue
21 #include "yat_assert.h"
23 #include <boost/thread.hpp>
53 template<
typename T,
class Compare = std::less<T> >
63 typedef typename std::set<T, Compare>::size_type
size_type;
87 boost::unique_lock<boost::mutex> lock(mutex_);
101 boost::unique_lock<boost::mutex> lock(mutex_);
103 condition_.wait(lock);
113 boost::unique_lock<boost::mutex> lock(mutex_);
118 condition_.notify_one();
127 boost::unique_lock<boost::mutex> lock(mutex_);
138 boost::unique_lock<boost::mutex> lock(mutex_);
153 boost::unique_lock<boost::mutex> lock(mutex_);
161 std::set<T, Compare> q_;
162 mutable boost::mutex mutex_;
163 boost::condition_variable condition_;
165 void pop(T& value,
const boost::unique_lock<boost::mutex>& lock)
172 typename std::set<T, Compare>::iterator it = q_.end();
173 YAT_ASSERT(q_.size());
180 const std::set<T, Compare>& q(
void)
const
182 boost::unique_lock<boost::mutex> lock(mutex_);
PriorityQueue(const PriorityQueue &other)
Copy constructor.
Definition: PriorityQueue.h:80
T value_type
Type of object stored in Queue.
Definition: PriorityQueue.h:58
Multi-thread safe priority queue.
Definition: PriorityQueue.h:54
PriorityQueue(void)
Create a PriorityQueue with no elements.
Definition: PriorityQueue.h:68
size_type size(void) const
Definition: PriorityQueue.h:125
bool try_pop(T &value)
Definition: PriorityQueue.h:136
bool empty(void) const
Definition: PriorityQueue.h:85
PriorityQueue & operator=(const PriorityQueue &lhs)
assignment operator
Definition: PriorityQueue.h:151
std::set< T, Compare >::size_type size_type
Definition: PriorityQueue.h:63
PriorityQueue(const Compare &comp)
Create a PriorityQueue with comp as Compare functor.
Definition: PriorityQueue.h:73
void push(const T &t)
insert an element into container
Definition: PriorityQueue.h:111
void pop(T &value)
access next element is queue
Definition: PriorityQueue.h:99