fixed blocking queue
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user