fixed blocking queue

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

View File

@@ -25,8 +25,10 @@ private:
public: public:
void push(T const& value) void push(T const& value)
{ {
std::unique_lock<std::mutex> lock(this->d_mutex); {
p_queue.push(value); std::unique_lock<std::mutex> lock(this->d_mutex);
p_queue.push(value);
}
this->d_condition.notify_one(); this->d_condition.notify_one();
} }
@@ -34,9 +36,9 @@ public:
{ {
// TODO die queue funzt net weil wir nich pushen koennen wenn wir im pop warten // TODO die queue funzt net weil wir nich pushen koennen wenn wir im pop warten
// 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;
} }