Commit 745c053d authored by deuce's avatar deuce
Browse files

Added xp_timer() returns the current value of a high-resolution timer

in seconds as a double.
parent cad41f66
......@@ -460,3 +460,35 @@ int DLLCALL get_errno(void)
{
return(errno);
}
/****************************************************************************/
/* Returns the current value of the systems best timer (in SECONDS) */
/* Any value < 0 indicates an error */
/****************************************************************************/
double DLLCALL xp_timer(void)
{
double ret=0;
#ifdef __unix__
struct timeval tv;
if(gettimeofday(&tv,NULL)==1)
return(-1);
ret=tv.tv_usec;
ret /= 1000000;
ret += tv.tv_sec;
#else
#ifdef _WIN32
LARGE_INTEGER freq;
if(QueryPerformanceFrequency(&freq)) {
ret=QueryPerformanceCounter();
ret /= freq;
}
else {
ret=GetTickCount();
ret /= 1000;
}
#else
#error Need xp_timer implementation!
#endif
#endif
return(ret);
}
......@@ -284,6 +284,7 @@ DLLEXPORT int DLLCALL get_errno(void);
#endif
DLLEXPORT int DLLCALL xp_random(int);
DLLEXPORT double DLLCALL xp_timer(void);
DLLEXPORT char* DLLCALL os_version(char *str);
DLLEXPORT char* DLLCALL lastchar(const char* str);
DLLEXPORT int DLLCALL safe_snprintf(char *dst, size_t size, const char *fmt, ...);
......
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