mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-21 21:17:19 +00:00
[common] time: prevent possible div by zero on windows
This commit is contained in:
parent
96b5892c31
commit
7bea919352
@ -39,13 +39,19 @@ typedef struct LGTimer LGTimer;
|
|||||||
static inline uint64_t microtime(void)
|
static inline uint64_t microtime(void)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static LARGE_INTEGER freq = { .QuadPart = 0LL };
|
static unsigned long div = 0;
|
||||||
if (!freq.QuadPart)
|
if (div == 0)
|
||||||
|
{
|
||||||
|
LARGE_INTEGER freq = { .QuadPart = 0LL };
|
||||||
QueryPerformanceFrequency(&freq);
|
QueryPerformanceFrequency(&freq);
|
||||||
|
div = freq.QuadPart / 1000000LL;
|
||||||
|
if(div == 0)
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
LARGE_INTEGER time;
|
LARGE_INTEGER time;
|
||||||
QueryPerformanceCounter(&time);
|
QueryPerformanceCounter(&time);
|
||||||
return time.QuadPart / (freq.QuadPart / 1000000LL);
|
return time.QuadPart / div;
|
||||||
#else
|
#else
|
||||||
struct timespec time;
|
struct timespec time;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &time);
|
clock_gettime(CLOCK_MONOTONIC, &time);
|
||||||
@ -76,6 +82,9 @@ static inline uint64_t nanotime(void)
|
|||||||
{
|
{
|
||||||
LARGE_INTEGER freq = { .QuadPart = 0LL };
|
LARGE_INTEGER freq = { .QuadPart = 0LL };
|
||||||
QueryPerformanceFrequency(&freq);
|
QueryPerformanceFrequency(&freq);
|
||||||
|
if (freq.QuadPart == 0)
|
||||||
|
abort();
|
||||||
|
|
||||||
multiplier = 1e9 / freq.QuadPart;
|
multiplier = 1e9 / freq.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user