mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-12-30 15:17:27 +00:00
160b131de3
Rewritten the following global utility constants: `umax` returns max number, restricted to unsigned. `smax` returns max signed number, restricted to integrals. `smin` returns min signed number, restricted to signed. `amin` returns smin or zero, less restricted. `amax` returns smax or umax, less restricted. Fix operators == and <=> for synthesized rel-ops.
57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#include "cond.h"
|
|
#include "sync.h"
|
|
|
|
// use constants, increase signal space
|
|
|
|
void cond_variable::imp_wait(u32 _old, u64 _timeout) noexcept
|
|
{
|
|
// Not supposed to fail
|
|
ensure(_old);
|
|
|
|
// Wait with timeout
|
|
m_value.wait(_old, c_signal_mask, atomic_wait_timeout{_timeout > max_timeout ? umax : _timeout * 1000});
|
|
|
|
// Cleanup
|
|
m_value.atomic_op([](u32& value)
|
|
{
|
|
// Remove waiter (c_waiter_mask)
|
|
value -= 1;
|
|
|
|
if ((value & c_waiter_mask) == 0)
|
|
{
|
|
// Last waiter removed, clean signals
|
|
value = 0;
|
|
}
|
|
});
|
|
}
|
|
|
|
void cond_variable::imp_wake(u32 _count) noexcept
|
|
{
|
|
const auto [_old, ok] = m_value.fetch_op([](u32& value)
|
|
{
|
|
if (!value || (value & c_signal_mask) == c_signal_mask)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Add signal
|
|
value += c_signal_mask & (0 - c_signal_mask);
|
|
return true;
|
|
});
|
|
|
|
if (!ok || !_count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_count > 1 || ((_old + (c_signal_mask & (0 - c_signal_mask))) & c_signal_mask) == c_signal_mask)
|
|
{
|
|
// Resort to notify_all if signal count reached max
|
|
m_value.notify_all(c_signal_mask);
|
|
}
|
|
else
|
|
{
|
|
m_value.notify_one(c_signal_mask);
|
|
}
|
|
}
|