AuroraRuntime/Source/IO/Loop/LSSemaphore.NT.cpp
Reece Wilson 433898709e [*] Check for null handle under LSHandle bc win32 apis are inconsistent as shit
[*] _beginthreadex returns null, nonex returns -1, and it doesnt fucking work with affinity but seems to work with name updates. i dont care to fix this yet. fuck microsoft.
[*] NT: preempt process watch thread of leaders instead of syncing to the process under a watch guard on free (evil, we should use a builtin nt threadpool. also cant be arsed to resolve)
2022-07-08 22:58:49 +01:00

57 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::IO::Loop
{
LSSemaphore::LSSemaphore(HANDLE handle) : LSHandle(AuReinterpretCast<AuUInt>(handle))
{}
LSSemaphore::~LSSemaphore()
{
auto handle = AuReinterpretCast<HANDLE>(this->handle);
AuWin32CloseHandle(handle);
this->handle = kInvalidHandle;
}
bool LSSemaphore::AddOne()
{
LONG atomicOld;
return ::ReleaseSemaphore(AuReinterpretCast<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 semaphore = ::CreateSemaphoreA(NULL, initialCount, AuNumericLimits<LONG>::max(), NULL);
if (!semaphore)
{
SysPushErrorGen("Out of OS resources?");
return {};
}
return AuMakeShared<LSSemaphore>(semaphore);
}
}