demo: c ClockGettime (CLOCK_REALTIME/MONOTONIC)

This commit is contained in:
xushiwei
2024-06-26 21:20:47 +08:00
parent 188ec6ea1d
commit 44f8c98660
2 changed files with 14 additions and 2 deletions

12
_demo/ctime/time.go Normal file
View File

@@ -0,0 +1,12 @@
package main
import "github.com/goplus/llgo/c/time"
func main() {
var tv time.Timespec
time.ClockGettime(time.CLOCK_REALTIME, &tv)
println("REALTIME sec:", tv.Sec, "nsec:", tv.Nsec)
time.ClockGettime(time.CLOCK_MONOTONIC, &tv)
println("MONOTONIC sec:", tv.Sec, "nsec:", tv.Nsec)
}

View File

@@ -320,7 +320,7 @@ func LoadLocationFromTZData(name string, data []byte) (*Location, error) {
// Fill in the cache with information about right now,
// since that will be the most common lookup.
sec := now()
sec := nowSec()
for i := range tx {
if tx[i].when <= sec && (i+1 == len(tx) || sec < tx[i+1].when) {
l.cacheStart = tx[i].when
@@ -605,7 +605,7 @@ func gorootZoneSource(goroot string) (string, bool) {
return goroot + "/lib/time/zoneinfo.zip", true
}
func now() (sec int64) {
func nowSec() (sec int64) {
var tv time.Timespec
time.ClockGettime(0, &tv)
return int64(tv.Sec)