[+] Added first attempt at the windows version of WaitMultipleObjects/ This will be removed shortly.

[*] Update readme
[*] Update QueryBsdHwStat
This commit is contained in:
Reece Wilson 2021-11-08 23:59:19 +00:00
parent 6888aaaee7
commit d18affeea2
7 changed files with 170 additions and 18 deletions

View File

@ -45,7 +45,7 @@ namespace Aurora::Loop
virtual ELoopSource GetType() = 0; virtual ELoopSource GetType() = 0;
}; };
AUKN_SYM AuList<AuSPtr<ILoopSource>> WaitMultipleObjects(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout); AUKN_SYM AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjects(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout);
class ILSSemaphore : public ILoopSource class ILSSemaphore : public ILoopSource
{ {

View File

@ -17,11 +17,12 @@
namespace Aurora::HWInfo namespace Aurora::HWInfo
{ {
AuOptional<AuUInt> QueryBsdHwStat(int id) template<typename T>
AuOptional<T> QueryBsdHwStat(int id)
{ {
#if defined(AURORA_IS_BSD_DERIVED) #if defined(AURORA_IS_BSD_DERIVED)
int mib[4]; int mib[4];
AuUInt stat; T stat;
size_t len = sizeof(stat); size_t len = sizeof(stat);
mib[0] = CTL_HW; mib[0] = CTL_HW;
@ -34,6 +35,15 @@ namespace Aurora::HWInfo
#endif #endif
} }
template<>
AuOptional<AuUInt> QueryBsdHwStat(int id);
template<>
AuOptional<unsigned int> QueryBsdHwStat(int id);
template<>
AuOptional<uint64_t> QueryBsdHwStat(int id);
void Init() void Init()
{ {
InitCpuInfo(); InitCpuInfo();

View File

@ -9,6 +9,7 @@
namespace Aurora::HWInfo namespace Aurora::HWInfo
{ {
AuOptional<AuUInt> QueryBsdHwStat(int id); template<typename T>
AuOptional<T> QueryBsdHwStat(int id);
void Init(); void Init();
} }

View File

@ -73,7 +73,7 @@ namespace Aurora::HWInfo
size_t len = sizeof(info); size_t len = sizeof(info);
sysctl(mib, 2, &info, &len, NULL, 0); sysctl(mib, 2, &info, &len, NULL, 0);
return info; return info; // TODO: consider polling VM_UVMEXP
} }
#endif #endif
@ -93,9 +93,17 @@ namespace Aurora::HWInfo
#elif defined(AURORA_IS_BSD_DERIVED) #elif defined(AURORA_IS_BSD_DERIVED)
auto maxMem = QueryBsdHwStat(HW_PHYSMEM); #if defined(HW_PHYSMEM64)
uint64_t stat;
auto cmd = HW_PHYSMEM64;
#else
unsigned int stat;
auto cmd = HW_PHYSMEM;
#endif
auto maxMem = QueryBsdHwStat<decltype(stat)>(cmd);
auto vmInfo = GetVMInfo(); auto vmInfo = GetVMInfo();
auto freeMem = AuUInt64(vmInfo.t_free) * QueryBsdHwStat(HW_PAGESIZE).value_or(4096); auto freeMem = AuUInt64(vmInfo.t_free) * QueryBsdHwStat<unsigned int>(HW_PAGESIZE).value_or(4096);
return RamStat {maxMem.value_or(freeMem * 2) - freeMem, maxMem.value_or(0)}; return RamStat {maxMem.value_or(freeMem * 2) - freeMem, maxMem.value_or(0)};

View File

@ -10,5 +10,35 @@
namespace Aurora::Loop namespace Aurora::Loop
{ {
class Win32Dummy : public ILoopSource
{
public:
Win32Dummy()
{}
bool IsSignaled() override;
ELoopSource GetType() override;
};
bool Win32Dummy::IsSignaled()
{
return {};
}
ELoopSource Win32Dummy::GetType()
{
return ELoopSource::eSourceWin32;
}
AUKN_SYM AuSPtr<ILoopSource> NewLSWin32Source()
{
AuSPtr<ILoopSource> ret;
if (!(ret = AuMakeShared<Win32Dummy>()))
{
return {};
}
return ret;
}
} }

View File

@ -7,11 +7,111 @@
***/ ***/
#include <Source/RuntimeInternal.hpp> #include <Source/RuntimeInternal.hpp>
#include "Loop.NT.hpp" #include "Loop.NT.hpp"
#include "ILoopSourceEx.hpp"
namespace Aurora::Loop namespace Aurora::Loop
{ {
AUKN_SYM AuList<AuSPtr<ILoopSource>> WaitMultipleObjects(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout) AUKN_SYM AuList<AuSPtr<ILoopSource>> WaitMultipleOrObjects(const AuList<AuSPtr<ILoopSource>> &objects, AuUInt32 timeout)
{ {
return {}; bool isWinLoop;
AuList<AuSPtr<ILoopSourceEx>> loopSourceExs;
AuList<AuSPtr<ILoopSource>> triggered;
AuList<HANDLE> handleArray;
AuSPtr<ILoopSource> msgSource;
isWinLoop = false;
loopSourceExs.reserve(objects.size());
handleArray.reserve(objects.size());
triggered.reserve(triggered.size());
for (const auto &source : objects)
{
if (!source)
{
continue;
}
if (source->GetType() == ELoopSource::eSourceWin32)
{
isWinLoop = true;
msgSource = source;
continue;
}
if (auto extended = std::dynamic_pointer_cast<ILoopSourceEx>(source))
{
loopSourceExs.push_back(extended);
for (const auto &handle : extended->GetHandles())
{
auto nthandle = reinterpret_cast<HANDLE>(handle);
handleArray.push_back(nthandle);
}
}
}
for (const auto &source : loopSourceExs)
{
source->OnPresleep();
}
DWORD ret;
if (isWinLoop)
{
ret = ::MsgWaitForMultipleObjectsEx(handleArray.size(), handleArray.data(), timeout ? timeout : INFINITE, QS_ALLPOSTMESSAGE | QS_ALLINPUT | QS_ALLEVENTS, MWMO_INPUTAVAILABLE);
}
else
{
ret = ::WaitForMultipleObjectsEx(handleArray.size(), handleArray.data(), false, timeout ? timeout : INFINITE, true);
}
bool error = ((ret == WAIT_TIMEOUT) ||
(ret == WAIT_IO_COMPLETION) ||
(ret == WAIT_FAILED));
bool isPump = WAIT_OBJECT_0 + handleArray.size() == ret;
AuUInt firstTriggered {};
if (!error)
{
if (!isPump)
{
firstTriggered = reinterpret_cast<AuUInt>(handleArray[ret - WAIT_OBJECT_0]);
}
}
for (const auto &source : loopSourceExs)
{
if (!error)
{
AuUInt lastHandle {};
bool wasTriggered {};
for (const auto &handle : source->GetHandles())
{
if ((firstTriggered == handle) ||
(WaitForSingleObject(reinterpret_cast<HANDLE>(handle), 0) == WAIT_OBJECT_0))
{
lastHandle = handle;
wasTriggered = true;
continue;
}
}
if (source->OnTrigger(lastHandle, wasTriggered))
{
triggered.push_back(source);
}
}
source->OnFinishSleep();
}
if (isPump)
{
triggered.push_back(msgSource);
}
return triggered;
} }
} }

View File

@ -8,9 +8,9 @@ scripts into your applications build pipeline to get started.
## Features ## Features
- Lightweight threading primitives backed by OS specific backends - Lightweight threading and synchronization primitives
- Async threading primitives, including WaitMultipleObjects paradigm [WIP] - Async threading primitives, including WaitMultipleObjects paradigm [WIP]
- Async and regular IO abstraction - Asynchronous and synchronous IO abstraction
- Optional event driven async programming paradigm - Optional event driven async programming paradigm
- Console; graphical and standard; binary and UTF-8 logger - Console; graphical and standard; binary and UTF-8 logger
- Debug and Telementry; asserts, exception logging, fio, nio backends - Debug and Telementry; asserts, exception logging, fio, nio backends
@ -23,6 +23,7 @@ scripts into your applications build pipeline to get started.
- Compression - Compression
- Locale and encoding - Locale and encoding
- C++ utility templates and macros - C++ utility templates and macros
- Follows all strings are UTF-8 convention
## Links ## Links
@ -42,12 +43,14 @@ Aurora Overloadable Type Declerations: https://git.reece.sx/AuroraSupport/Aurora
## Logging ## Logging
Aurora Runtime does not attempt to implement your favourite production logger. We instead<br> Aurora Runtime does not attempt to implement your favourite production logger. We instead
implement a subscription based log message dispatcher with some default backends including<br> implement a subscription based log message dispatcher with some default backends including
a file logger, Windows debug logging, Windows conhost stdin/out using UTF-8, UNIX stdin/out<br> a file logger, Windows debug logging, Windows conhost stdin/out using UTF-8, UNIX stdin/out
respecting the applications codepage, a wxWidgets toolkit GUI, and hopefully more to come. <br> respecting the applications codepage, a wxWidgets toolkit GUI, and hopefully more to come.
Additionally, consoles that provide an input stream can be used in conjunction with the parse<br> Additionally, consoles that provide an input stream can be used in conjunction with the parse
subsystem to provide basic command-based deserialization, tokenization, and dispatch. subsystem to provide basic command-based deserialization, tokenization, and dispatch of UTF-8
translated strings regardless of the system locale
## Loop [WIP] ## Loop [WIP]