AuroraRuntime/Include/Aurora/Time/StaticClocksClasses.hpp

109 lines
4.8 KiB
C++
Raw Normal View History

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: StaticClocksClasses.hpp
Date: 2023-07-07
Author: Reece
***/
#pragma once
namespace Aurora::Time
{
struct ClockBase
{
};
template <typename T = void>
struct Clock
{
};
#define AURT_ADD_CLOCK_A(name, oldClockType) \
struct Clock ## name : ClockBase \
{ \
static inline AuUInt64 GetCurrentTimeNS() \
{ \
return oldClockType ## ClockNS(); \
} \
\
static inline AuUInt64 GetCurrentTimeMS() \
{ \
return oldClockType ## ClockMS(); \
} \
\
static inline AuUInt64 GetFrequency() \
{ \
return oldClockType ## ClockJiffies(); \
} \
}; \
\
template <> \
struct Clock<Clock ## name> \
{ \
static inline AuUInt64 GetCurrentTimeNS() \
{ \
return Clock## name::GetCurrentTimeNS(); \
} \
\
static inline AuUInt64 GetCurrentTimeMS() \
{ \
return Clock ## name::GetCurrentTimeMS(); \
} \
\
static inline AuUInt64 GetFrequency() \
{ \
return Clock ## name::GetFrequency(); \
} \
};
#define AURT_ADD_CLOCK_B(name, oldClockType) \
struct Clock ## name : ClockBase \
{ \
static inline AuUInt64 GetCurrentTimeNS() \
{ \
return oldClockType ## ClockNS(); \
} \
\
static inline AuUInt64 GetCurrentTimeMS() \
{ \
return oldClockType ## ClockMS(); \
} \
\
static inline AuUInt64 GetFrequency() \
{ \
return 1000; \
} \
}; \
\
template <> \
struct Clock<Clock ## name> \
{ \
static inline AuUInt64 GetCurrentTimeNS() \
{ \
return Clock## name::GetCurrentTimeNS(); \
} \
\
static inline AuUInt64 GetCurrentTimeMS() \
{ \
return Clock ## name::GetCurrentTimeMS(); \
} \
\
static inline AuUInt64 GetFrequency() \
{ \
return Clock ## name::GetFrequency(); \
} \
};
AURT_ADD_CLOCK_B(Wall, Current);
AURT_ADD_CLOCK_A(Steady, Steady);
AURT_ADD_CLOCK_A(ProcessTime, Process);
AURT_ADD_CLOCK_A(ProcessKernelTime, ProcessKernel);
AURT_ADD_CLOCK_A(ProcessUserTime, ProcessUser);
AURT_ADD_CLOCK_A(ThreadTime, Thread);
AURT_ADD_CLOCK_A(ThreadKernelTime, ThreadKernel);
AURT_ADD_CLOCK_A(ThreadUserTime, ThreadUser);
#undef AURT_ADD_CLOCK_A
}