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

#ifdef WIN32

#include <ITAException.h>

#include <windows.h>

ITAWinPCClock* ITAWinPCClock::m_pInstance = NULL;

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

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

	m_dFrequency = (double) li.QuadPart;
}

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

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

36
37
__forceinline double ITAWinPCClock::getTime()
{
Jonas Stienen's avatar
Jonas Stienen committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
	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