[+] Added first attempt at the windows version of WaitMultipleObjects/ This will be removed shortly.
[*] Update readme [*] Update QueryBsdHwStat
This commit is contained in:
parent
6888aaaee7
commit
d18affeea2
@ -45,7 +45,7 @@ namespace Aurora::Loop
|
||||
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
|
||||
{
|
||||
|
@ -17,11 +17,12 @@
|
||||
|
||||
namespace Aurora::HWInfo
|
||||
{
|
||||
AuOptional<AuUInt> QueryBsdHwStat(int id)
|
||||
template<typename T>
|
||||
AuOptional<T> QueryBsdHwStat(int id)
|
||||
{
|
||||
#if defined(AURORA_IS_BSD_DERIVED)
|
||||
int mib[4];
|
||||
AuUInt stat;
|
||||
T stat;
|
||||
size_t len = sizeof(stat);
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
@ -33,6 +34,15 @@ namespace Aurora::HWInfo
|
||||
return {};
|
||||
#endif
|
||||
}
|
||||
|
||||
template<>
|
||||
AuOptional<AuUInt> QueryBsdHwStat(int id);
|
||||
|
||||
template<>
|
||||
AuOptional<unsigned int> QueryBsdHwStat(int id);
|
||||
|
||||
template<>
|
||||
AuOptional<uint64_t> QueryBsdHwStat(int id);
|
||||
|
||||
void Init()
|
||||
{
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
namespace Aurora::HWInfo
|
||||
{
|
||||
AuOptional<AuUInt> QueryBsdHwStat(int id);
|
||||
template<typename T>
|
||||
AuOptional<T> QueryBsdHwStat(int id);
|
||||
void Init();
|
||||
}
|
@ -73,7 +73,7 @@ namespace Aurora::HWInfo
|
||||
size_t len = sizeof(info);
|
||||
sysctl(mib, 2, &info, &len, NULL, 0);
|
||||
|
||||
return info;
|
||||
return info; // TODO: consider polling VM_UVMEXP
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -93,9 +93,17 @@ namespace Aurora::HWInfo
|
||||
|
||||
#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 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)};
|
||||
|
||||
|
@ -10,5 +10,35 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -7,11 +7,111 @@
|
||||
***/
|
||||
#include <Source/RuntimeInternal.hpp>
|
||||
#include "Loop.NT.hpp"
|
||||
#include "ILoopSourceEx.hpp"
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
19
readme.md
19
readme.md
@ -8,9 +8,9 @@ scripts into your applications build pipeline to get started.
|
||||
|
||||
## Features
|
||||
|
||||
- Lightweight threading primitives backed by OS specific backends
|
||||
- Lightweight threading and synchronization primitives
|
||||
- Async threading primitives, including WaitMultipleObjects paradigm [WIP]
|
||||
- Async and regular IO abstraction
|
||||
- Asynchronous and synchronous IO abstraction
|
||||
- Optional event driven async programming paradigm
|
||||
- Console; graphical and standard; binary and UTF-8 logger
|
||||
- Debug and Telementry; asserts, exception logging, fio, nio backends
|
||||
@ -23,6 +23,7 @@ scripts into your applications build pipeline to get started.
|
||||
- Compression
|
||||
- Locale and encoding
|
||||
- C++ utility templates and macros
|
||||
- Follows all strings are UTF-8 convention
|
||||
|
||||
## Links
|
||||
|
||||
@ -42,12 +43,14 @@ Aurora Overloadable Type Declerations: https://git.reece.sx/AuroraSupport/Aurora
|
||||
|
||||
## Logging
|
||||
|
||||
Aurora Runtime does not attempt to implement your favourite production logger. We instead<br>
|
||||
implement a subscription based log message dispatcher with some default backends including<br>
|
||||
a file logger, Windows debug logging, Windows conhost stdin/out using UTF-8, UNIX stdin/out<br>
|
||||
respecting the applications codepage, a wxWidgets toolkit GUI, and hopefully more to come. <br>
|
||||
Additionally, consoles that provide an input stream can be used in conjunction with the parse<br>
|
||||
subsystem to provide basic command-based deserialization, tokenization, and dispatch.
|
||||
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
|
||||
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.
|
||||
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 of UTF-8
|
||||
translated strings regardless of the system locale
|
||||
|
||||
|
||||
## Loop [WIP]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user