Commit a3e175a5 authored by deuce's avatar deuce
Browse files

Added msclock() and MSCLOCKS_PER_SEC - this is a realtime clock with a

frequency of MSCLOCKS_PER_SEC... the initial value is undefined.
parent 83b4d9ef
......@@ -334,3 +334,18 @@ char* DLLCALL asctime_r(const struct tm *tm, char *buf)
}
#endif /* !defined(__unix__) */
/********************************************/
/* Hi-res real-time clock implementation. */
/********************************************/
#ifdef __unix__
clock_t DLLCALL msclock(void)
{
long long int usecs;
struct timeval tv;
if(gettimeofday(&tv,NULL)==1)
return(-1);
usecs=tv.tv_sec*1000000+tv.tv_usec;
return((clock_t)(usecs/(1000000/MSCLOCKS_PER_SEC)));
}
#endif
......@@ -44,6 +44,7 @@
#if defined(__unix__)
#include <sched.h> /* sched_yield */
#include <time.h> /* clock_t */
#include <sys/time.h> /* struct timeval */
#include <strings.h> /* strcasecmp() */
#include <unistd.h> /* usleep */
......@@ -268,6 +269,13 @@ DLLEXPORT int DLLCALL xp_random(int);
DLLEXPORT char* DLLCALL os_version(char *str);
DLLEXPORT char* DLLCALL lastchar(const char* str);
DLLEXPORT int DLLCALL safe_snprintf(char *dst, size_t size, char *fmt, ...);
#if defined(_WIN32)
#define msclock() clock()
#else
#define MSCLOCKS_PER_SEC 1000
clock_t msclock(void);
#endif
#if defined(__cplusplus)
}
#endif
......
......@@ -49,6 +49,7 @@ int main()
int fd;
int fd2;
int canrelock=0;
clock_t ticks;
/* Show platform details */
DESCRIBE_COMPILER(compiler);
......@@ -171,8 +172,9 @@ int main()
t=time(NULL);
printf("sleeping... ");
fflush(stdout);
ticks=msclock();
SLEEP(5000);
printf("slept %ld seconds\n",time(NULL)-t);
printf("slept %ld seconds (%ld according to msclock)\n",time(NULL)-t,(msclock()-ticks)/MSCLOCKS_PER_SEC);
/* Thread SLEEP test */
printf("\nThread SLEEP(5 second) test\n");
......
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