diff --git a/contrib/time-shim.c b/contrib/time-shim.c index 17c7aee..22d9038 100755 --- a/contrib/time-shim.c +++ b/contrib/time-shim.c @@ -30,28 +30,28 @@ #define FILETIME_1970 116444736000000000ull /* seconds between 1/1/1601 and 1/1/1970 */ #define HECTONANOSEC_PER_SEC 10000000ull -int gettimeofday(struct timeval *tv, void * not_implemented) -{ - RIST_MARK_UNUSED(not_implemented); - - union { - unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */ - FILETIME ft; - } _now; - - if (tv != NULL) - { - struct timespec tp; - GetSystemTimeAsFileTime (&_now.ft); /* 100-nanoseconds since 1-1-1601 */ - /* The actual accuracy on XP seems to be 125,000 nanoseconds = 125 microseconds = 0.125 milliseconds */ - _now.ns100 -= FILETIME_1970; /* 100 nano-seconds since 1-1-1970 */ - tp.tv_sec = _now.ns100 / HECTONANOSEC_PER_SEC; /* seconds since 1-1-1970 */ - tp.tv_nsec = (long) (_now.ns100 % HECTONANOSEC_PER_SEC) * 100; /* nanoseconds */ - tv->tv_sec = tp.tv_sec; - tv->tv_usec = tp.tv_nsec/1000; - } - return 0; -} +// int gettimeofday(struct timeval *tv, void * not_implemented) +// { +// RIST_MARK_UNUSED(not_implemented); + +// union { +// unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */ +// FILETIME ft; +// } _now; + +// if (tv != NULL) +// { +// struct timespec tp; +// GetSystemTimeAsFileTime (&_now.ft); /* 100-nanoseconds since 1-1-1601 */ +// /* The actual accuracy on XP seems to be 125,000 nanoseconds = 125 microseconds = 0.125 milliseconds */ +// _now.ns100 -= FILETIME_1970; /* 100 nano-seconds since 1-1-1970 */ +// tp.tv_sec = _now.ns100 / HECTONANOSEC_PER_SEC; /* seconds since 1-1-1970 */ +// tp.tv_nsec = (long) (_now.ns100 % HECTONANOSEC_PER_SEC) * 100; /* nanoseconds */ +// tv->tv_sec = tp.tv_sec; +// tv->tv_usec = tp.tv_nsec/1000; +// } +// return 0; +// } //(un)graciously copied from mingw-w64/winpthreads/src/clock.c @@ -80,72 +80,72 @@ static inline int lc_set_errno(int result) return 0; } -int clock_gettime(clockid_t clock_id, struct timespec *tp) -{ - uint64_t t; - LARGE_INTEGER pf, pc; - union { - uint64_t u64; - FILETIME ft; - } ct, et, kt, ut; - - switch(clock_id) { - case CLOCK_REALTIME: - { - GetSystemTimeAsFileTime(&ct.ft); - t = ct.u64 - DELTA_EPOCH_IN_100NS; - tp->tv_sec = t / POW10_7; - tp->tv_nsec = ((int) (t % POW10_7)) * 100; - - return 0; - } - - case CLOCK_MONOTONIC: - { - if (QueryPerformanceFrequency(&pf) == 0) - return lc_set_errno(EINVAL); - - if (QueryPerformanceCounter(&pc) == 0) - return lc_set_errno(EINVAL); - - tp->tv_sec = pc.QuadPart / pf.QuadPart; - tp->tv_nsec = (int) (((pc.QuadPart % pf.QuadPart) * POW10_9 + (pf.QuadPart >> 1)) / pf.QuadPart); - if (tp->tv_nsec >= POW10_9) { - tp->tv_sec ++; - tp->tv_nsec -= POW10_9; - } - - return 0; - } - - case CLOCK_PROCESS_CPUTIME_ID: - { - if(0 == GetProcessTimes(GetCurrentProcess(), &ct.ft, &et.ft, &kt.ft, &ut.ft)) - return lc_set_errno(EINVAL); - t = kt.u64 + ut.u64; - tp->tv_sec = t / POW10_7; - tp->tv_nsec = ((int) (t % POW10_7)) * 100; - - return 0; - } - - case CLOCK_THREAD_CPUTIME_ID: - { - if(0 == GetThreadTimes(GetCurrentThread(), &ct.ft, &et.ft, &kt.ft, &ut.ft)) - return lc_set_errno(EINVAL); - t = kt.u64 + ut.u64; - tp->tv_sec = t / POW10_7; - tp->tv_nsec = ((int) (t % POW10_7)) * 100; - - return 0; - } - - default: - break; - } - - return lc_set_errno(EINVAL); -} +// int clock_gettime(clockid_t clock_id, struct timespec *tp) +// { +// uint64_t t; +// LARGE_INTEGER pf, pc; +// union { +// uint64_t u64; +// FILETIME ft; +// } ct, et, kt, ut; + +// switch(clock_id) { +// case CLOCK_REALTIME: +// { +// GetSystemTimeAsFileTime(&ct.ft); +// t = ct.u64 - DELTA_EPOCH_IN_100NS; +// tp->tv_sec = t / POW10_7; +// tp->tv_nsec = ((int) (t % POW10_7)) * 100; + +// return 0; +// } + +// case CLOCK_MONOTONIC: +// { +// if (QueryPerformanceFrequency(&pf) == 0) +// return lc_set_errno(EINVAL); + +// if (QueryPerformanceCounter(&pc) == 0) +// return lc_set_errno(EINVAL); + +// tp->tv_sec = pc.QuadPart / pf.QuadPart; +// tp->tv_nsec = (int) (((pc.QuadPart % pf.QuadPart) * POW10_9 + (pf.QuadPart >> 1)) / pf.QuadPart); +// if (tp->tv_nsec >= POW10_9) { +// tp->tv_sec ++; +// tp->tv_nsec -= POW10_9; +// } + +// return 0; +// } + +// case CLOCK_PROCESS_CPUTIME_ID: +// { +// if(0 == GetProcessTimes(GetCurrentProcess(), &ct.ft, &et.ft, &kt.ft, &ut.ft)) +// return lc_set_errno(EINVAL); +// t = kt.u64 + ut.u64; +// tp->tv_sec = t / POW10_7; +// tp->tv_nsec = ((int) (t % POW10_7)) * 100; + +// return 0; +// } + +// case CLOCK_THREAD_CPUTIME_ID: +// { +// if(0 == GetThreadTimes(GetCurrentThread(), &ct.ft, &et.ft, &kt.ft, &ut.ft)) +// return lc_set_errno(EINVAL); +// t = kt.u64 + ut.u64; +// tp->tv_sec = t / POW10_7; +// tp->tv_nsec = ((int) (t % POW10_7)) * 100; + +// return 0; +// } + +// default: +// break; +// } + +// return lc_set_errno(EINVAL); +// } #endif