From 92a75cfa80767257b2fd1a0ab4820aeb2d6da00f Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 9 Sep 2019 04:41:47 +0300 Subject: [PATCH] Remove `unique_cond` Not very useful. --- Utilities/cond.cpp | 48 ---------------------------------------------- Utilities/cond.h | 47 --------------------------------------------- 2 files changed, 95 deletions(-) diff --git a/Utilities/cond.cpp b/Utilities/cond.cpp index 8c70be1b3f..64c0515323 100644 --- a/Utilities/cond.cpp +++ b/Utilities/cond.cpp @@ -54,54 +54,6 @@ void cond_variable::imp_wake(u32 _count) noexcept })); } -bool unique_cond::imp_wait(u64 _timeout) noexcept -{ - // State transition: c_sig -> c_lock \ c_lock -> c_wait - const u32 _old = m_value.fetch_sub(1); - if (LIKELY(_old == c_sig)) - return true; - - return balanced_wait_until(m_value, _timeout, [&](u32& value, auto... ret) -> int - { - if (value == c_sig) - { - value = c_lock; - return +1; - } - - if constexpr (sizeof...(ret)) - { - value = c_lock; - return -1; - } - - return 0; - }); -} - -void unique_cond::imp_notify() noexcept -{ - auto [old, ok] = m_value.fetch_op([](u32& v) - { - if (UNLIKELY(v > 0 && v < c_sig)) - { - v = c_sig; - return true; - } - - return false; - }); - - verify(HERE), old <= c_sig; - - if (LIKELY(!ok || old == c_lock)) - { - return; - } - - balanced_awaken(m_value, 1); -} - bool shared_cond::imp_wait(u32 slot, u64 _timeout) noexcept { if (slot >= 32) diff --git a/Utilities/cond.h b/Utilities/cond.h index 02c9143e14..01a23d83eb 100644 --- a/Utilities/cond.h +++ b/Utilities/cond.h @@ -62,53 +62,6 @@ public: static constexpr u64 max_timeout = u64{UINT32_MAX} / 1000 * 1000000; }; -// Condition variable fused with a pseudo-mutex which is never supposed to be locked concurrently. -class unique_cond -{ - enum : u32 - { - c_wait = 1, - c_lock = 2, - c_sig = 3, - }; - - atomic_t m_value{0}; - - bool imp_wait(u64 _timeout) noexcept; - void imp_notify() noexcept; - -public: - constexpr unique_cond() = default; - - void lock() noexcept - { - // Shouldn't be locked by more than one thread concurrently - while (UNLIKELY(!m_value.compare_and_swap_test(0, c_lock))) - ; - } - - void unlock() noexcept - { - m_value = 0; - } - - bool wait(std::unique_lock& lock, u64 usec_timeout = -1) noexcept - { - AUDIT(lock.owns_lock()); - AUDIT(lock.mutex() == this); - return imp_wait(usec_timeout); - } - - void notify() noexcept - { - // Early exit if notification is not required - if (LIKELY(!m_value)) - return; - - imp_notify(); - } -}; - // Condition variable fused with a pseudo-mutex supporting only reader locks (up to 32 readers). class shared_cond {