mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-06 10:09:33 +02:00
abortable pop
This commit is contained in:
parent
935899b0a2
commit
d0c88e2ce0
1 changed files with 9 additions and 9 deletions
|
@ -52,9 +52,7 @@ public:
|
||||||
bool try_pop(T& item, std::chrono::microseconds timeout)
|
bool try_pop(T& item, std::chrono::microseconds timeout)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> mlock(mutex_);
|
std::unique_lock<std::mutex> mlock(mutex_);
|
||||||
|
cond_.wait_for(mlock, timeout);
|
||||||
if (!cond_.wait_for(mlock, timeout, [this] { return !queue_.empty(); }))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (queue_.empty())
|
if (queue_.empty())
|
||||||
return false;
|
return false;
|
||||||
|
@ -75,15 +73,17 @@ public:
|
||||||
cond_.notify_one();
|
cond_.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop(T& item)
|
bool pop(T& item)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> mlock(mutex_);
|
std::unique_lock<std::mutex> mlock(mutex_);
|
||||||
while (queue_.empty())
|
cond_.wait(mlock);
|
||||||
{
|
|
||||||
cond_.wait(mlock);
|
if (queue_.empty())
|
||||||
}
|
return false;
|
||||||
item = queue_.front();
|
|
||||||
|
item = std::move(queue_.front());
|
||||||
queue_.pop();
|
queue_.pop();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(const T& item)
|
void push(const T& item)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue