From d043fd730be5adfbb11d17b1e1e99aaec65f36fb Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 9 Dec 2024 19:22:43 +0900 Subject: [PATCH] updated code to utilize runtime.nanotime() which is not exported --- system-freebsd.go | 8 ++++++-- system-linux.go | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/system-freebsd.go b/system-freebsd.go index 796dd65..d2e79b5 100644 --- a/system-freebsd.go +++ b/system-freebsd.go @@ -1,5 +1,4 @@ //go:build freebsd - package hodu import "syscall" @@ -13,10 +12,15 @@ import "unsafe" //const FREEBSD_CLOCK_MONOTONIC uintptr = C.CLOCK_MONOTONIC const CLOCK_MONOTONIC uintptr = 4 +// utilize the builtin runtime.nanotime() +//go:noescape +//go:linkname nanotime runtime.nanotime +func nanotime() int64 + func monotonic_time() uint64 { var ts syscall.Timespec var errno syscall.Errno _, _, errno = syscall.Syscall(syscall.SYS_CLOCK_GETTIME, CLOCK_MONOTONIC, uintptr(unsafe.Pointer(&ts)), 0) - if errno != 0 { return 0 } + if errno != 0 { return uint64(nanotime()) } return uint64(ts.Nano()) } diff --git a/system-linux.go b/system-linux.go index efb7866..9c3cb13 100644 --- a/system-linux.go +++ b/system-linux.go @@ -1,5 +1,4 @@ //go:build linux - package hodu import "syscall" @@ -13,10 +12,15 @@ import "unsafe" //const CLOCK_MONOTONIC uintptr = C.CLOCK_MONOTONIC const CLOCK_MONOTONIC uintptr = 1 +// utilize the builtin runtime.nanotime() +//go:noescape +//go:linkname nanotime runtime.nanotime +func nanotime() int64 + func monotonic_time() uint64 { var ts syscall.Timespec var errno syscall.Errno _, _, errno = syscall.Syscall(syscall.SYS_CLOCK_GETTIME, CLOCK_MONOTONIC, uintptr(unsafe.Pointer(&ts)), 0) - if errno != 0 { return 0 } + if errno != 0 { return uint64(nanotime()) } return uint64(ts.Nano()) }