/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: Mutex.Generic.cpp Date: 2021-6-12 Author: Reece ***/ #include #include "Mutex.Generic.hpp" #if defined(_AURUNTIME_GENERICMUTEX) namespace Aurora::Threading::Primitives { Mutex::Mutex() { value_ = 0; } Mutex::~Mutex() { value_ = 0; } bool Mutex::HasOSHandle(AuMach &mach) { return false; } bool Mutex::TryLock() { #if defined(_AU_HAS_ATOMIC_INTRINS) return _interlockedbittestandset(&value_, 0) == 0; #else return value_.fetch_or(1); #endif } bool Mutex::HasLockImplementation() { return false; } void Mutex::Lock() { auto status = Lock(0); SysAssert(status, "Couldn't lock Mutex object"); } bool Mutex::Lock(AuUInt64 timeout) { SysAssertExp(!HasLockImplementation()); return Aurora::Threading::WaitFor(this, timeout); } void Mutex::Unlock() { value_ = 0; } AUKN_SYM IWaitable *MutexNew() { return _new Mutex(); } AUKN_SYM void MutexRelease(IWaitable *waitable) { AuSafeDelete(waitable); } } #endif