thread/Cond: add wait() overload which takes a unique_lock<>
Just like std::condition_variable, which however has no way to specify the std::mutex directly.
This commit is contained in:
@@ -149,7 +149,7 @@ BufferedInputStream::RunThread() noexcept
|
||||
{
|
||||
SetThreadName("input_buffered");
|
||||
|
||||
const std::lock_guard<Mutex> lock(mutex);
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
|
||||
while (!stop) {
|
||||
assert(size == buffer.size());
|
||||
@@ -205,6 +205,6 @@ BufferedInputStream::RunThread() noexcept
|
||||
client_cond.notify_one();
|
||||
InvokeOnAvailable();
|
||||
} else
|
||||
wake_cond.wait(mutex);
|
||||
wake_cond.wait(lock);
|
||||
}
|
||||
}
|
||||
|
@@ -57,14 +57,14 @@ InputStream::OpenReady(const char *uri, Mutex &mutex)
|
||||
is->SetHandler(&handler);
|
||||
|
||||
{
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
|
||||
while (true) {
|
||||
is->Update();
|
||||
if (is->IsReady())
|
||||
break;
|
||||
|
||||
handler.cond.wait(mutex);
|
||||
handler.cond.wait(lock);
|
||||
}
|
||||
|
||||
is->Check();
|
||||
|
@@ -67,7 +67,7 @@ ThreadInputStream::ThreadFunc() noexcept
|
||||
{
|
||||
FormatThreadName("input:%s", plugin);
|
||||
|
||||
const std::lock_guard<Mutex> lock(mutex);
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
|
||||
try {
|
||||
Open();
|
||||
@@ -85,7 +85,7 @@ ThreadInputStream::ThreadFunc() noexcept
|
||||
|
||||
auto w = buffer.Write();
|
||||
if (w.empty()) {
|
||||
wake_cond.wait(mutex);
|
||||
wake_cond.wait(lock);
|
||||
} else {
|
||||
size_t nbytes;
|
||||
|
||||
|
Reference in New Issue
Block a user