Implement shared_mutex::lock_unlock

Minor fix for shared_mutex::try_lock - don't optimize for pessimistic case
This commit is contained in:
Nekotekina 2018-10-01 20:03:40 +03:00
parent 8a1b5abee1
commit 7a024f3355
2 changed files with 82 additions and 19 deletions

View file

@ -19,9 +19,11 @@ class shared_mutex final
void imp_lock_shared(u32 val);
void imp_unlock_shared(u32 old);
void imp_wait();
void imp_signal();
void imp_lock(u32 val);
void imp_unlock(u32 old);
void imp_lock_upgrade();
void imp_lock_unlock();
public:
constexpr shared_mutex() = default;
@ -57,7 +59,7 @@ public:
bool try_lock()
{
return m_value == 0 && m_value.compare_and_swap_test(0, c_one);
return m_value.compare_and_swap_test(0, c_one);
}
void lock()
@ -103,6 +105,15 @@ public:
m_value -= c_one - 1;
}
// Optimized wait for lockability without locking, relaxed
void lock_unlock()
{
if (UNLIKELY(m_value != 0))
{
imp_lock_unlock();
}
}
// Check whether can immediately obtain an exclusive (writer) lock
bool is_free() const
{