From ad4ca0c449c9ca1084e25eafa826b81433af12e6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 7 May 2019 19:31:00 +0200 Subject: [PATCH] thread/*Cond: remove wait() overloads without std::unique_lock<> --- src/thread/PosixCond.hxx | 25 ++++++++----------------- src/thread/WindowsCond.hxx | 30 ++++++++---------------------- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/src/thread/PosixCond.hxx b/src/thread/PosixCond.hxx index 92a8a62d4..d16aa2898 100644 --- a/src/thread/PosixCond.hxx +++ b/src/thread/PosixCond.hxx @@ -71,17 +71,13 @@ public: pthread_cond_broadcast(&cond); } - void wait(PosixMutex &mutex) noexcept { - pthread_cond_wait(&cond, &mutex.mutex); - } - - template - void wait(std::unique_lock &lock) noexcept { - wait(*lock.mutex()); + void wait(std::unique_lock &lock) noexcept { + pthread_cond_wait(&cond, &lock.mutex()->mutex); } private: - bool wait_for(PosixMutex &mutex, uint_least32_t timeout_us) noexcept { + bool wait_for(std::unique_lock &lock, + uint_least32_t timeout_us) noexcept { struct timeval now; gettimeofday(&now, nullptr); @@ -94,11 +90,12 @@ private: ts.tv_sec++; } - return pthread_cond_timedwait(&cond, &mutex.mutex, &ts) == 0; + return pthread_cond_timedwait(&cond, &lock.mutex()->mutex, &ts) == 0; } public: - bool wait_for(PosixMutex &mutex, + template + bool wait_for(std::unique_lock &lock, std::chrono::steady_clock::duration timeout) noexcept { auto timeout_us = std::chrono::duration_cast(timeout).count(); if (timeout_us < 0) @@ -106,13 +103,7 @@ public: else if (timeout_us > std::numeric_limits::max()) timeout_us = std::numeric_limits::max(); - return wait_for(mutex, timeout_us); - } - - template - bool wait_for(std::unique_lock &lock, - std::chrono::steady_clock::duration timeout) noexcept { - return wait_for(*lock.mutex(), timeout); + return wait_for(lock, timeout_us); } }; diff --git a/src/thread/WindowsCond.hxx b/src/thread/WindowsCond.hxx index 49bb8d7e6..162a9ac7a 100644 --- a/src/thread/WindowsCond.hxx +++ b/src/thread/WindowsCond.hxx @@ -57,32 +57,18 @@ public: WakeAllConditionVariable(&cond); } -private: - bool wait_for(CriticalSection &mutex, DWORD timeout_ms) noexcept { - return SleepConditionVariableCS(&cond, &mutex.critical_section, - timeout_ms); + void wait(std::unique_lock &lock) noexcept { + SleepConditionVariableCS(&cond, + &lock.mutex()->critical_section, + INFINITE); } -public: - bool wait_for(CriticalSection &mutex, + bool wait_for(std::unique_lock &lock, std::chrono::steady_clock::duration timeout) noexcept { auto timeout_ms = std::chrono::duration_cast(timeout).count(); - return wait_for(mutex, timeout_ms); - } - - template - bool wait_for(std::unique_lock &lock, - std::chrono::steady_clock::duration timeout) noexcept { - return wait_for(*lock.mutex(), timeout); - } - - void wait(CriticalSection &mutex) noexcept { - wait_for(mutex, INFINITE); - } - - template - void wait(std::unique_lock &lock) noexcept { - wait(*lock.mutex()); + return SleepConditionVariableCS(&cond, + &lock.mutex()->critical_section, + timeout_ms); } };