Win32: use high resolution timers (QueryPerformanceCounter) if available
This commit is contained in:
@@ -71,14 +71,31 @@ static clockid_t getClockId()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
static bool qpc_init = false;
|
||||||
|
static LARGE_INTEGER s_frequency;
|
||||||
|
static BOOL s_use_qpc;
|
||||||
|
|
||||||
void SGTimeStamp::stamp()
|
void SGTimeStamp::stamp()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
unsigned int t;
|
if (!qpc_init) {
|
||||||
t = timeGetTime();
|
s_use_qpc = QueryPerformanceFrequency(&s_frequency);
|
||||||
_sec = t / 1000;
|
qpc_init = true;
|
||||||
_nsec = ( t - ( _sec * 1000 ) ) * 1000 * 1000;
|
}
|
||||||
|
if (qpc_init && s_use_qpc) {
|
||||||
|
LARGE_INTEGER now;
|
||||||
|
QueryPerformanceCounter(&now);
|
||||||
|
_sec = now.QuadPart / s_frequency.QuadPart;
|
||||||
|
_nsec = (1000000000LL * (now.QuadPart - _sec * s_frequency.QuadPart)) / s_frequency.QuadPart;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unsigned int t;
|
||||||
|
|
||||||
|
t = timeGetTime();
|
||||||
|
_sec = t / 1000;
|
||||||
|
_nsec = (t - (_sec * 1000)) * 1000 * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(_POSIX_TIMERS) && (0 < _POSIX_TIMERS)
|
#elif defined(_POSIX_TIMERS) && (0 < _POSIX_TIMERS)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(getClockId(), &ts);
|
clock_gettime(getClockId(), &ts);
|
||||||
|
|||||||
Reference in New Issue
Block a user