2021-10-02 10:28:49 +00:00
|
|
|
/***
|
|
|
|
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
|
|
|
|
{
|
2022-04-07 01:20:46 +00:00
|
|
|
LSSemaphore::LSSemaphore(HANDLE handle) : LSHandle(reinterpret_cast<AuUInt>(handle))
|
|
|
|
{}
|
|
|
|
|
|
|
|
LSSemaphore::~LSSemaphore()
|
|
|
|
{
|
|
|
|
auto handle = reinterpret_cast<HANDLE>(this->handle);
|
|
|
|
AuWin32CloseHandle(handle);
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:56:56 +00:00
|
|
|
bool LSSemaphore::AddOne()
|
2021-10-03 12:47:16 +00:00
|
|
|
{
|
|
|
|
LONG atomicOld;
|
|
|
|
return ReleaseSemaphore(reinterpret_cast<HANDLE>(handle), 1, &atomicOld);
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:56:56 +00:00
|
|
|
bool LSSemaphore::IsSignaled()
|
2021-10-03 12:47:16 +00:00
|
|
|
{
|
|
|
|
return LSHandle::IsSignaled();
|
|
|
|
}
|
|
|
|
|
2022-04-12 21:26:15 +00:00
|
|
|
bool LSSemaphore::WaitOn(AuUInt32 timeout)
|
|
|
|
{
|
|
|
|
return LSHandle::WaitOn(timeout);
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:56:56 +00:00
|
|
|
ELoopSource LSSemaphore::GetType()
|
2021-10-03 12:47:16 +00:00
|
|
|
{
|
|
|
|
return ELoopSource::eSourceSemaphore;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuSPtr<ILSSemaphore> NewLSSemaphore(AuUInt32 initialCount)
|
|
|
|
{
|
2022-03-30 17:56:56 +00:00
|
|
|
AuSPtr<LSSemaphore> ret;
|
2021-10-03 12:47:16 +00:00
|
|
|
|
2022-02-19 17:56:45 +00:00
|
|
|
auto mutex = ::CreateSemaphoreA(NULL, initialCount, AuNumericLimits<LONG>::max(), NULL);
|
2021-10-03 12:47:16 +00:00
|
|
|
if (mutex == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
SysPushErrorGen("Out of OS resources?");
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:56:56 +00:00
|
|
|
return AuMakeShared<LSSemaphore>(mutex);
|
2021-10-03 12:47:16 +00:00
|
|
|
}
|
2021-10-02 10:28:49 +00:00
|
|
|
}
|