147 DWORD total_cycles=0, cycles;
148 DWORD stamp0, stamp1;
149 DWORD total_ticks=0, ticks;
151 LARGE_INTEGER count_freq;
154 if ( !QueryPerformanceFrequency(&count_freq) )
return(0);
157 HANDLE process = GetCurrentProcess();
158 DWORD processPri = GetPriorityClass(process);
159 SetPriorityClass(process, REALTIME_PRIORITY_CLASS);
161 HANDLE thread = GetCurrentThread();
162 int threadPri = GetThreadPriority(thread);
163 SetThreadPriority(thread, THREAD_PRIORITY_TIME_CRITICAL);
187 QueryPerformanceCounter(&t0);
189 t1.LowPart = t0.LowPart;
190 t1.HighPart = t0.HighPart;
196 while ( (
DWORD)t1.LowPart - (
DWORD)t0.LowPart<50) {
197 QueryPerformanceCounter(&t1);
203 t0.LowPart = t1.LowPart;
204 t0.HighPart = t1.HighPart;
210 while ( (
DWORD)t1.LowPart - (
DWORD)t0.LowPart < 1000 ) {
211 QueryPerformanceCounter(&t1);
218 cycles = stamp1 - stamp0;
220 double bigticks = (double)((
DWORD)t1.LowPart - (
DWORD)t0.LowPart);
221 assert((bigticks * 100000.0) > bigticks);
222 bigticks = bigticks * 100000.0;
224 ticks = (
DWORD)(bigticks / (
double)(count_freq.LowPart / 10));
228 total_ticks += ticks;
229 total_cycles += cycles;
230 if ( (ticks % count_freq.LowPart) > (count_freq.LowPart/2) ) ticks++;
234 if ( cycles%ticks > ticks/2 ) freq++;
236 total = ( freq + freq2 + freq3 );
238 }
while ( (tries < 3 ) || (tries < 20) && ((abs(3 * freq -total) > 3*
TOLERANCE )|| (abs(3 * freq2-total) > 3*
TOLERANCE )|| (abs(3 * freq3-total) > 3*
TOLERANCE )));
240 SetThreadPriority(thread, threadPri);
241 SetPriorityClass(process, processPri);
246 freq3 = ( total_cycles * 10 ) / total_ticks;
247 freq2 = ( total_cycles * 100 ) / total_ticks;
251 int norm_freq = total_cycles / total_ticks;
253 freq = norm_freq * 10;