AuroraRuntime/Source/Loop/LSMutex.NT.cpp
2022-04-12 22:29:50 +01:00

55 lines
1.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSMutex.NT.cpp
Date: 2021-10-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "LSMutex.hpp"
namespace Aurora::Loop
{
Mutex::Mutex(HANDLE handle) : LSHandle(reinterpret_cast<AuUInt>(handle))
{}
Mutex::~Mutex()
{
auto handle = reinterpret_cast<HANDLE>(this->handle);
AuWin32CloseHandle(handle);
}
bool Mutex::Unlock()
{
return ReleaseMutex(reinterpret_cast<HANDLE>(handle));
}
bool Mutex::IsSignaled()
{
return LSHandle::IsSignaled();
}
bool Mutex::WaitOn(AuUInt32 timeout)
{
return LSHandle::WaitOn(timeout);
}
ELoopSource Mutex::GetType()
{
return ELoopSource::eSourceMutex;
}
AUKN_SYM AuSPtr<ILSMutex> NewLSMutex()
{
AuSPtr<ILSMutex> ret;
auto mutex = ::CreateMutexW(NULL, false, NULL);
if (mutex == INVALID_HANDLE_VALUE)
{
SysPushErrorGen("Out of OS resources?");
return {};
}
return AuMakeShared<Mutex>(mutex);
}
}