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:
@@ -124,9 +124,9 @@ public:
|
||||
}
|
||||
|
||||
void Wait() {
|
||||
const std::lock_guard<Mutex> lock(mutex);
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
while (!done)
|
||||
cond.wait(mutex);
|
||||
cond.wait(lock);
|
||||
|
||||
if (postponed_error)
|
||||
std::rethrow_exception(postponed_error);
|
||||
|
@@ -167,7 +167,7 @@ private:
|
||||
}
|
||||
|
||||
void WaitConnected() {
|
||||
const std::lock_guard<Mutex> protect(mutex);
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
|
||||
while (true) {
|
||||
switch (state) {
|
||||
@@ -179,7 +179,7 @@ private:
|
||||
}
|
||||
|
||||
if (state == State::INITIAL)
|
||||
cond.wait(mutex);
|
||||
cond.wait(lock);
|
||||
break;
|
||||
|
||||
case State::CONNECTING:
|
||||
|
@@ -198,7 +198,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept
|
||||
void
|
||||
UdisksStorage::MountWait()
|
||||
{
|
||||
const std::lock_guard<Mutex> lock(mutex);
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
|
||||
if (mounted_storage)
|
||||
/* already mounted */
|
||||
@@ -210,7 +210,7 @@ UdisksStorage::MountWait()
|
||||
}
|
||||
|
||||
while (want_mount)
|
||||
cond.wait(mutex);
|
||||
cond.wait(lock);
|
||||
|
||||
if (mount_error)
|
||||
std::rethrow_exception(mount_error);
|
||||
@@ -272,7 +272,7 @@ try {
|
||||
void
|
||||
UdisksStorage::UnmountWait()
|
||||
{
|
||||
const std::lock_guard<Mutex> lock(mutex);
|
||||
std::unique_lock<Mutex> lock(mutex);
|
||||
|
||||
if (!mounted_storage)
|
||||
/* not mounted */
|
||||
@@ -281,7 +281,7 @@ UdisksStorage::UnmountWait()
|
||||
defer_unmount.Schedule();
|
||||
|
||||
while (mounted_storage)
|
||||
cond.wait(mutex);
|
||||
cond.wait(lock);
|
||||
|
||||
if (mount_error)
|
||||
std::rethrow_exception(mount_error);
|
||||
|
Reference in New Issue
Block a user