Qt 4.8
Typedefs | Functions | Variables
qelapsedtimer_win.cpp File Reference
#include "qelapsedtimer.h"
#include <windows.h>
#include <private/qsystemlibrary_p.h>

Go to the source code of this file.

Typedefs

typedef ULONGLONG(WINAPI * PtrGetTickCount64) (void)
 

Functions

static quint64 getTickCount ()
 
bool operator< (const QElapsedTimer &v1, const QElapsedTimer &v2)
 
static void resolveLibs ()
 
static qint64 ticksToNanoseconds (qint64 ticks)
 

Variables

static quint64 counterFrequency = 0
 
static PtrGetTickCount64 ptrGetTickCount64 = 0
 

Typedef Documentation

◆ PtrGetTickCount64

typedef ULONGLONG(WINAPI * PtrGetTickCount64) (void)

Definition at line 47 of file qelapsedtimer_win.cpp.

Function Documentation

◆ getTickCount()

static quint64 getTickCount ( )
static

Definition at line 93 of file qelapsedtimer_win.cpp.

94 {
95  resolveLibs();
96 
97  // This avoids a division by zero and disables the high performance counter if it's not available
98  if (counterFrequency > 0) {
99  LARGE_INTEGER counter;
100 
101  if (QueryPerformanceCounter(&counter)) {
102  return counter.QuadPart;
103  } else {
104  qWarning("QueryPerformanceCounter failed, although QueryPerformanceFrequency succeeded.");
105  return 0;
106  }
107  }
108 
109  if (ptrGetTickCount64)
110  return ptrGetTickCount64();
111 
112  static quint32 highdword = 0;
113  static quint32 lastval = 0;
114  quint32 val = GetTickCount();
115  if (val < lastval)
116  ++highdword;
117  lastval = val;
118  return val | (quint64(highdword) << 32);
119 }
static quint64 counterFrequency
unsigned __int64 quint64
Definition: qglobal.h:943
Q_CORE_EXPORT void qWarning(const char *,...)
static void resolveLibs()
static PtrGetTickCount64 ptrGetTickCount64
unsigned int quint32
Definition: qglobal.h:938

◆ operator<()

bool operator< ( const QElapsedTimer v1,
const QElapsedTimer v2 
)

Definition at line 178 of file qelapsedtimer_win.cpp.

179 {
180  return (v1.t1 - v2.t1) < 0;
181 }

◆ resolveLibs()

static void resolveLibs ( )
static

Definition at line 55 of file qelapsedtimer_win.cpp.

Referenced by QFileSystemEngine::fillPermissions(), getTickCount(), isDirPath(), QFileSystemEngine::owner(), and readSymLink().

56 {
57  static volatile bool done = false;
58  if (done)
59  return;
60 
61  // try to get GetTickCount64 from the system
62  QSystemLibrary kernel32(QLatin1String("kernel32"));
63  if (!kernel32.load())
64  return;
65 
66  // does this function exist on WinCE, or will ever exist?
67  ptrGetTickCount64 = (PtrGetTickCount64)kernel32.resolve("GetTickCount64");
68 
69  // Retrieve the number of high-resolution performance counter ticks per second
70  LARGE_INTEGER frequency;
71  if (!QueryPerformanceFrequency(&frequency)) {
72  counterFrequency = 0;
73  } else {
74  counterFrequency = frequency.QuadPart;
75  }
76 
77  done = true;
78 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static quint64 counterFrequency
ULONGLONG(WINAPI * PtrGetTickCount64)(void)
static PtrGetTickCount64 ptrGetTickCount64

◆ ticksToNanoseconds()

static qint64 ticksToNanoseconds ( qint64  ticks)
inlinestatic

Definition at line 80 of file qelapsedtimer_win.cpp.

Referenced by getTickCount().

81 {
82  if (counterFrequency > 0) {
83  // QueryPerformanceCounter uses an arbitrary frequency
84  qint64 seconds = ticks / counterFrequency;
85  qint64 nanoSeconds = (ticks - seconds * counterFrequency) * 1000000000 / counterFrequency;
86  return seconds * 1000000000 + nanoSeconds;
87  } else {
88  // GetTickCount(64) return milliseconds
89  return ticks * 1000000;
90  }
91 }
static quint64 counterFrequency
__int64 qint64
Definition: qglobal.h:942

Variable Documentation

◆ counterFrequency

quint64 counterFrequency = 0
static

Definition at line 53 of file qelapsedtimer_win.cpp.

Referenced by getTickCount(), resolveLibs(), and ticksToNanoseconds().

◆ ptrGetTickCount64

PtrGetTickCount64 ptrGetTickCount64 = 0
static

Definition at line 48 of file qelapsedtimer_win.cpp.

Referenced by getTickCount(), and resolveLibs().