Skip to content

Commit 5d2ad07

Browse files
authored
win: increase precision of clocks in clock_time_get (#182)
This increases the precision of the UVWASI_CLOCK_PROCESS_CPUTIME_ID and UVWASI_CLOCK_THREAD_CPUTIME_ID clocks on Windows. The raw values from GetProcessTimes() and GetThreadTimes() are in units of 100 nanoseconds, which matches the reported resolution returned from uvwasi_clock_time_get().
1 parent 334b186 commit 5d2ad07

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/clocks.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,17 @@
1717
FILETIME exit; \
1818
FILETIME system; \
1919
FILETIME user; \
20-
SYSTEMTIME sys_system; \
21-
SYSTEMTIME sys_user; \
2220
if (0 == get_times((handle), &create, &exit, &system, &user)) { \
2321
return uvwasi__translate_uv_error( \
2422
uv_translate_sys_error(GetLastError()) \
2523
); \
2624
} \
2725
\
28-
if (0 == FileTimeToSystemTime(&system, &sys_system)) { \
29-
return uvwasi__translate_uv_error( \
30-
uv_translate_sys_error(GetLastError()) \
31-
); \
32-
} \
33-
\
34-
if (0 == FileTimeToSystemTime(&user, &sys_user)) { \
35-
return uvwasi__translate_uv_error( \
36-
uv_translate_sys_error(GetLastError()) \
37-
); \
38-
} \
39-
\
40-
(time) = (((uvwasi_timestamp_t)(sys_system.wHour * 3600) + \
41-
(sys_system.wMinute * 60) + sys_system.wSecond) * NANOS_PER_SEC) + \
42-
((uvwasi_timestamp_t)(sys_system.wMilliseconds) * 1000000) + \
43-
(((uvwasi_timestamp_t)(sys_user.wHour * 3600) + \
44-
(sys_user.wMinute * 60) + sys_user.wSecond) * NANOS_PER_SEC) + \
45-
((uvwasi_timestamp_t)(sys_user.wMilliseconds) * 1000000); \
26+
/* FILETIME times are in units of 100 nanoseconds */ \
27+
(time) = (((uvwasi_timestamp_t) \
28+
system.dwHighDateTime << 32 | system.dwLowDateTime) * 100 + \
29+
((uvwasi_timestamp_t) \
30+
user.dwHighDateTime << 32 | user.dwLowDateTime) * 100); \
4631
return UVWASI_ESUCCESS; \
4732
} while (0)
4833

0 commit comments

Comments
 (0)