modfied queue
This commit is contained in:
@@ -25,7 +25,7 @@ template<typename T>
|
|||||||
class BlockingQueue : public IBlockingQueue<T>
|
class BlockingQueue : public IBlockingQueue<T>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::mutex d_mutex;
|
std::mutex write_mutex, read_mutex;
|
||||||
std::condition_variable d_condition;
|
std::condition_variable d_condition;
|
||||||
heap::priority_queue<T, heap::stable<true>> p_queue;
|
heap::priority_queue<T, heap::stable<true>> p_queue;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
void push(T const &value)
|
void push(T const &value)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
std::unique_lock<std::mutex> lock(this->write_mutex);
|
||||||
p_queue.push(value);
|
p_queue.push(value);
|
||||||
}
|
}
|
||||||
this->d_condition.notify_one();
|
this->d_condition.notify_one();
|
||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
T pop()
|
T pop()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(this->d_mutex);
|
std::unique_lock<std::mutex> lock(this->read_mutex);
|
||||||
this->d_condition.wait(lock, [=]
|
this->d_condition.wait(lock, [=]
|
||||||
{ return !this->p_queue.empty(); });
|
{ return !this->p_queue.empty(); });
|
||||||
T rc = *this->p_queue.begin();
|
T rc = *this->p_queue.begin();
|
||||||
|
|||||||
Reference in New Issue
Block a user