From 529eba18c78858541da934ecbd176dd97db339f7 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Fri, 13 Oct 2023 21:43:59 +0100 Subject: [PATCH] [+] IAuroraThread::GetThreadCreationTime --- .../Threading/Threads/IAuroraThread.hpp | 7 ++++ Source/Threading/Threads/AuOSThread.cpp | 32 +++++++++++++++++++ Source/Threading/Threads/AuOSThread.hpp | 5 +++ 3 files changed, 44 insertions(+) diff --git a/Include/Aurora/Threading/Threads/IAuroraThread.hpp b/Include/Aurora/Threading/Threads/IAuroraThread.hpp index 3e129868..51956c6f 100644 --- a/Include/Aurora/Threading/Threads/IAuroraThread.hpp +++ b/Include/Aurora/Threading/Threads/IAuroraThread.hpp @@ -17,6 +17,8 @@ namespace Aurora::HWInfo struct CpuBitId; } +#include + namespace Aurora::Threading::Threads { struct TLSView; @@ -52,6 +54,11 @@ namespace Aurora::Threading::Threads virtual HWInfo::CpuBitId GetMask() = 0; virtual AuString GetName() = 0; + + virtual AuUInt64 GetThreadCreationTime(Time::EClock eClock) = 0; + + // TODO: will deprecate with a version that does call init on thread and deinit on deinit + // ... just wait for it /// Registers a thread feature _not_ calling on init /// It is not possible for this lower level thread object to schedule an init call (defer to async) /// Use this to register teardown functions diff --git a/Source/Threading/Threads/AuOSThread.cpp b/Source/Threading/Threads/AuOSThread.cpp index 6ccd82ad..0f53c6e4 100644 --- a/Source/Threading/Threads/AuOSThread.cpp +++ b/Source/Threading/Threads/AuOSThread.cpp @@ -90,6 +90,8 @@ namespace Aurora::Threading::Threads this->terminateSignal_ = AuThreadPrimitives::EventShared(true, false, true); SysAssert(this->terminatedSignalLs_ && this->terminateSignalLs_ && this->terminated_ && this->terminateSignal_); + + this->InitThreadCreateTime(); } OSThread::OSThread() : info_(gDummyThreadInfo), @@ -102,6 +104,8 @@ namespace Aurora::Threading::Threads SysAssert(this->terminated_ && this->terminateSignal_); this->bNotOwned = true; + + this->InitThreadCreateTime(); } OSThread::OSThread(AuUInt64 id) : info_(gDummyThreadInfo), @@ -551,6 +555,32 @@ namespace Aurora::Threading::Threads void AttachSignalKiller(); + void OSThread::InitThreadCreateTime() + { + uClockCreationTime[0] = AuTime::CurrentClockNS(); + uClockCreationTime[1] = AuTime::SteadyClockNS(); + } + + AuUInt64 OSThread::GetThreadCreationTime(Time::EClock eClock) + { + if (AuTime::EClockIsValid(eClock)) + { + SysPushErrorArg(); + return {}; + } + + switch (eClock) + { + case Time::EClock::eWall: + return uClockCreationTime[0]; + case Time::EClock::eSteady: + return uClockCreationTime[1]; + default: + SysPushErrorArg(); + return {}; + } + } + void OSThread::_ThreadEP() { // Poke TLS reference thread entity @@ -577,6 +607,8 @@ namespace Aurora::Threading::Threads auto pA = this->terminatedSignalLs_; auto pB = this->terminated_; + this->InitThreadCreateTime(); + try { if (auto task = task_) diff --git a/Source/Threading/Threads/AuOSThread.hpp b/Source/Threading/Threads/AuOSThread.hpp index eac4a9dd..a400b0d9 100644 --- a/Source/Threading/Threads/AuOSThread.hpp +++ b/Source/Threading/Threads/AuOSThread.hpp @@ -47,6 +47,10 @@ namespace Aurora::Threading::Threads void Detach() override; + AuUInt64 GetThreadCreationTime(Time::EClock eClock) override; + + void InitThreadCreateTime(); + void _ThreadEP(); AuSPtr AsLoopSource() override; AuSPtr GetShutdownSignalWaitable() override; @@ -108,6 +112,7 @@ namespace Aurora::Threading::Threads Primitives::CriticalSection exitOnlyOnce_; AuList> threadFeatures_; AuBinarySemaphore epExecEvent; + AuUInt64 uClockCreationTime[2] {}; AuFunction task_;