github.com/primecitizens/pcz/std@v0.2.1/time/sysclock/clock_wasi.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 //go:build wasip1 5 6 package sysclock 7 8 import ( 9 "github.com/primecitizens/pcz/std/core/mark" 10 "github.com/primecitizens/pcz/std/ffi/wasm/wasi" 11 ) 12 13 func Walltime() (sec int64, nsec int32) { 14 var time wasi.Timestamp 15 errno := wasi.ClockTimeGet(wasi.ClockRealtime, 0, mark.NoEscapePointer(&time)) 16 if errno != 0 { 17 return 0, 0 18 } 19 20 return int64(time / 1000_000_000), int32(time % 1000_000_000) 21 } 22 23 func Nanotime() int64 { 24 var time wasi.Timestamp 25 errno := wasi.ClockTimeGet(wasi.ClockMonotonic, 0, mark.NoEscapePointer(&time)) 26 if errno != 0 { 27 return 0 28 } 29 30 return int64(time) 31 }