diff --git a/Include/Aurora/Threading/IWaitable.hpp b/Include/Aurora/Threading/IWaitable.hpp index f07ea082..9091b90c 100644 --- a/Include/Aurora/Threading/IWaitable.hpp +++ b/Include/Aurora/Threading/IWaitable.hpp @@ -21,7 +21,7 @@ namespace Aurora::Threading virtual bool HasOSHandle(AuMach &mach) = 0; virtual bool HasLockImplementation() = 0; virtual void Lock() = 0; - virtual bool Lock(AuUInt64 timeout /*=0*/) = 0; + virtual bool LockMS(AuUInt64 timeout /*=0*/) = 0; virtual bool LockNS(AuUInt64 timeout /*=0*/) = 0; virtual bool TryLock() = 0; virtual void Unlock() = 0; diff --git a/Include/Aurora/Threading/Primitives/Event.hpp b/Include/Aurora/Threading/Primitives/Event.hpp index df504196..8aba33ec 100644 --- a/Include/Aurora/Threading/Primitives/Event.hpp +++ b/Include/Aurora/Threading/Primitives/Event.hpp @@ -24,7 +24,7 @@ namespace Aurora::Threading::Primitives inline void Wait(AuUInt32 ms) { - Lock(ms); + LockMS(ms); } virtual void Reset() = 0; diff --git a/Include/Aurora/Threading/Primitives/Mutex.hpp b/Include/Aurora/Threading/Primitives/Mutex.hpp index 4dd042b5..d6daf012 100644 --- a/Include/Aurora/Threading/Primitives/Mutex.hpp +++ b/Include/Aurora/Threading/Primitives/Mutex.hpp @@ -9,5 +9,5 @@ namespace Aurora::Threading::Primitives { - AUKN_SHARED_SOO(Mutex, IWaitable, kPrimitiveSizeMutex); + AUKN_SHARED_SOO(Mutex, IHyperWaitable, kPrimitiveSizeMutex); } \ No newline at end of file diff --git a/Include/Aurora/Threading/Primitives/SOOPrimitives.hpp b/Include/Aurora/Threading/Primitives/SOOPrimitives.hpp index 55c00e35..8414b88e 100644 --- a/Include/Aurora/Threading/Primitives/SOOPrimitives.hpp +++ b/Include/Aurora/Threading/Primitives/SOOPrimitives.hpp @@ -7,6 +7,11 @@ ***/ #pragma once +#if defined(AURORA_COMPILER_MSVC) + #pragma warning(push) + #pragma warning(disable: 4141) +#endif + namespace Aurora::Threading::Primitives { static const auto kDefaultPrimitiveSize = 128; @@ -28,6 +33,9 @@ namespace Aurora::Threading::Primitives static const auto kPrimitiveSizeRWLock = kPrimitiveSizeNTRWLock; static const auto kPrimitiveSizeCond = kPrimitiveSizeNTCond; static const auto kPrimitiveSizeCondMutex = kPrimitiveSizeNTCondMutex; + + // fuck you, its time to overtake the STL in even Windows 11 micro-benchmarks + #define AURT_ENABLE_HYPER_MUTEX //#elif defined(AURORA_IS_LINUX_DERIVED) // @@ -43,4 +51,32 @@ namespace Aurora::Threading::Primitives static const auto kPrimitiveSizeCondMutex = kDefaultPrimitiveSize; #endif -} \ No newline at end of file + + struct AUKN_SYM HyperWaitable : IWaitable + { + auline inline void Lock() final override + { + if (AuAtomicTestAndSet(&this->state_, 0u) == 0) + { + return; + } + + SlowLock(); + } + + virtual void SlowLock() = 0; + + protected: + volatile AuUInt32 state_ {}; + }; + +#if defined(AURT_ENABLE_HYPER_MUTEX) + using IHyperWaitable = HyperWaitable; +#else + using IHyperWaitable = IWaitable; +#endif +} + +#if defined(AURORA_COMPILER_MSVC) + #pragma warning(pop) +#endif \ No newline at end of file diff --git a/Include/Aurora/Threading/Primitives/SpinLock.hpp b/Include/Aurora/Threading/Primitives/SpinLock.hpp index b2205422..85352e92 100644 --- a/Include/Aurora/Threading/Primitives/SpinLock.hpp +++ b/Include/Aurora/Threading/Primitives/SpinLock.hpp @@ -7,27 +7,36 @@ ***/ #pragma once +#if defined(AURORA_COMPILER_MSVC) + #pragma warning(push) + #pragma warning(disable: 4275) +#endif + namespace Aurora::Threading::Primitives { - struct AUKN_SYM SpinLock : IWaitable + struct AUKN_SYM SpinLock : HyperWaitable { + using HyperWaitable::Lock; + SpinLock(); bool HasOSHandle(AuMach &mach) override; bool HasLockImplementation() override; - bool Lock(AuUInt64 timeout) override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; bool TryLock() override; - void Lock() override; + void SlowLock() override; void Unlock() override; - - private: - AuAtomicInt value_; }; AUKN_SHARED_API(SpinLock, SpinLock); + using SpinLockSOO = SpinLock; using SpinLockSOO_t = SpinLock; -} \ No newline at end of file +} + +#if defined(AURORA_COMPILER_MSVC) + #pragma warning(pop) +#endif \ No newline at end of file diff --git a/Include/Aurora/Threading/Waitables/BooleanWaitable.hpp b/Include/Aurora/Threading/Waitables/BooleanWaitable.hpp index 1c54b304..694344cb 100644 --- a/Include/Aurora/Threading/Waitables/BooleanWaitable.hpp +++ b/Include/Aurora/Threading/Waitables/BooleanWaitable.hpp @@ -41,7 +41,7 @@ namespace Aurora::Threading::Waitables SysPanic("BooleanWaitable is not lockable"); } - bool Lock(AuUInt64 timeout) override + bool LockMS(AuUInt64 timeout) override { SysPanic("BooleanWaitable is not lockable"); return false; diff --git a/Include/Aurora/Threading/Waitables/CBWaitable.hpp b/Include/Aurora/Threading/Waitables/CBWaitable.hpp index 4ba5c704..f9acbc50 100644 --- a/Include/Aurora/Threading/Waitables/CBWaitable.hpp +++ b/Include/Aurora/Threading/Waitables/CBWaitable.hpp @@ -41,7 +41,7 @@ namespace Aurora::Threading::Waitables SysPanic("CBWaitable is not lockable"); } - bool Lock(AuUInt64 timeout) override + bool LockMS(AuUInt64 timeout) override { SysPanic("CBWaitable is not lockable"); return false; diff --git a/Source/Grug/AuGrug.cpp b/Source/Grug/AuGrug.cpp index 762874ae..65014440 100644 --- a/Source/Grug/AuGrug.cpp +++ b/Source/Grug/AuGrug.cpp @@ -85,7 +85,7 @@ namespace Aurora::Grug if (gArrows) { // grug sleep for 100ms or until poked - if (gArrows->Lock(kGrugSleepMs)) + if (gArrows->LockMS(kGrugSleepMs)) { DequeueOneArrow(); } diff --git a/Source/Logging/AuLogger.cpp b/Source/Logging/AuLogger.cpp index 15843877..7304e32a 100644 --- a/Source/Logging/AuLogger.cpp +++ b/Source/Logging/AuLogger.cpp @@ -15,8 +15,8 @@ namespace Aurora::Logging using namespace Console; static AuList> gLogTasks; - static AuThreadPrimitives::SpinLock gGlobalSpin; - static AuThreadPrimitives::SpinLock gTaskSpin; + static AuThreadPrimitives::MutexSOO gGlobalSpin; + static AuThreadPrimitives::MutexSOO gTaskSpin; static AuList gFlushableLoggers; Logger::Logger(const AuList> &sinks) : sinks(sinks) diff --git a/Source/Threading/AuWaitFor.cpp b/Source/Threading/AuWaitFor.cpp index 16ac62ee..2ed66b03 100644 --- a/Source/Threading/AuWaitFor.cpp +++ b/Source/Threading/AuWaitFor.cpp @@ -231,7 +231,7 @@ namespace Aurora::Threading return false; } - status = waitable->Lock(timeout); + status = waitable->LockMS(timeout); return true; } diff --git a/Source/Threading/Primitives/AuConditionMutex.NT.cpp b/Source/Threading/Primitives/AuConditionMutex.NT.cpp index 06ca5d67..b793bc8f 100644 --- a/Source/Threading/Primitives/AuConditionMutex.NT.cpp +++ b/Source/Threading/Primitives/AuConditionMutex.NT.cpp @@ -76,7 +76,13 @@ namespace Aurora::Threading::Primitives #else auto &uValueRef = this->lock_.uWaitCount; + #if defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64) + // Intel 64 and IA - 32 Architectures Software Developer's Manual, Volume 3A + // Section: 9.1.1 + *(AuUInt8 *)&uValueRef = 0; + #else AuAtomicAnd(&uValueRef, ~0xFFu); + #endif while (true) { diff --git a/Source/Threading/Primitives/AuCriticalSection.cpp b/Source/Threading/Primitives/AuCriticalSection.cpp index 92d7b98f..7f104dff 100644 --- a/Source/Threading/Primitives/AuCriticalSection.cpp +++ b/Source/Threading/Primitives/AuCriticalSection.cpp @@ -49,11 +49,11 @@ namespace Aurora::Threading::Primitives void CriticalSection::Lock() { - auto status = Lock(0); + auto status = LockMS(0); SysAssert(status, "Spurious critical section wakeup"); } - bool CriticalSection::Lock(AuUInt64 timeout) + bool CriticalSection::LockMS(AuUInt64 timeout) { auto cur = GetThreadCookie(); @@ -63,7 +63,7 @@ namespace Aurora::Threading::Primitives return true; } - if (!this->mutex_.Lock(timeout)) + if (!this->mutex_.LockMS(timeout)) { return false; } diff --git a/Source/Threading/Primitives/AuCriticalSection.hpp b/Source/Threading/Primitives/AuCriticalSection.hpp index 3626a6f9..8d27db6b 100644 --- a/Source/Threading/Primitives/AuCriticalSection.hpp +++ b/Source/Threading/Primitives/AuCriticalSection.hpp @@ -21,13 +21,13 @@ namespace Aurora::Threading::Primitives bool HasLockImplementation() override; bool TryLock() override; void Lock() override; - bool Lock(AuUInt64 timeout) override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; void Unlock() override; private: Mutex mutex_; ThreadCookie_t owner_; - std::atomic count_; + AuUInt32 count_; }; } \ No newline at end of file diff --git a/Source/Threading/Primitives/AuEvent.cpp b/Source/Threading/Primitives/AuEvent.cpp index 0b08a64b..ff6e42e8 100644 --- a/Source/Threading/Primitives/AuEvent.cpp +++ b/Source/Threading/Primitives/AuEvent.cpp @@ -25,7 +25,7 @@ namespace Aurora::Threading::Primitives return true; } - bool EventImpl::Lock(AuUInt64 uTimeout /*=0*/) + bool EventImpl::LockMS(AuUInt64 uTimeout /*=0*/) { return LockNS(AuMSToNS(uTimeout)); } @@ -116,7 +116,7 @@ namespace Aurora::Threading::Primitives void EventImpl::Lock() { - auto ok = Lock(0); + auto ok = LockNS(0); SysAssert(ok); } diff --git a/Source/Threading/Primitives/AuEvent.hpp b/Source/Threading/Primitives/AuEvent.hpp index 8ff5c1ca..46c73e2f 100644 --- a/Source/Threading/Primitives/AuEvent.hpp +++ b/Source/Threading/Primitives/AuEvent.hpp @@ -18,7 +18,7 @@ namespace Aurora::Threading::Primitives ~EventImpl(); bool Init(); - bool Lock(AuUInt64 timeout /*=0*/) override; + bool LockMS(AuUInt64 timeout /*=0*/) override; bool LockNS(AuUInt64 timeout /*=0*/) override; bool TryLock() override; void Reset() override; diff --git a/Source/Threading/Primitives/AuMutex.Linux.cpp b/Source/Threading/Primitives/AuMutex.Linux.cpp index b63786f1..6acd377e 100755 --- a/Source/Threading/Primitives/AuMutex.Linux.cpp +++ b/Source/Threading/Primitives/AuMutex.Linux.cpp @@ -75,7 +75,7 @@ namespace Aurora::Threading::Primitives }); } - bool Mutex::Lock(AuUInt64 uTimeout) + bool Mutex::LockMS(AuUInt64 uTimeout) { return LockNS(AuMSToNS(uTimeout)); } @@ -147,7 +147,7 @@ namespace Aurora::Threading::Primitives void Mutex::Lock() { - auto status = Lock(0); + auto status = LockMS(0); SysAssert(status, "Couldn't lock mutex"); } diff --git a/Source/Threading/Primitives/AuMutex.Linux.hpp b/Source/Threading/Primitives/AuMutex.Linux.hpp index 279f31f3..3c232767 100755 --- a/Source/Threading/Primitives/AuMutex.Linux.hpp +++ b/Source/Threading/Primitives/AuMutex.Linux.hpp @@ -18,7 +18,7 @@ namespace Aurora::Threading::Primitives bool TryLock() override; bool HasLockImplementation() override; void Lock() override; - bool Lock(AuUInt64 timeout) override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; void Unlock() override; diff --git a/Source/Threading/Primitives/AuMutex.NT.cpp b/Source/Threading/Primitives/AuMutex.NT.cpp index af3cd9e9..76350167 100644 --- a/Source/Threading/Primitives/AuMutex.NT.cpp +++ b/Source/Threading/Primitives/AuMutex.NT.cpp @@ -55,14 +55,19 @@ namespace Aurora::Threading::Primitives return true; } - void Mutex::Lock() + void Mutex::SlowLock() { - auto status = Lock(0); + auto status = LockNS(0); SysAssert(status, "Couldn't lock Mutex object"); } - bool Mutex::Lock(AuUInt64 uTimeout) + bool Mutex::LockMS(AuUInt64 uTimeout) { + if (AuAtomicTestAndSet(&this->state_, 0) == 0) + { + return true; + } + return LockNS(AuMSToNS(uTimeout)); } @@ -239,8 +244,13 @@ namespace Aurora::Threading::Primitives auto &uValueRef = this->state_; - // clear lock and wake-pending bit, leaving waking up bit alone + #if defined(AURORA_ARCH_X86) || defined(AURORA_ARCH_X64) + // Intel 64 and IA - 32 Architectures Software Developer's Manual, Volume 3A + // Section: 9.1.1 + *(AuUInt8 *)&uValueRef = 0; + #else AuAtomicAnd(&uValueRef, ~0xFFu); + #endif while (true) { @@ -279,12 +289,12 @@ namespace Aurora::Threading::Primitives } } - AUKN_SYM IWaitable *MutexNew() + AUKN_SYM IHyperWaitable *MutexNew() { return _new Mutex(); } - AUKN_SYM void MutexRelease(IWaitable *pMutex) + AUKN_SYM void MutexRelease(IHyperWaitable *pMutex) { AuSafeDelete(pMutex); } diff --git a/Source/Threading/Primitives/AuMutex.NT.hpp b/Source/Threading/Primitives/AuMutex.NT.hpp index 070b1ffa..c174af96 100644 --- a/Source/Threading/Primitives/AuMutex.NT.hpp +++ b/Source/Threading/Primitives/AuMutex.NT.hpp @@ -9,7 +9,7 @@ namespace Aurora::Threading::Primitives { - struct Mutex : IWaitable + struct Mutex : IHyperWaitable { Mutex(); ~Mutex(); @@ -17,8 +17,8 @@ namespace Aurora::Threading::Primitives bool HasOSHandle(AuMach &mach) override; bool TryLock() override; bool HasLockImplementation() override; - void Lock() override; - bool Lock(AuUInt64 timeout) override; + void SlowLock() override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; void Unlock() override; @@ -27,6 +27,5 @@ namespace Aurora::Threading::Primitives SRWLOCK atomicHolder_; CONDITION_VARIABLE wakeup_; #endif - volatile AuUInt32 state_{}; }; } \ No newline at end of file diff --git a/Source/Threading/Primitives/AuMutex.Unix.cpp b/Source/Threading/Primitives/AuMutex.Unix.cpp index ff1015f3..8932439a 100644 --- a/Source/Threading/Primitives/AuMutex.Unix.cpp +++ b/Source/Threading/Primitives/AuMutex.Unix.cpp @@ -46,7 +46,7 @@ namespace Aurora::Threading::Primitives return (old == 0 && AuAtomicCompareExchange(&this->value_, 1, old) == old); } - bool Mutex::Lock(AuUInt64 uTimeout) + bool Mutex::LockMS(AuUInt64 uTimeout) { return LockNS(AuMSToNS(uTimeout)); } @@ -114,16 +114,14 @@ namespace Aurora::Threading::Primitives void Mutex::Lock() { - auto status = Lock(0); + auto status = LockNS(0); SysAssert(status, "Couldn't lock mutex"); } void Mutex::Unlock() { - { - AU_LOCK_GUARD(this->mutex_); - this->value_ = 0; - } + AU_LOCK_GUARD(this->mutex_); + this->value_ = 0; auto ret = ::pthread_cond_signal(&this->pthreadCv_); SysAssert(ret == 0, "Couldn't wake any mutex waiter"); } diff --git a/Source/Threading/Primitives/AuMutex.Unix.hpp b/Source/Threading/Primitives/AuMutex.Unix.hpp index d25d3898..7ec7b318 100644 --- a/Source/Threading/Primitives/AuMutex.Unix.hpp +++ b/Source/Threading/Primitives/AuMutex.Unix.hpp @@ -20,7 +20,7 @@ namespace Aurora::Threading::Primitives bool TryLock() override; bool HasLockImplementation() override; void Lock() override; - bool Lock(AuUInt64 timeout) override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; void Unlock() override; diff --git a/Source/Threading/Primitives/AuRWLock.cpp b/Source/Threading/Primitives/AuRWLock.cpp index 47df40d8..f0e8653b 100644 --- a/Source/Threading/Primitives/AuRWLock.cpp +++ b/Source/Threading/Primitives/AuRWLock.cpp @@ -24,7 +24,7 @@ namespace Aurora::Threading::Primitives } template - bool RWLockAccessView::Lock(AuUInt64 timeout) + bool RWLockAccessView::LockMS(AuUInt64 timeout) { if constexpr (bIsReadView) { diff --git a/Source/Threading/Primitives/AuRWLock.hpp b/Source/Threading/Primitives/AuRWLock.hpp index c7c1d961..333f27b6 100644 --- a/Source/Threading/Primitives/AuRWLock.hpp +++ b/Source/Threading/Primitives/AuRWLock.hpp @@ -24,7 +24,7 @@ namespace Aurora::Threading::Primitives } - bool Lock(AuUInt64 timeout) override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; bool TryLock() override; @@ -41,7 +41,7 @@ namespace Aurora::Threading::Primitives void Lock() override { - SysAssert(Lock(0)); + SysAssert(LockNS(0)); } void Unlock() override; diff --git a/Source/Threading/Primitives/AuSemaphore.Linux.cpp b/Source/Threading/Primitives/AuSemaphore.Linux.cpp index bbe3e642..de038d48 100644 --- a/Source/Threading/Primitives/AuSemaphore.Linux.cpp +++ b/Source/Threading/Primitives/AuSemaphore.Linux.cpp @@ -74,7 +74,7 @@ namespace Aurora::Threading::Primitives }); } - bool Semaphore::Lock(AuUInt64 uTimeout) + bool Semaphore::LockMS(AuUInt64 uTimeout) { return LockNS(AuMSToNS(uTimeout)); } @@ -150,7 +150,7 @@ namespace Aurora::Threading::Primitives void Semaphore::Lock() { - auto status = Lock(0); + auto status = LockNS(0); SysAssert(status, "Couldn't lock semaphore"); } diff --git a/Source/Threading/Primitives/AuSemaphore.Linux.hpp b/Source/Threading/Primitives/AuSemaphore.Linux.hpp index 4634e411..63e6e89f 100644 --- a/Source/Threading/Primitives/AuSemaphore.Linux.hpp +++ b/Source/Threading/Primitives/AuSemaphore.Linux.hpp @@ -17,7 +17,7 @@ namespace Aurora::Threading::Primitives bool HasOSHandle(AuMach &mach) override; bool HasLockImplementation() override; bool TryLock() override; - bool Lock(AuUInt64 timeout) override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; void Lock() override; void Unlock(long count) override; diff --git a/Source/Threading/Primitives/AuSemaphore.NT.cpp b/Source/Threading/Primitives/AuSemaphore.NT.cpp index 0cc27799..7c8d0d31 100644 --- a/Source/Threading/Primitives/AuSemaphore.NT.cpp +++ b/Source/Threading/Primitives/AuSemaphore.NT.cpp @@ -43,7 +43,7 @@ namespace Aurora::Threading::Primitives }); } - bool Semaphore::Lock(AuUInt64 uTimeout) + bool Semaphore::LockMS(AuUInt64 uTimeout) { return LockNS(AuMSToNS(uTimeout)); } @@ -130,7 +130,7 @@ namespace Aurora::Threading::Primitives void Semaphore::Lock() { - auto status = Lock(0); + auto status = LockNS(0); SysAssert(status, "Couldn't lock semaphore"); } diff --git a/Source/Threading/Primitives/AuSemaphore.NT.hpp b/Source/Threading/Primitives/AuSemaphore.NT.hpp index 33c78eca..e80fdf71 100644 --- a/Source/Threading/Primitives/AuSemaphore.NT.hpp +++ b/Source/Threading/Primitives/AuSemaphore.NT.hpp @@ -20,7 +20,7 @@ namespace Aurora::Threading::Primitives bool HasOSHandle(AuMach &mach) override; bool HasLockImplementation() override; bool TryLock() override; - bool Lock(AuUInt64 timeout) override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; void Lock() override; void Unlock(long count) override; diff --git a/Source/Threading/Primitives/AuSemaphore.Unix.cpp b/Source/Threading/Primitives/AuSemaphore.Unix.cpp index 9ed3059a..22a1e0db 100644 --- a/Source/Threading/Primitives/AuSemaphore.Unix.cpp +++ b/Source/Threading/Primitives/AuSemaphore.Unix.cpp @@ -46,7 +46,7 @@ namespace Aurora::Threading::Primitives return (old != 0 && AuAtomicCompareExchange(&this->value_, old - 1, old) == old); } - bool Semaphore::Lock(AuUInt64 uTimeout) + bool Semaphore::LockMS(AuUInt64 uTimeout) { return LockNS(AuMSToNS(uTimeout)); } @@ -117,7 +117,7 @@ namespace Aurora::Threading::Primitives void Semaphore::Lock() { - auto status = Lock(0); + auto status = LockNS(0); SysAssert(status, "Couldn't lock semaphore"); } diff --git a/Source/Threading/Primitives/AuSemaphore.Unix.hpp b/Source/Threading/Primitives/AuSemaphore.Unix.hpp index 99764064..1d772ce6 100644 --- a/Source/Threading/Primitives/AuSemaphore.Unix.hpp +++ b/Source/Threading/Primitives/AuSemaphore.Unix.hpp @@ -19,7 +19,7 @@ namespace Aurora::Threading::Primitives bool HasOSHandle(AuMach &mach) override; bool HasLockImplementation() override; bool TryLock() override; - bool Lock(AuUInt64 timeout) override; + bool LockMS(AuUInt64 timeout) override; bool LockNS(AuUInt64 timeout) override; void Lock() override; void Unlock(long count) override; diff --git a/Source/Threading/Primitives/AuSpinLock.cpp b/Source/Threading/Primitives/AuSpinLock.cpp index 0878f5ad..ddc1d44b 100644 --- a/Source/Threading/Primitives/AuSpinLock.cpp +++ b/Source/Threading/Primitives/AuSpinLock.cpp @@ -25,7 +25,7 @@ namespace Aurora::Threading::Primitives SpinLock::SpinLock() { - value_ = 0; + state_ = 0; } bool SpinLock::HasOSHandle(AuMach &mach) @@ -35,7 +35,7 @@ namespace Aurora::Threading::Primitives bool SpinLock::TryLock() { - return AuAtomicTestAndSet(&this->value_, 0) == 0; + return AuAtomicTestAndSet(&this->state_, 0) == 0; } bool SpinLock::HasLockImplementation() @@ -43,9 +43,9 @@ namespace Aurora::Threading::Primitives return true; } - void SpinLock::Lock() + void SpinLock::SlowLock() { - auto status = Lock(0); + auto status = LockNS(0); SysAssert(status, "Couldn't lock Mutex object"); } @@ -53,10 +53,10 @@ namespace Aurora::Threading::Primitives { if (timeout == 0) { - while (AuAtomicTestAndSet(&this->value_, 0)) + while (AuAtomicTestAndSet(&this->state_, 0)) { long count = 0; - while (this->value_) + while (this->state_) { YieldCpu(count); } @@ -67,10 +67,10 @@ namespace Aurora::Threading::Primitives AuUInt64 startTime = AuTime::HighResClockNS(); AuUInt64 endTime = startTime + timeout; - while (AuAtomicTestAndSet(&this->value_, 0)) + while (AuAtomicTestAndSet(&this->state_, 0)) { long count = 0; - while (value_) + while (this->state_) { if (endTime <= AuTime::HighResClockNS()) { @@ -84,13 +84,13 @@ namespace Aurora::Threading::Primitives return true; } - bool SpinLock::Lock(AuUInt64 timeout) + bool SpinLock::LockMS(AuUInt64 timeout) { return LockNS(AuMSToNS(timeout)); } void SpinLock::Unlock() { - this->value_ = 0; + this->state_ = 0; } } \ No newline at end of file