From cf13dee1f3df62df18abddd8b4dd236d9e241d07 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 6 Oct 2019 13:32:03 +0300 Subject: [PATCH] Prioritize vip_lock in shared_mutex Should fix some deadlock issues. --- Utilities/mutex.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Utilities/mutex.h b/Utilities/mutex.h index fd690820cf..c0db4fb80b 100644 --- a/Utilities/mutex.h +++ b/Utilities/mutex.h @@ -122,14 +122,14 @@ public: const u32 value = m_value.load(); // Conditional increment - return value < c_one - 1 && (value % c_vip) == 0 && m_value.compare_and_swap_test(value, value + c_vip); + return (value < c_one - 1 || value & (c_one - c_vip)) && (value % c_vip) == 0 && m_value.compare_and_swap_test(value, value + c_vip); } void lock_vip() { const u32 value = m_value.load(); - if (UNLIKELY(value >= c_one - 1 || (value % c_vip) || !m_value.compare_and_swap_test(value, value + c_vip))) + if (UNLIKELY((value >= c_one - 1 && !(value & (c_one - c_vip))) || (value % c_vip) || !m_value.compare_and_swap_test(value, value + c_vip))) { imp_lock_vip(value); }