1 krisbash 1.1 #include "sleep.h"
2
3 #if defined(CONFIG_OS_WINDOWS)
4 # include <windows.h>
5 # include <time.h>
6 #elif defined(CONFIG_POSIX)
7 # include <unistd.h>
8 # include <time.h>
9 # include <sys/time.h>
10 # include <sys/types.h>
11 #endif
12
13 PAL_Boolean PAL_Time(
14 PAL_Uint64* self)
15 {
16 #if defined(_MSC_VER)
17 FILETIME ft;
18 ULARGE_INTEGER tmp;
19
20 GetSystemTimeAsFileTime(&ft);
21 tmp.u.LowPart = ft.dwLowDateTime;
22 krisbash 1.1 tmp.u.HighPart = ft.dwHighDateTime;
23 tmp.QuadPart -= 0X19DB1DED53E8000;
24 *self = tmp.QuadPart / (UINT64)10;
25 return PAL_TRUE;
26 #elif defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK > 0)
27
28 struct timespec ts;
29 memset( &ts, 0, sizeof(ts));
30
31 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
32 return PAL_FALSE;
33
34 /* Seconds to microseconds plus nano seconds to microseconds */
35 *self = ((PAL_Uint64)ts.tv_sec * (PAL_Uint64)1000000) + ((PAL_Uint64)ts.tv_nsec / (PAL_Uint64)1000);
36 return PAL_TRUE;
37 #else
38 struct timeval tv;
39 struct timezone tz;
40 memset(&tv, 0, sizeof(tv));
41 memset(&tz, 0, sizeof(tz));
42
43 krisbash 1.1 if (gettimeofday(&tv, &tz) != 0)
44 return PAL_FALSE;
45
46 *self = (PAL_Uint64)tv.tv_sec * (PAL_Uint64)1000000 + (PAL_Uint64)tv.tv_usec;
47 return PAL_TRUE;
48 #endif
49 }
|