mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-02 21:11:25 +12:00
Implement shared_mutex::lock_unlock
Minor fix for shared_mutex::try_lock - don't optimize for pessimistic case
This commit is contained in:
parent
8a1b5abee1
commit
7a024f3355
2 changed files with 82 additions and 19 deletions
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue