Files
fastfetch/src/common/time.h
T

39 lines
893 B
C
Raw Normal View History

#pragma once
#ifndef FF_INCLUDED_common_time
#define FF_INCLUDED_common_time
#include <stdint.h>
2022-10-14 16:39:48 +08:00
#ifdef _WIN32
#include <synchapi.h>
2022-12-14 15:40:32 +08:00
#include <profileapi.h>
#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);
#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));
#endif
}
static inline void ffTimeSleep(uint32_t msec)
{
2022-10-14 16:39:48 +08:00
#ifdef _WIN32
SleepEx(msec, TRUE);
#else
nanosleep(&(struct timespec){ msec / 1000, (msec % 1000) * 1000000 }, NULL);
#endif
}
#endif