mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-02 13:01:27 +12:00
Remove notifier
class
Poorly implemented condition variable.
This commit is contained in:
parent
b91661ae71
commit
a45f86a4a2
5 changed files with 2 additions and 178 deletions
|
@ -54,100 +54,6 @@ void cond_variable::imp_wake(u32 _count) noexcept
|
|||
}));
|
||||
}
|
||||
|
||||
bool notifier::imp_try_lock(u32 count)
|
||||
{
|
||||
return m_counter.atomic_op([&](u32& value)
|
||||
{
|
||||
if ((value % (max_readers + 1)) + count <= max_readers)
|
||||
{
|
||||
value += count;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void notifier::imp_unlock(u32 count)
|
||||
{
|
||||
const u32 counter = m_counter.sub_fetch(count);
|
||||
|
||||
if (UNLIKELY(counter % (max_readers + 1)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (counter)
|
||||
{
|
||||
const u32 _old = m_counter.atomic_op([](u32& value) -> u32
|
||||
{
|
||||
if (value % (max_readers + 1))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return std::exchange(value, 0) / (max_readers + 1);
|
||||
});
|
||||
|
||||
const u32 wc = m_cond.m_value;
|
||||
|
||||
if (_old && wc)
|
||||
{
|
||||
m_cond.imp_wake(_old > wc ? wc : _old);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32 notifier::imp_notify(u32 count)
|
||||
{
|
||||
return m_counter.atomic_op([&](u32& value) -> u32
|
||||
{
|
||||
if (const u32 add = value % (max_readers + 1))
|
||||
{
|
||||
// Mutex is locked
|
||||
const u32 result = add > count ? count : add;
|
||||
value += result * (max_readers + 1);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Mutex is unlocked
|
||||
value = 0;
|
||||
return count;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool notifier::wait(u64 usec_timeout)
|
||||
{
|
||||
const u32 _old = m_cond.m_value.fetch_add(1);
|
||||
|
||||
if (max_readers < m_counter.fetch_op([](u32& value)
|
||||
{
|
||||
if (value > max_readers)
|
||||
{
|
||||
value -= max_readers;
|
||||
}
|
||||
|
||||
value -= 1;
|
||||
}))
|
||||
{
|
||||
// Return without waiting
|
||||
m_cond.imp_wait(_old, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool res = m_cond.imp_wait(_old, usec_timeout);
|
||||
|
||||
while (!try_lock_shared())
|
||||
{
|
||||
// TODO
|
||||
busy_wait();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool unique_cond::imp_wait(u64 _timeout) noexcept
|
||||
{
|
||||
// State transition: c_sig -> c_lock \ c_lock -> c_wait
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue