mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Improve resolution of System.nanoTime
This commit is contained in:
parent
1b23c9194b
commit
093b506c9a
|
@ -28,6 +28,7 @@ import org.teavm.interop.DelegateTo;
|
||||||
import org.teavm.interop.Import;
|
import org.teavm.interop.Import;
|
||||||
import org.teavm.interop.NoSideEffects;
|
import org.teavm.interop.NoSideEffects;
|
||||||
import org.teavm.interop.Unmanaged;
|
import org.teavm.interop.Unmanaged;
|
||||||
|
import org.teavm.jso.browser.Performance;
|
||||||
import org.teavm.runtime.Allocator;
|
import org.teavm.runtime.Allocator;
|
||||||
import org.teavm.runtime.GC;
|
import org.teavm.runtime.GC;
|
||||||
import org.teavm.runtime.RuntimeArray;
|
import org.teavm.runtime.RuntimeArray;
|
||||||
|
@ -222,8 +223,15 @@ public final class TSystem extends TObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long nanoTime() {
|
public static long nanoTime() {
|
||||||
return currentTimeMillis() * 1000000;
|
if (PlatformDetector.isLowLevel()) {
|
||||||
|
return nanoTimeLowLevel();
|
||||||
|
} else {
|
||||||
|
return (long) (Performance.now() * 1000000);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Import(name = "currentTimeNano")
|
||||||
|
private static native long nanoTimeLowLevel();
|
||||||
|
|
||||||
public static int identityHashCode(Object x) {
|
public static int identityHashCode(Object x) {
|
||||||
return ((TObject) x).identity();
|
return ((TObject) x).identity();
|
||||||
|
|
|
@ -232,7 +232,13 @@ static int64_t currentTimeMillis() {
|
||||||
struct timespec time;
|
struct timespec time;
|
||||||
clock_gettime(CLOCK_REALTIME, &time);
|
clock_gettime(CLOCK_REALTIME, &time);
|
||||||
|
|
||||||
return time.tv_sec * 1000 + (int64_t) round(time.tv_nsec / 1000000);
|
return time.tv_sec * INT64_C(1000) + (int64_t) round(time.tv_nsec / 1000000);
|
||||||
|
}
|
||||||
|
static int64_t currentTimeNano() {
|
||||||
|
struct timespec time;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &time);
|
||||||
|
|
||||||
|
return time.tv_sec * INT64_C(1000000000) + (int64_t) round(time.tv_nsec);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user