0ad/source/lib/sysdep/win/whrt/tick_source.h
janwas c45ef68a88 add work-in-progress WHRT (win high res timer). works well enough, but calibration is not yet complete nor is TSC usable.
cpu: accessor functions ensure what they return is valid. no longer
needs to call wtime_reset_impl (ugh). uses ModuleInitState.
ia32: add APIC ID accessor and prevent redundant init

This was SVN commit r5093.
2007-05-26 16:57:39 +00:00

58 lines
1.3 KiB
C++

/**
* =========================================================================
* File : tick_source.h
* Project : 0 A.D.
* Description : Interface for timer implementations
* =========================================================================
*/
// license: GPL; see lib/license.txt
#ifndef INCLUDED_TICK_SOURCE
#define INCLUDED_TICK_SOURCE
class TickSourceUnavailable : public std::runtime_error
{
public:
TickSourceUnavailable(const std::string& msg)
: std::runtime_error(msg)
{
}
};
class TickSource
{
public:
TickSource() {}
virtual ~TickSource() {}
virtual bool IsSafe() const = 0;
virtual const char* Name() const = 0;
virtual u64 Ticks() const = 0;
/**
* WHRT uses this to ensure the counter (running at nominal frequency)
* doesn't overflow more than once during CALIBRATION_INTERVAL_MS.
**/
virtual uint CounterBits() const = 0;
/**
* initial measurement of the tick rate. not necessarily correct
* (e.g. when using TSC: cpu_ClockFrequency isn't exact).
**/
virtual double NominalFrequency() const = 0;
/**
* actual resolution [s]
* (override if the timer adjustment is greater than 1 tick).
**/
virtual double Resolution() const
{
return 1.0 / NominalFrequency();
}
};
#endif // #ifndef INCLUDED_TICK_SOURCE