/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: LSSemaphore.NT.cpp Date: 2021-10-1 Author: Reece ***/ #include #include "LSSemaphore.hpp" namespace Aurora::IO::Loop { LSSemaphore::LSSemaphore(HANDLE handle) : LSHandle(AuReinterpretCast(handle)) {} LSSemaphore::~LSSemaphore() { auto handle = AuReinterpretCast(this->handle); AuWin32CloseHandle(handle); this->handle = kInvalidHandle; } bool LSSemaphore::AddOne() { LONG atomicOld; return ::ReleaseSemaphore(AuReinterpretCast(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 NewLSSemaphore(AuUInt32 initialCount) { AuSPtr ret; auto semaphore = ::CreateSemaphoreA(NULL, initialCount, AuNumericLimits::max(), NULL); if (!semaphore) { SysPushErrorGen("Out of OS resources?"); return {}; } return AuMakeShared(semaphore); } }