mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
CLOCK_MONOTONIC_RAW support for Go
This commit is contained in:
@@ -10,9 +10,11 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@@ -310,3 +312,16 @@ func FunctionName(a any) string {
|
|||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MonotonicRaw() (time.Time, error) {
|
||||||
|
ts := unix.Timespec{}
|
||||||
|
var clock_id int32 = unix.CLOCK_MONOTONIC
|
||||||
|
if runtime.GOOS == "linux" {
|
||||||
|
clock_id = unix.CLOCK_MONOTONIC_RAW
|
||||||
|
}
|
||||||
|
if err := unix.ClockGettime(clock_id, &ts); err != nil {
|
||||||
|
return time.Time{}, err
|
||||||
|
}
|
||||||
|
s, ns := ts.Unix()
|
||||||
|
return time.Unix(s, ns), nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user