[*] bonk (use AuAXXX atomics)

This commit is contained in:
Reece Wilson 2023-09-02 04:55:43 +01:00
parent a20e9b4954
commit de25694416
13 changed files with 45 additions and 38 deletions

View File

@ -152,7 +152,7 @@ namespace Aurora::Threading::Primitives
virtual void SlowLock() = 0;
protected:
volatile AuUInt32 state_ {};
AuAUInt32 state_ {};
};
#if defined(AURT_ENABLE_HYPER_MUTEX)

View File

@ -167,8 +167,8 @@ namespace Aurora::Threading::Waitables
}
}
volatile AuUInt32 uAtomicState {};
volatile AuUInt32 uAtomicSleeping {};
AuAUInt32 uAtomicState {};
AuAUInt32 uAtomicSleeping {};
private:
auline bool TryLock3()

View File

@ -165,7 +165,7 @@ namespace Aurora::Threading::Waitables
return true;
}
volatile AuUInt32 uAtomicState {};
volatile AuUInt32 uAtomicSleeping {};
AuAUInt32 uAtomicState {};
AuAUInt32 uAtomicSleeping {};
};
}

View File

@ -162,7 +162,7 @@ namespace Aurora::Threading::Waitables
return true;
}
volatile AuUInt32 uAtomicState {};
volatile AuUInt32 uAtomicSleeping {};
AuAUInt32 uAtomicState {};
AuAUInt32 uAtomicSleeping {};
};
}

View File

@ -6,6 +6,7 @@
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "Source/Threading/Primitives/AuConditionMutex.NT.hpp"
namespace Aurora
{
@ -153,6 +154,17 @@ namespace Aurora
ADD_GET_PROC(Shell, SHGetKnownFolderPath)
if (pNtCreateKeyedEvent &&
Threading::Primitives::gKeyedEventHandle == INVALID_HANDLE_VALUE)
{
if (!gUseNativeWaitCondvar)
{
SysAssert(pNtCreateKeyedEvent);
pNtCreateKeyedEvent(&Threading::Primitives::gKeyedEventHandle, -1, NULL, 0);
}
}
#else
pWaitOnAddress = WaitOnAddress;
pWakeByAddressSingle = WakeByAddressSingle;

View File

@ -11,7 +11,15 @@
namespace Aurora::Threading
{
bool InternalLTSWaitOnAddressHighRes(void *pTargetAddress,
void *pCompareAddress,
const void *pCompareAddress,
AuUInt8 uWordSize,
AuUInt64 qwNanosecondsAbs);
static bool InternalLTSWaitOnAddressHighRes(volatile void *pTargetAddress,
const void *pCompareAddress,
AuUInt8 uWordSize,
AuUInt64 qwNanosecondsAbs)
{
return InternalLTSWaitOnAddressHighRes((void *)pTargetAddress, pCompareAddress, uWordSize, qwNanosecondsAbs);
}
}

View File

@ -769,7 +769,7 @@ namespace Aurora::Threading
// it does not, however, work on emulated platforms
// this is intentional
bool InternalLTSWaitOnAddressHighRes(void *pTargetAddress,
void *pCompareAddress,
const void *pCompareAddress,
AuUInt8 uWordSize,
AuUInt64 qwNanosecondsAbs)
{

View File

@ -28,7 +28,7 @@ namespace Aurora::Threading::Primitives
private:
SemaphoreImpl s_;
AuUInt32 uWaiters_;
AuAUInt32 uWaiters_;
};
SemaphoreConditionVariableImpl::SemaphoreConditionVariableImpl() :

View File

@ -18,19 +18,6 @@ namespace Aurora::Threading::Primitives
Win32ConditionMutex::Win32ConditionMutex()
{
#if !defined(AURORA_FORCE_SRW_LOCKS)
if (!pWaitOnAddress && !pNtCreateKeyedEvent)
{
InitProcAddresses();
}
if (gKeyedEventHandle == INVALID_HANDLE_VALUE)
{
if (!gUseNativeWaitCondvar)
{
SysAssert(pNtCreateKeyedEvent);
pNtCreateKeyedEvent(&gKeyedEventHandle, -1, NULL, 0);
}
}
#else
::InitializeSRWLock(&this->lock_);
#endif

View File

@ -95,7 +95,7 @@ namespace Aurora::Threading::Primitives
}
}
bRet = pNtWaitForKeyedEvent(gKeyedEventHandle, &this->wlist, 0, &word) != NTSTATUS_TIMEOUT;
bRet = pNtWaitForKeyedEvent(gKeyedEventHandle, (void *)&this->wlist, 0, &word) != NTSTATUS_TIMEOUT;
}
pMutex->Lock();
@ -118,7 +118,7 @@ namespace Aurora::Threading::Primitives
}
AuUInt8 uBlockBit { 1 };
pWakeByAddressAll(&this->wlist); // this is kinda sad
pWakeByAddressAll((void *)&this->wlist); // this is kinda sad
bRet = InternalLTSWaitOnAddressHighRes(&this->wlist, &uBlockBit, 1, uEndTimeSteady); // why?
}
else
@ -126,7 +126,7 @@ namespace Aurora::Threading::Primitives
pMutex->Unlock();
// Obligatory Windows XP+ resched
bRet = pNtWaitForKeyedEvent(gKeyedEventHandle, &this->wlist, 0, nullptr) != NTSTATUS_TIMEOUT;
bRet = pNtWaitForKeyedEvent(gKeyedEventHandle, (void *)&this->wlist, 0, nullptr) != NTSTATUS_TIMEOUT;
}
pMutex->Lock();
@ -231,7 +231,7 @@ namespace Aurora::Threading::Primitives
}
}
pNtWaitForKeyedEvent(gKeyedEventHandle, &this->wlist, 0, nullptr);
pNtWaitForKeyedEvent(gKeyedEventHandle, (void *)&this->wlist, 0, nullptr);
}
pMutex->Lock();
@ -332,11 +332,11 @@ namespace Aurora::Threading::Primitives
{
if (gUseNativeWaitCondvar)
{
pWakeByAddressSingle(&this->wlist);
pWakeByAddressSingle((void *)&this->wlist);
}
else
{
pNtReleaseKeyedEvent(gKeyedEventHandle, &this->wlist, FALSE, nullptr);
pNtReleaseKeyedEvent(gKeyedEventHandle, (void *)&this->wlist, FALSE, nullptr);
}
return;
@ -376,7 +376,7 @@ namespace Aurora::Threading::Primitives
expected - uAwoken,
original) == original)
{
pWakeByAddressAll(&this->wlist);
pWakeByAddressAll((void *)&this->wlist);
return;
}
else
@ -404,7 +404,7 @@ namespace Aurora::Threading::Primitives
bool bBreak {};
if (AuAtomicCompareExchange(&this->wlist, ((expected - 1) << kShiftCountByBits) /*intentional clear*/, original) == original)
{
pNtReleaseKeyedEvent(gKeyedEventHandle, &this->wlist, FALSE, nullptr);
pNtReleaseKeyedEvent(gKeyedEventHandle, (void *)&this->wlist, FALSE, nullptr);
uBroadcastIterations--;
bBreak = true;

View File

@ -26,8 +26,8 @@ namespace Aurora::Threading::Primitives
#if defined(AURORA_FORCE_SRW_LOCKS)
CONDITION_VARIABLE winCond_;
#else
AuUInt32 wlist {};
AuUInt32 signalCount {};
AuAUInt32 wlist {};
AuAUInt32 signalCount {};
#endif
};

View File

@ -96,7 +96,7 @@ namespace Aurora::Threading::Primitives
auto pCounter = GetSleepCounter();
AuAtomicAdd(pCounter, 1u);
bool bStatus = InternalLTSWaitOnAddressHighRes(&this->dwState_, (void *)&kExpect, sizeof(kExpect), uEnd);
bool bStatus = InternalLTSWaitOnAddressHighRes(&this->dwState_, &kExpect, sizeof(kExpect), uEnd);
AuAtomicSub(pCounter, 1u);
if (!bStatus)
@ -156,7 +156,7 @@ namespace Aurora::Threading::Primitives
auto pCounter = GetSleepCounter();
AuAtomicAdd(pCounter, 1u);
bool bStatus = InternalLTSWaitOnAddressHighRes(&this->dwState_, (void *)&kExpect, sizeof(kExpect), qwTimeoutAbs);
bool bStatus = InternalLTSWaitOnAddressHighRes(&this->dwState_, &kExpect, sizeof(kExpect), qwTimeoutAbs);
AuAtomicSub(pCounter, 1u);
if (!bStatus)
@ -214,11 +214,11 @@ namespace Aurora::Threading::Primitives
{
if (count == 1)
{
pWakeByAddressSingle(&this->dwState_);
pWakeByAddressSingle((void *)&this->dwState_);
}
else
{
pWakeByAddressAll(&this->dwState_);
pWakeByAddressAll((void *)&this->dwState_);
}
}
}

View File

@ -32,7 +32,7 @@ namespace Aurora::Threading::Primitives
auline AuUInt32 *GetSleepCounter();
private:
AuUInt32 dwState_ {};
AuAUInt32 dwState_ {};
ConditionMutexInternal mutex;
ConditionVariableInternal var;
};