AuroraRuntime/Source/Threading/Primitives/AuMutex.Generic.cpp

71 lines
1.3 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Mutex.Generic.cpp
Date: 2021-6-12
Author: Reece
***/
2021-09-30 14:57:41 +00:00
#include <Source/RuntimeInternal.hpp>
2022-11-17 07:46:07 +00:00
#include "AuMutex.Generic.hpp"
2021-06-27 21:25:29 +00:00
#if defined(_AURUNTIME_GENERICMUTEX)
namespace Aurora::Threading::Primitives
{
MutexImpl::MutexImpl()
2021-06-27 21:25:29 +00:00
{
value_ = 0;
}
MutexImpl::~MutexImpl()
2021-06-27 21:25:29 +00:00
{
value_ = 0;
}
bool MutexImpl::HasOSHandle(AuMach &mach)
2021-06-27 21:25:29 +00:00
{
return false;
}
bool MutexImpl::TryLock()
2021-06-27 21:25:29 +00:00
{
#if defined(_AU_HAS_ATOMIC_INTRINS)
return _interlockedbittestandset(&value_, 0) == 0;
#else
return value_.fetch_or(1);
#endif
}
bool MutexImpl::HasLockImplementation()
2021-06-27 21:25:29 +00:00
{
return false;
}
void MutexImpl::Lock()
2021-06-27 21:25:29 +00:00
{
auto status = Lock(0);
SysAssert(status, "Couldn't lock Mutex object");
}
bool MutexImpl::Lock(AuUInt64 timeout)
2021-06-27 21:25:29 +00:00
{
SysAssertExp(!HasLockImplementation());
return Aurora::Threading::WaitFor(this, timeout);
}
void MutexImpl::Unlock()
2021-06-27 21:25:29 +00:00
{
value_ = 0;
}
AUKN_SYM IWaitable *MutexNew()
{
return _new Mutex();
}
2022-11-17 07:46:07 +00:00
AUKN_SYM void MutexRelease(IWaitable *pMutex)
2021-06-27 21:25:29 +00:00
{
2022-11-17 07:46:07 +00:00
AuSafeDelete<Mutex *>(pMutex);
2021-06-27 21:25:29 +00:00
}
}
#endif