mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-06 15:01:18 +12:00
Add all the files
This commit is contained in:
parent
e3db07a16a
commit
d60742f52b
1445 changed files with 430238 additions and 0 deletions
38
src/util/helpers/fspinlock.h
Normal file
38
src/util/helpers/fspinlock.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
// minimal but efficient non-recursive spinlock implementation
|
||||
|
||||
#include <atomic>
|
||||
|
||||
class FSpinlock
|
||||
{
|
||||
public:
|
||||
void acquire()
|
||||
{
|
||||
while( true )
|
||||
{
|
||||
if (!m_lockBool.exchange(true, std::memory_order_acquire))
|
||||
break;
|
||||
while (m_lockBool.load(std::memory_order_relaxed)) _mm_pause();
|
||||
}
|
||||
}
|
||||
|
||||
bool tryAcquire()
|
||||
{
|
||||
return !m_lockBool.exchange(true, std::memory_order_acquire);
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue