27 #include "precompiled.h"
72 static size_t nextCounterId = 0;
118 ENSURE(resolution <= 2e-3);
205 ts = (
volatile TimerState*)InterlockedExchangePointer((
volatile PVOID*)&
ts2, (PVOID)
ts);
212 const double time = state->
time;
246 const DWORD ret = WaitForSingleObject(hExitEvent, UPDATE_INTERVAL_MS);
248 if(ret != WAIT_TIMEOUT)
264 const size_t rolloversPerInterval = size_t(UPDATE_INTERVAL_MS /
i64(period_2*2.0*1000.0));
265 ENSURE(rolloversPerInterval <= 1);
267 hExitEvent = CreateEvent(0, TRUE, FALSE, 0);
268 if(hExitEvent == INVALID_HANDLE_VALUE)
281 BOOL ok = SetEvent(hExitEvent);
284 if(WaitForSingleObject(hUpdateThread, 100) != WAIT_OBJECT_0)
285 TerminateThread(hUpdateThread, 0);
286 CloseHandle(hExitEvent);
287 CloseHandle(hUpdateThread);
#define WINIT_REGISTER_LATE_SHUTDOWN(func)
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
virtual Status Activate()=0
static __declspec(align(64)) TimerState timerStates[2]
static void ShutdownUpdateThread()
some WinAPI functions SetLastError(0) on success, which is bad because it can hide previous errors...
static ICounter * counter
static void UpdateTimerState()
static unsigned __stdcall UpdateThread(void *data)
static HANDLE hUpdateThread
static const DWORD UPDATE_INTERVAL_MS
LIB_API void debug_SetThreadName(const char *name)
inform the debugger of the current thread's name.
virtual double NominalFrequency() const =0
initial measurement of the tick rate.
virtual const wchar_t * Name() const =0
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
virtual double Resolution() const =0
actual resolution [s].
static void InitCounter()
static size_t counterBits
void acpi_Shutdown()
invalidates all pointers returned by acpi_GetTable.
const Status WHRT_COUNTER_UNSAFE
i64 Status
Error handling system.
static Status whrt_Shutdown()
static u64 CounterDelta(u64 oldCounter, u64 newCounter)
static Status ActivateCounter(ICounter *counter)
static double nominalFrequency
wchar_t * StatusDescription(Status status, wchar_t *buf, size_t max_chars)
generate textual description of a Status.
#define WARN_IF_FALSE(expression)
#define WARN_RETURN(status)
virtual u64 Counter() const =0
static ICounter * GetNextBestSafeCounter()
static Status InitUpdateThread()
static void ShutdownCounter()
void DestroyCounter(ICounter *&counter)
shut down the counter, free its resources and zero its pointer.
stores all timer state shared between readers and the update thread.
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).
virtual bool IsSafe() const =0
static volatile TimerState *volatile ts
static Status whrt_Init()
virtual size_t CounterBits() const =0
#define RETURN_STATUS_IF_ERR(expression)
#define WINIT_REGISTER_EARLY_INIT2(func)
ICounter * CreateCounter(size_t id)
static volatile TimerState *volatile ts2