Skip to content

Commit d16ebe6

Browse files
committed
Fix THREAD_CPUTIME clock_time_get on Windows
1 parent 02a7e48 commit d16ebe6

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/clocks.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
#include "uv_mapping.h"
1212

1313

14-
#define UVWASI__WIN_TIME_AND_RETURN(handle, time) \
14+
#define UVWASI__WIN_TIME_AND_RETURN(handle, get_times, time) \
1515
do { \
1616
FILETIME create; \
1717
FILETIME exit; \
1818
FILETIME system; \
1919
FILETIME user; \
2020
SYSTEMTIME sys_system; \
2121
SYSTEMTIME sys_user; \
22-
if (0 == GetProcessTimes((handle), &create, &exit, &system, &user)) { \
22+
if (0 == get_times((handle), &create, &exit, &system, &user)) { \
2323
return uvwasi__translate_uv_error( \
2424
uv_translate_sys_error(GetLastError()) \
2525
); \
@@ -137,7 +137,7 @@ uvwasi_errno_t uvwasi__clock_gettime_realtime(uvwasi_timestamp_t* time) {
137137

138138
uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time) {
139139
#if defined(_WIN32)
140-
UVWASI__WIN_TIME_AND_RETURN(GetCurrentProcess(), *time);
140+
UVWASI__WIN_TIME_AND_RETURN(GetCurrentProcess(), GetProcessTimes, *time);
141141
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && \
142142
!defined(__APPLE__) && \
143143
!defined(__sun)
@@ -150,7 +150,7 @@ uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time) {
150150

151151
uvwasi_errno_t uvwasi__clock_gettime_thread_cputime(uvwasi_timestamp_t* time) {
152152
#if defined(_WIN32)
153-
UVWASI__WIN_TIME_AND_RETURN(GetCurrentThread(), *time);
153+
UVWASI__WIN_TIME_AND_RETURN(GetCurrentThread(), GetThreadTimes, *time);
154154
#elif defined(__APPLE__)
155155
UVWASI__OSX_THREADTIME_AND_RETURN(*time);
156156
#elif defined(CLOCK_THREAD_CPUTIME_ID) && !defined(__sun) && !defined(__PASE__)

test/test-clock-time-get.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include "uvwasi.h"
5+
6+
int main(void) {
7+
uvwasi_t uvwasi;
8+
uvwasi_options_t init_options;
9+
uvwasi_errno_t err;
10+
uvwasi_timestamp_t time;
11+
uvwasi_timestamp_t precision = 1000;
12+
13+
uvwasi_options_init(&init_options);
14+
15+
err = uvwasi_init(&uvwasi, &init_options);
16+
assert(err == 0);
17+
18+
err = uvwasi_clock_time_get(&uvwasi, UVWASI_CLOCK_REALTIME, precision, &time);
19+
assert(err == 0);
20+
assert(time > 0);
21+
22+
err = uvwasi_clock_time_get(&uvwasi, UVWASI_CLOCK_MONOTONIC, precision, &time);
23+
assert(err == 0);
24+
assert(time > 0);
25+
26+
err = uvwasi_clock_time_get(&uvwasi, UVWASI_CLOCK_PROCESS_CPUTIME_ID, precision, &time);
27+
assert(err == 0);
28+
assert(time > 0);
29+
30+
err = uvwasi_clock_time_get(&uvwasi, UVWASI_CLOCK_THREAD_CPUTIME_ID, precision, &time);
31+
assert(err == 0);
32+
assert(time > 0);
33+
34+
uvwasi_destroy(&uvwasi);
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)