mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00

lease uses monotimer to calculate its expiration. In this way, changing system time won't affect in lease expiration. FIX #6700
25 lines
799 B
Go
25 lines
799 B
Go
// Copyright (C) 2016 Arista Networks, Inc.
|
|
// Use of this source code is governed by the Apache License 2.0
|
|
// that can be found in the COPYING file.
|
|
|
|
// Package monotime provides a fast monotonic clock source.
|
|
package monotime
|
|
|
|
import (
|
|
_ "unsafe" // required to use //go:linkname
|
|
)
|
|
|
|
//go:noescape
|
|
//go:linkname nanotime runtime.nanotime
|
|
func nanotime() int64
|
|
|
|
// Now returns the current time in nanoseconds from a monotonic clock.
|
|
// The time returned is based on some arbitrary platform-specific point in the
|
|
// past. The time returned is guaranteed to increase monotonically at a
|
|
// constant rate, unlike time.Now() from the Go standard library, which may
|
|
// slow down, speed up, jump forward or backward, due to NTP activity or leap
|
|
// seconds.
|
|
func Now() Time {
|
|
return Time(nanotime())
|
|
}
|