mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-03 08:39:49 +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)
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex_);
|
||||
|
||||
if (!cond_.wait_for(mlock, timeout, [this] { return !queue_.empty(); }))
|
||||
return false;
|
||||
cond_.wait_for(mlock, timeout);
|
||||
|
||||
if (queue_.empty())
|
||||
return false;
|
||||
|
@ -75,15 +73,17 @@ public:
|
|||
cond_.notify_one();
|
||||
}
|
||||
|
||||
void pop(T& item)
|
||||
bool pop(T& item)
|
||||
{
|
||||
std::unique_lock<std::mutex> mlock(mutex_);
|
||||
while (queue_.empty())
|
||||
{
|
||||
cond_.wait(mlock);
|
||||
}
|
||||
item = queue_.front();
|
||||
cond_.wait(mlock);
|
||||
|
||||
if (queue_.empty())
|
||||
return false;
|
||||
|
||||
item = std::move(queue_.front());
|
||||
queue_.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
void push(const T& item)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue