diff options
author | Eugene Tarassov | 2015-05-20 19:09:11 +0000 |
---|---|---|
committer | Eugene Tarassov | 2015-05-20 19:09:11 +0000 |
commit | 813f4d539c27e7dcef5bb842b145183e6f50880b (patch) | |
tree | ce89f517f0724f72054890a408180ae1680b0710 | |
parent | e476a6d4e0e1f7d576e2af2fde47642285fb1e27 (diff) | |
download | org.eclipse.tcf.agent-813f4d539c27e7dcef5bb842b145183e6f50880b.tar.gz org.eclipse.tcf.agent-813f4d539c27e7dcef5bb842b145183e6f50880b.tar.xz org.eclipse.tcf.agent-813f4d539c27e7dcef5bb842b145183e6f50880b.zip |
TCF Agent: added support for CLOCK_MONOTONIC on Windows
-rw-r--r-- | agent/tcf/framework/mdep.c | 40 | ||||
-rw-r--r-- | agent/tcf/framework/mdep.h | 3 |
2 files changed, 33 insertions, 10 deletions
diff --git a/agent/tcf/framework/mdep.c b/agent/tcf/framework/mdep.c index dabbe56d..2b52ca82 100644 --- a/agent/tcf/framework/mdep.c +++ b/agent/tcf/framework/mdep.c @@ -250,19 +250,41 @@ static __int64 file_time_to_unix_time(const FILETIME * ft) { } int clock_gettime(clockid_t clock_id, struct timespec * tp) { - FILETIME ft; - __int64 tim; - - assert(clock_id == CLOCK_REALTIME); if (!tp) { errno = EINVAL; return -1; } - GetSystemTimeAsFileTime(&ft); - tim = file_time_to_unix_time(&ft); - tp->tv_sec = (long)(tim / 1000000L); - tp->tv_nsec = (long)(tim % 1000000L) * 1000; - return 0; + memset(tp, 0, sizeof(struct timespec)); + if (clock_id == CLOCK_REALTIME) { + FILETIME ft; + __int64 tim; + GetSystemTimeAsFileTime(&ft); + tim = file_time_to_unix_time(&ft); + tp->tv_sec = (time_t)(tim / 1000000L); + tp->tv_nsec = (long)(tim % 1000000L) * 1000; + return 0; + } + if (clock_id == CLOCK_MONOTONIC) { + typedef ULONGLONG (FAR WINAPI * ProcType)(void); + static ProcType proc = NULL; + static int chk_done = 0; + ULONGLONG time_ms = 0; + /* GetTickCount() is valid only first 49 days */ + /* GetTickCount64 not available before Windows Vista */ + if (!chk_done) { + HMODULE kernel_dll = LoadLibraryA("Kernel32.dll"); + if (kernel_dll != NULL) { + proc = (ProcType)GetProcAddress(kernel_dll, "GetTickCount64"); + } + chk_done = 1; + } + time_ms = proc != NULL ? proc() : (ULONGLONG)GetTickCount(); + tp->tv_sec = (time_t)(time_ms / 1000); + tp->tv_nsec = (long)(time_ms % 1000) * 1000000; + return 0; + } + errno = ENOSYS; + return -1; } void usleep(useconds_t useconds) { diff --git a/agent/tcf/framework/mdep.h b/agent/tcf/framework/mdep.h index 8fb4ebbf..1e718a2b 100644 --- a/agent/tcf/framework/mdep.h +++ b/agent/tcf/framework/mdep.h @@ -142,7 +142,8 @@ typedef unsigned long pid_t; typedef unsigned long useconds_t; #endif -#define CLOCK_REALTIME 1 +#define CLOCK_REALTIME 1 +#define CLOCK_MONOTONIC 2 typedef int clockid_t; extern int clock_gettime(clockid_t clock_id, struct timespec * tp); extern void usleep(useconds_t useconds); |