Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/clocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
#include "uv_mapping.h"


#define UVWASI__WIN_TIME_AND_RETURN(handle, time) \
#define UVWASI__WIN_TIME_AND_RETURN(handle, get_times, time) \
do { \
FILETIME create; \
FILETIME exit; \
FILETIME system; \
FILETIME user; \
SYSTEMTIME sys_system; \
SYSTEMTIME sys_user; \
if (0 == GetProcessTimes((handle), &create, &exit, &system, &user)) { \
if (0 == get_times((handle), &create, &exit, &system, &user)) { \
return uvwasi__translate_uv_error( \
uv_translate_sys_error(GetLastError()) \
); \
Expand Down Expand Up @@ -137,7 +137,7 @@ uvwasi_errno_t uvwasi__clock_gettime_realtime(uvwasi_timestamp_t* time) {

uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time) {
#if defined(_WIN32)
UVWASI__WIN_TIME_AND_RETURN(GetCurrentProcess(), *time);
UVWASI__WIN_TIME_AND_RETURN(GetCurrentProcess(), GetProcessTimes, *time);
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && \
!defined(__APPLE__) && \
!defined(__sun)
Expand All @@ -150,7 +150,7 @@ uvwasi_errno_t uvwasi__clock_gettime_process_cputime(uvwasi_timestamp_t* time) {

uvwasi_errno_t uvwasi__clock_gettime_thread_cputime(uvwasi_timestamp_t* time) {
#if defined(_WIN32)
UVWASI__WIN_TIME_AND_RETURN(GetCurrentThread(), *time);
UVWASI__WIN_TIME_AND_RETURN(GetCurrentThread(), GetThreadTimes, *time);
#elif defined(__APPLE__)
UVWASI__OSX_THREADTIME_AND_RETURN(*time);
#elif defined(CLOCK_THREAD_CPUTIME_ID) && !defined(__sun) && !defined(__PASE__)
Expand Down
37 changes: 37 additions & 0 deletions test/test-clock-time-get.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "uvwasi.h"

int main(void) {
uvwasi_t uvwasi;
uvwasi_options_t init_options;
uvwasi_errno_t err;
uvwasi_timestamp_t time;
uvwasi_timestamp_t precision = 1000;

uvwasi_options_init(&init_options);

err = uvwasi_init(&uvwasi, &init_options);
assert(err == 0);

err = uvwasi_clock_time_get(&uvwasi, UVWASI_CLOCK_REALTIME, precision, &time);
assert(err == 0);
assert(time > 0);

err = uvwasi_clock_time_get(&uvwasi, UVWASI_CLOCK_MONOTONIC, precision, &time);
assert(err == 0);
assert(time > 0);

err = uvwasi_clock_time_get(&uvwasi, UVWASI_CLOCK_PROCESS_CPUTIME_ID, precision, &time);
assert(err == 0);
assert(time > 0);

err = uvwasi_clock_time_get(&uvwasi, UVWASI_CLOCK_THREAD_CPUTIME_ID, precision, &time);
assert(err == 0);
assert(time > 0);

uvwasi_destroy(&uvwasi);

return 0;
}