ITAWinPCClock.cpp 1.19 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1
2
3
4
5
6
7
8
9
10
11
#include <ITAWinPCClock.h>

#ifdef WIN32

#include <ITAException.h>

#define _WIN32_WINNT 0x0500 
#include <windows.h>

ITAWinPCClock* ITAWinPCClock::m_pInstance = NULL;

12
13
ITAWinPCClock* ITAWinPCClock::getInstance()
{
Jonas Stienen's avatar
Jonas Stienen committed
14
15
16
17
	if (!m_pInstance) m_pInstance = new ITAWinPCClock();
	return m_pInstance;
}

18
19
ITAWinPCClock::ITAWinPCClock()
{
Jonas Stienen's avatar
Jonas Stienen committed
20
21
22
23
24
25
26
	LARGE_INTEGER li;
	if (!QueryPerformanceFrequency(&li))
		ITA_EXCEPT1(UNKNOWN, "Failed to query the Windows performance counter frequency");

	m_dFrequency = (double) li.QuadPart;
}

27
28
double ITAWinPCClock::getResolution() const
{
Jonas Stienen's avatar
Jonas Stienen committed
29
30
31
	return 1/m_dFrequency;
}

32
33
double ITAWinPCClock::getFrequency() const
{
Jonas Stienen's avatar
Jonas Stienen committed
34
35
36
	return m_dFrequency;
}

37
38
__forceinline double ITAWinPCClock::getTime()
{
Jonas Stienen's avatar
Jonas Stienen committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	LARGE_INTEGER li;
	QueryPerformanceCounter(&li);
	return ((double) li.QuadPart) / m_dFrequency;
}

#else // WIN32

// Dummy implementation - does nothing, but allows clean compiling and linking

ITAWinPCClock* ITAWinPCClock::m_pInstance = NULL;

ITAWinPCClock* ITAWinPCClock::getInstance() { return NULL; }
ITAWinPCClock::ITAWinPCClock() {}
double ITAWinPCClock::getResolution() const { return 0; }
double ITAWinPCClock::getFrequency() const { return 0; }
double ITAWinPCClock::getTime() { return 0; }

#endif // WIN32