56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: LSSemaphore.NT.cpp
|
|
Date: 2021-10-1
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "LSSemaphore.hpp"
|
|
|
|
namespace Aurora::Loop
|
|
{
|
|
LSSemaphore::LSSemaphore(HANDLE handle) : LSHandle(reinterpret_cast<AuUInt>(handle))
|
|
{}
|
|
|
|
LSSemaphore::~LSSemaphore()
|
|
{
|
|
auto handle = reinterpret_cast<HANDLE>(this->handle);
|
|
AuWin32CloseHandle(handle);
|
|
}
|
|
|
|
bool LSSemaphore::AddOne()
|
|
{
|
|
LONG atomicOld;
|
|
return ReleaseSemaphore(reinterpret_cast<HANDLE>(handle), 1, &atomicOld);
|
|
}
|
|
|
|
bool LSSemaphore::IsSignaled()
|
|
{
|
|
return LSHandle::IsSignaled();
|
|
}
|
|
|
|
bool LSSemaphore::WaitOn(AuUInt32 timeout)
|
|
{
|
|
return LSHandle::WaitOn(timeout);
|
|
}
|
|
|
|
ELoopSource LSSemaphore::GetType()
|
|
{
|
|
return ELoopSource::eSourceSemaphore;
|
|
}
|
|
|
|
AUKN_SYM AuSPtr<ILSSemaphore> NewLSSemaphore(AuUInt32 initialCount)
|
|
{
|
|
AuSPtr<LSSemaphore> ret;
|
|
|
|
auto mutex = ::CreateSemaphoreA(NULL, initialCount, AuNumericLimits<LONG>::max(), NULL);
|
|
if (mutex == INVALID_HANDLE_VALUE)
|
|
{
|
|
SysPushErrorGen("Out of OS resources?");
|
|
return {};
|
|
}
|
|
|
|
return AuMakeShared<LSSemaphore>(mutex);
|
|
}
|
|
} |