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"
|
|
|
|
|
2022-06-11 23:52:46 +00:00
|
|
|
namespace Aurora::IO::Loop
|
2021-10-02 10:28:49 +00:00
|
|
|
{
|
2022-04-18 23:51:36 +00:00
|
|
|
LSSemaphore::LSSemaphore(HANDLE handle) : LSHandle(AuReinterpretCast<AuUInt>(handle))
|
2022-04-07 01:20:46 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
LSSemaphore::~LSSemaphore()
|
|
|
|
{
|
2022-04-18 23:51:36 +00:00
|
|
|
auto handle = AuReinterpretCast<HANDLE>(this->handle);
|
2022-04-07 01:20:46 +00:00
|
|
|
AuWin32CloseHandle(handle);
|
2022-04-16 13:01:33 +00:00
|
|
|
this->handle = kInvalidHandle;
|
2022-04-07 01:20:46 +00:00
|
|
|
}
|
|
|
|
|
2022-03-30 17:56:56 +00:00
|
|
|
bool LSSemaphore::AddOne()
|
2021-10-03 12:47:16 +00:00
|
|
|
{
|
|
|
|
LONG atomicOld;
|
2022-04-19 21:50:34 +00:00
|
|
|
return ::ReleaseSemaphore(AuReinterpretCast<HANDLE>(handle), 1, &atomicOld);
|
2021-10-03 12:47:16 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|