- static mtime_t freq = INT64_C(-1);
-
- if( freq == INT64_C(-1) )
- {
- /* Extract from the Tcl source code:
- * (http://www.cs.man.ac.uk/fellowsd-bin/TIP/7.html)
- *
- * Some hardware abstraction layers use the CPU clock
- * in place of the real-time clock as a performance counter
- * reference. This results in:
- * - inconsistent results among the processors on
- * multi-processor systems.
- * - unpredictable changes in performance counter frequency
- * on "gearshift" processors such as Transmeta and
- * SpeedStep.
- * There seems to be no way to test whether the performance
- * counter is reliable, but a useful heuristic is that
- * if its frequency is 1.193182 MHz or 3.579545 MHz, it's
- * derived from a colorburst crystal and is therefore
- * the RTC rather than the TSC. If it's anything else, we
- * presume that the performance counter is unreliable.
- */
- LARGE_INTEGER buf;
-
- freq = ( QueryPerformanceFrequency( &buf ) &&
- (buf.QuadPart == INT64_C(1193182) || buf.QuadPart == INT64_C(3579545) ) )
- ? buf.QuadPart : 0;
-
-#if defined( WIN32 )
- /* on windows 2000, XP and Vista detect if there are two
- cores there - that makes QueryPerformanceFrequency in
- any case not trustable?
- (may also be true, for single cores with adaptive
- CPU frequency and active power management?)
- */
- HINSTANCE h_Kernel32 = LoadLibrary(_T("kernel32.dll"));
- if(h_Kernel32)
- {
- void WINAPI (*pf_GetSystemInfo)(LPSYSTEM_INFO);
- pf_GetSystemInfo = (void WINAPI (*)(LPSYSTEM_INFO))
- GetProcAddress(h_Kernel32, _T("GetSystemInfo"));
- if(pf_GetSystemInfo)
- {
- SYSTEM_INFO system_info;
- pf_GetSystemInfo(&system_info);
- if(system_info.dwNumberOfProcessors > 1)
- freq = 0;
- }
- FreeLibrary(h_Kernel32);
- }
-#endif
- }