fixed blocking queue

This commit is contained in:
Jonas Zeunert
2018-07-11 16:42:13 +02:00
parent cfccb67561
commit 30e3b9967f

View File

@@ -24,9 +24,11 @@ private:
public: 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->d_mutex);
p_queue.push(value); p_queue.push(value);
}
this->d_condition.notify_one(); this->d_condition.notify_one();
} }
@@ -36,7 +38,7 @@ public:
// TODO denk ma ueber future nach // TODO denk ma ueber future nach
std::unique_lock<std::mutex> lock(this->d_mutex); std::unique_lock<std::mutex> lock(this->d_mutex);
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); }); this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); });
T rc = *this->p_queue.end(); T rc = *this->p_queue.begin();
this->p_queue.pop(); this->p_queue.pop();
return rc; return rc;
} }