[+] IAuroraThread::GetThreadCreationTime

This commit is contained in:
Reece Wilson 2023-10-13 21:43:59 +01:00
parent be60d2c80d
commit 529eba18c7
3 changed files with 44 additions and 0 deletions

View File

@ -17,6 +17,8 @@ namespace Aurora::HWInfo
struct CpuBitId;
}
#include <Aurora/Time/EClock.hpp>
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

View File

@ -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_)

View File

@ -47,6 +47,10 @@ namespace Aurora::Threading::Threads
void Detach() override;
AuUInt64 GetThreadCreationTime(Time::EClock eClock) override;
void InitThreadCreateTime();
void _ThreadEP();
AuSPtr<AuLoop::ILoopSource> AsLoopSource() override;
AuSPtr<IWaitable> GetShutdownSignalWaitable() override;
@ -108,6 +112,7 @@ namespace Aurora::Threading::Threads
Primitives::CriticalSection exitOnlyOnce_;
AuList<AuSPtr<IThreadFeature>> threadFeatures_;
AuBinarySemaphore epExecEvent;
AuUInt64 uClockCreationTime[2] {};
AuFunction<void()> task_;