Commit 84a2bb32 authored by Deucе's avatar Deucе 👌🏾
Browse files

Add xp_timer64()

This is a millisecond timer that tries to avoid floating-point
operations.
parent ab673a5c
Pipeline #2716 failed with stage
in 5 minutes and 6 seconds
......@@ -825,6 +825,42 @@ long double xp_timer(void)
return(ret);
}
/****************************************************************************/
/* Returns the current value of the systems best timer (in MILLISECONDS) */
/* Any value < 0 indicates an error */
/****************************************************************************/
uint64_t xp_timer64(void)
{
uint64_t ret;
#if defined(__unix__)
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
ret = ts.tv_sec * 1000;
ret += ts.tv_nsec / 1000000;
}
else
ret = -1;
#elif defined(_WIN32)
LARGE_INTEGER freq;
LARGE_INTEGER tick;
if (
if(QueryPerformanceFrequency(&freq) && QueryPerformanceCounter(&tick)) {
static BOOL intable = (freq % 1000) == 0;
if (intable)
ret = tick.QuadPart / (freq.QuadPart / 1000);
else
ret = ((double)tick.QuadPart)/(((double)freq.QuadPart) / 1000);
}
else {
ret=GetTickCount();
}
#else
#error no high-resolution time for this platform
#endif
return(ret);
}
/* Returns TRUE if specified process is running */
BOOL check_pid(pid_t pid)
{
......
......@@ -353,6 +353,7 @@ DLLEXPORT void xp_randomize(void);
DLLEXPORT long xp_random(int);
DLLEXPORT long double xp_timer(void);
DLLEXPORT uint64_t xp_timer64(void);
DLLEXPORT char* os_version(char *str);
DLLEXPORT char* os_cmdshell(void);
DLLEXPORT char* lastchar(const char* str);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment