From 717bc406e96fbff30cf02adad019cf9daa14e59c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 6 Mar 2023 10:28:32 +0100 Subject: Add Clock, implementing proper monotonic and wallclock time using Instant (sec + nsec), currentTimeMillis() is also monotonic now, reused by Platform. Dropped Platform.currentTimeMicros() Clock and its implementation was copied from jaulibs, a spin-off from Direct-BT. The implementation uses `clock_gettime(CLOCK_MONOTONIC, &t)` and is considered safe and high-performant as it avoids a kernel call via VDSO (GNU/Linux). --- src/java/com/jogamp/common/os/Platform.java | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'src/java/com/jogamp/common/os/Platform.java') diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index e6821ba..9c65596 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -1,5 +1,5 @@ /** - * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -521,26 +521,12 @@ public class Platform extends PlatformPropsImpl { // /** - * Returns the unix based current time in milliseconds, based on gettimeofday(..). - *

- * This is an alternative to {@link System#currentTimeMillis()} and {@link System#nanoTime()}. - * While the named {@link System} methods do provide the required precision, - * gettimeofday() also guarantees time accuracy, i.e. update interval. - *

- * @see #currentTimeMicros() - */ - public static native long currentTimeMillis(); - - /** - * Returns the unix based current time in microseconds, based on gettimeofday(..). - *

- * This is an alternative to {@link System#currentTimeMillis()} and {@link System#nanoTime()}. - * While the named {@link System} methods do provide the required precision, - * gettimeofday() also guarantees time accuracy, i.e. update interval. - *

- * @see #currentTimeMillis() + * Returns the unix based current time in milliseconds, see {@link Clock#currentTimeMillis()}. + * @see Clock#currentTimeMillis() */ - public static native long currentTimeMicros(); + public static long currentTimeMillis() { + return Clock.currentTimeMillis(); + } /** * Returns the estimated sleep jitter value in nanoseconds. -- cgit v1.2.3