From 1842451b0e49ac1899ed3ab3515021a6077aff92 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 7 Mar 2023 01:02:19 +0100 Subject: Clock: Consider return code on failed native clock_gettime(..) call; Add Win32 clock_gettime() implementation. Consider return code on failed native clock_gettime(..) call - Return Instant.EPOCH for all Instant variations (essentially 0) - Return 0 for all 'long' variations (ms, ns) Add Win32 clock_gettime() implementation. - Source: https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-libraries/winpthreads/src/clock.c - Public Domain within mingw-w64, included here to simplify linkage. - Tested on Win10 64bit w/ TestTextRendererNEWT00, all values are OK --- src/java/com/jogamp/common/os/Clock.java | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/java') diff --git a/src/java/com/jogamp/common/os/Clock.java b/src/java/com/jogamp/common/os/Clock.java index 03a0040..9380442 100644 --- a/src/java/com/jogamp/common/os/Clock.java +++ b/src/java/com/jogamp/common/os/Clock.java @@ -32,8 +32,11 @@ public class Clock { Platform.initSingleton(); // loads native gluegen_rt library { final long[/*2*/] val = { 0, 0 }; - getMonotonicStartupTimeImpl(val); - t0 = Instant.ofEpochSecond(val[0], val[1]); + if( getMonotonicStartupTimeImpl(val) ) { + t0 = Instant.ofEpochSecond(val[0], val[1]); + } else { + t0 = Instant.EPOCH; + } } } @@ -59,10 +62,13 @@ public class Clock { */ public static Instant getMonotonicTime() { final long[/*2*/] val = { 0, 0 }; - getMonotonicTimeImpl(val); - return Instant.ofEpochSecond(val[0], val[1]); + if( getMonotonicTimeImpl(val) ) { + return Instant.ofEpochSecond(val[0], val[1]); + } else { + return Instant.EPOCH; + } } - private static native void getMonotonicTimeImpl(final long[/*2*/] val); + private static native boolean getMonotonicTimeImpl(final long[/*2*/] val); /** * Returns current wall-clock real-time since Unix Epoch `00:00:00 UTC on 1970-01-01`. @@ -80,10 +86,13 @@ public class Clock { */ public static Instant getWallClockTime() { final long[/*2*/] val = { 0, 0 }; - getWallClockTimeImpl(val); - return Instant.ofEpochSecond(val[0], val[1]); + if( getWallClockTimeImpl(val) ) { + return Instant.ofEpochSecond(val[0], val[1]); + } else { + return Instant.EPOCH; + } } - private static native void getWallClockTimeImpl(final long[/*2*/] val); + private static native boolean getWallClockTimeImpl(final long[/*2*/] val); /** * Returns the monotonic startup time since module startup as used in {@link #currentNanos()} and {@link #getMonotonicNanos()}. @@ -91,7 +100,7 @@ public class Clock { * @see #getMonotonicNanos() */ public static Instant getMonotonicStartupTime() { return t0; } - private static native void getMonotonicStartupTimeImpl(final long[/*2*/] val); + private static native boolean getMonotonicStartupTimeImpl(final long[/*2*/] val); /** * Returns current monotonic nanoseconds since start of this application. -- cgit v1.2.3