2022-10-07 19:02:27 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2022-10-14 16:39:48 +08:00
|
|
|
#ifdef _WIN32
|
2022-10-07 19:02:27 +08:00
|
|
|
#include <synchapi.h>
|
2022-12-14 15:40:32 +08:00
|
|
|
#include <profileapi.h>
|
2023-09-12 14:50:38 +08:00
|
|
|
#include <sysinfoapi.h>
|
2022-10-07 19:02:27 +08:00
|
|
|
#else
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static inline uint64_t ffTimeGetTick() //In msec
|
|
|
|
|
{
|
2022-10-14 16:39:48 +08:00
|
|
|
#ifdef _WIN32
|
2022-12-14 15:40:32 +08:00
|
|
|
LARGE_INTEGER frequency;
|
|
|
|
|
QueryPerformanceFrequency(&frequency);
|
|
|
|
|
LARGE_INTEGER start;
|
|
|
|
|
QueryPerformanceCounter(&start);
|
|
|
|
|
return (uint64_t)(start.QuadPart * 1000 / frequency.QuadPart);
|
2022-10-07 19:02:27 +08:00
|
|
|
#else
|
2022-12-14 15:40:32 +08:00
|
|
|
struct timespec timeNow;
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &timeNow);
|
|
|
|
|
return (uint64_t)((timeNow.tv_sec * 1000) + (timeNow.tv_nsec / 1000000));
|
2022-10-07 19:02:27 +08:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 14:50:38 +08:00
|
|
|
static inline uint64_t ffTimeGetNow()
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
uint64_t timeNow;
|
|
|
|
|
GetSystemTimeAsFileTime((FILETIME*) &timeNow);
|
|
|
|
|
return (timeNow - 116444736000000000ull) / 10000ull;
|
|
|
|
|
#else
|
|
|
|
|
struct timespec timeNow;
|
|
|
|
|
clock_gettime(CLOCK_REALTIME, &timeNow);
|
|
|
|
|
return (uint64_t)((timeNow.tv_sec * 1000) + (timeNow.tv_nsec / 1000000));
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-07 19:02:27 +08:00
|
|
|
static inline void ffTimeSleep(uint32_t msec)
|
|
|
|
|
{
|
2022-10-14 16:39:48 +08:00
|
|
|
#ifdef _WIN32
|
2022-10-07 19:02:27 +08:00
|
|
|
SleepEx(msec, TRUE);
|
|
|
|
|
#else
|
2024-01-17 23:12:55 +08:00
|
|
|
nanosleep(&(struct timespec){ msec / 1000, (long) (msec % 1000) * 1000000 }, NULL);
|
2022-10-07 19:02:27 +08:00
|
|
|
#endif
|
|
|
|
|
}
|