16# define WIN32_LEAN_AND_MEAN
24 static int hasperfcounter = -1;
25 static double perffreq;
27 if (hasperfcounter == -1) {
29 hasperfcounter = QueryPerformanceFrequency((LARGE_INTEGER *)&ifreq);
30 perffreq = double(ifreq);
36 QueryPerformanceCounter((LARGE_INTEGER *)&
count);
38 return count / perffreq;
41 static double accum = 0.0;
43 int ntick = GetTickCount();
46 accum += (0xFFFFFFFF - ltick + ntick) / 1000.0;
49 accum += (ntick - ltick) / 1000.0;
71 HANDLE timerHandle = CreateWaitableTimerExW(
72 nullptr,
nullptr, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
74 if (GetLastError() == ERROR_INVALID_PARAMETER) {
76 DWORD duration_ms = DWORD(std::ceil(
double(us) / 1000.0));
81 "BLI_time_sleep_precise_us: CreateWaitableTimerExW failed: %d\n",
88 LARGE_INTEGER wait_time;
89 wait_time.QuadPart = -us * 10;
90 if (!SetWaitableTimer(timerHandle, &wait_time, 0,
nullptr,
nullptr, 0)) {
91 fprintf(stderr,
"BLI_time_sleep_precise_us: SetWaitableTimer failed: %d\n", GetLastError());
92 CloseHandle(timerHandle);
96 if (WaitForSingleObject(timerHandle, INFINITE) != WAIT_OBJECT_0) {
97 fprintf(stderr,
"BLI_time_sleep_precise_us: WaitForSingleObject failed: %d\n", GetLastError());
98 CloseHandle(timerHandle);
102 CloseHandle(timerHandle);
110# include <sys/time.h>
118 gettimeofday(&tv, &tz);
120 return (
double(tv.tv_sec) + tv.tv_usec / 1000000.0);
128 gettimeofday(&tv, &tz);
145 std::this_thread::sleep_for(std::chrono::microseconds(us));
Platform independent time functions.
void BLI_time_sleep_ms(int ms)
double BLI_time_now_seconds()
long int BLI_time_now_seconds_i()
void BLI_time_sleep_precise_us(int us)