mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-12-12 10:37:02 +00:00
Make controller button code thread-safe (#405)
* Refactor spinlock to meet Lockable requirements * Input: Refactor button code and make it thread-safe
This commit is contained in:
parent
c40466f3a8
commit
028b3f7992
28 changed files with 311 additions and 220 deletions
|
|
@ -7,32 +7,33 @@
|
|||
class FSpinlock
|
||||
{
|
||||
public:
|
||||
void acquire()
|
||||
bool is_locked() const
|
||||
{
|
||||
while( true )
|
||||
return m_lockBool.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// implement BasicLockable and Lockable
|
||||
void lock() const
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!m_lockBool.exchange(true, std::memory_order_acquire))
|
||||
if (!m_lockBool.exchange(true, std::memory_order_acquire))
|
||||
break;
|
||||
while (m_lockBool.load(std::memory_order_relaxed)) _mm_pause();
|
||||
}
|
||||
}
|
||||
|
||||
bool tryAcquire()
|
||||
bool try_lock() const
|
||||
{
|
||||
return !m_lockBool.exchange(true, std::memory_order_acquire);
|
||||
}
|
||||
|
||||
void release()
|
||||
void unlock() const
|
||||
{
|
||||
m_lockBool.store(false, std::memory_order_release);
|
||||
}
|
||||
|
||||
bool isHolding() const
|
||||
{
|
||||
return m_lockBool.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::atomic<bool> m_lockBool = false;
|
||||
mutable std::atomic<bool> m_lockBool = false;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue