mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 12:51:42 +00:00
Cross-platform spin lock implementation.
This commit is contained in:
parent
d68e88314f
commit
58c8ed45e0
1 changed files with 20 additions and 6 deletions
|
|
@ -695,15 +695,22 @@ void RtlRaiseException_x()
|
||||||
|
|
||||||
void KfReleaseSpinLock(uint32_t* spinLock)
|
void KfReleaseSpinLock(uint32_t* spinLock)
|
||||||
{
|
{
|
||||||
InterlockedExchange((volatile long*)spinLock, 0);
|
std::atomic_ref spinLockRef(*spinLock);
|
||||||
|
spinLockRef = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KfAcquireSpinLock(uint32_t* spinLock)
|
void KfAcquireSpinLock(uint32_t* spinLock)
|
||||||
{
|
{
|
||||||
const auto ctx = GetPPCContext();
|
std::atomic_ref spinLockRef(*spinLock);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
uint32_t expected = 0;
|
||||||
|
if (spinLockRef.compare_exchange_weak(expected, g_ppcContext->r13.u32))
|
||||||
|
break;
|
||||||
|
|
||||||
while (InterlockedCompareExchange((volatile long*)spinLock, ByteSwap(*(uint32_t*)(g_memory.Translate(ctx->r13.u32 + 0x110))), 0) != 0)
|
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t KeQueryPerformanceFrequency()
|
uint64_t KeQueryPerformanceFrequency()
|
||||||
|
|
@ -735,15 +742,22 @@ void VdGetSystemCommandBuffer()
|
||||||
|
|
||||||
void KeReleaseSpinLockFromRaisedIrql(uint32_t* spinLock)
|
void KeReleaseSpinLockFromRaisedIrql(uint32_t* spinLock)
|
||||||
{
|
{
|
||||||
InterlockedExchange((volatile long*)spinLock, 0);
|
std::atomic_ref spinLockRef(*spinLock);
|
||||||
|
spinLockRef = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeAcquireSpinLockAtRaisedIrql(uint32_t* spinLock)
|
void KeAcquireSpinLockAtRaisedIrql(uint32_t* spinLock)
|
||||||
{
|
{
|
||||||
const auto ctx = GetPPCContext();
|
std::atomic_ref spinLockRef(*spinLock);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
uint32_t expected = 0;
|
||||||
|
if (spinLockRef.compare_exchange_weak(expected, g_ppcContext->r13.u32))
|
||||||
|
break;
|
||||||
|
|
||||||
while (InterlockedCompareExchange((volatile long*)spinLock, ByteSwap(*(uint32_t*)(g_memory.Translate(ctx->r13.u32 + 0x110))), 0) != 0)
|
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t KiApcNormalRoutineNop()
|
uint32_t KiApcNormalRoutineNop()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue