Thursday, July 1, 2010

uSleep on windows (win32)

I am facing a terrible issue regarding timing on windows.

Googling arround, I've found those infos:

Using QueryPerformanceCounter and QueryPerformanceFrequency APIs in Dev-C++
QueryPerformanceCounter() vs. GetTickCount()
How to time a block of code
And Results of some quick research on timing in Win32

With that I'm trying to write something like a uSleep function for windows:


void uSleep(int waitTime){
__int64 time1 = 0, time2 = 0, sysFreq = 0;

QueryPerformanceCounter((LARGE_INTEGER *)&time1);
QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
QueryPerformanceCounter((LARGE_INTEGER *)&time2);

// }while((((time2-time1)*1.0)/sysFreq)<waitTime);
}while( (time2-time1) <waitTime);

There is also already a nanosleep at:
and a usleep at MKSToolkit at:

No comments:

Post a Comment