// Update runs the update step of the clock, updating its synchronization with
// the reference clock.
//
// Update returns timekeeping and true with the new timekeeping parameters if
// the clock is calibrated. Update should be called regularly to prevent the
// clock from getting significantly out of sync from the reference clock.
//
// The returned timekeeping parameters are invalidated on the next call to
// Update.
Update runs the update step of the clock, updating its synchronization with
the reference clock.

Update returns timekeeping and true with the new timekeeping parameters if
the clock is calibrated. Update should be called regularly to prevent the
clock from getting significantly out of sync from the reference clock.

The returned timekeeping parameters are invalidated on the next call to
Update.
// Update runs the update step of the clock updating its synchronization with // the reference clock . // // Update returns timekeeping and true with the new timekeeping parameters if // the clock is calibrated . Update should be called regularly to prevent the // clock from getting significantly out of sync from the reference clock . // // The returned timekeeping parameters are invalidated on the next call to // Update .
func (c *CalibratedClock) Update() (Parameters, bool) {
	c.mu.Lock()
	defer c.mu.Unlock()
	if err := c.ref.Sample(); err != nil {
		c.resetLocked("Unable to update calibrated clock: %v.", err)
		return Parameters{}, false
	}
	oldest, newest, ok := c.ref.Range()
	if !ok {
		return Parameters{}, false
	}
	minCount := uint64(newest.before - oldest.after)
	maxCount := uint64(newest.after - oldest.before)
	refInterval := uint64(newest.ref - oldest.ref)
	nsPerS := uint64(time.Second.Nanoseconds())
	minHz, ok := muldiv64(minCount, nsPerS, refInterval)
	if !ok {
		c.resetLocked("Unable to update calibrated clock: (%v - %v) * %v / %v overflows.", newest.before, oldest.after, nsPerS, refInterval)
		return Parameters{}, false
	}
	maxHz, ok := muldiv64(maxCount, nsPerS, refInterval)
	if !ok {
		c.resetLocked("Unable to update calibrated clock: (%v - %v) * %v / %v overflows.", newest.after, oldest.before, nsPerS, refInterval)
		return Parameters{}, false
	}
	c.updateParams(Parameters{
		Frequency:  (minHz + maxHz) / 2,
		BaseRef:    newest.ref,
		BaseCycles: newest.after,
	})
	return c.params, true
}
func ( c * CalibratedClock ) Update ( ) ( Parameters , bool ) { c . mu . Lock ( ) defer c . mu . Unlock ( ) if err := c . ref . Sample ( ) ; err != nil { c . resetLocked ( " " , err ) return Parameters { } , false } oldest , newest , ok := c . ref . Range ( ) if ! ok { return Parameters { } , false } minCount := uint64 ( newest . before - oldest . after ) maxCount := uint64 ( newest . after - oldest . before ) refInterval := uint64 ( newest . ref - oldest . ref ) nsPerS := uint64 ( time . Second . Nanoseconds ( ) ) minHz , ok := muldiv64 ( minCount , nsPerS , refInterval ) if ! ok { c . resetLocked ( " " , newest . before , oldest . after , nsPerS , refInterval ) return Parameters { } , false } maxHz , ok := muldiv64 ( maxCount , nsPerS , refInterval ) if ! ok { c . resetLocked ( " " , newest . after , oldest . before , nsPerS , refInterval ) return Parameters { } , false } c . updateParams ( Parameters { Frequency : ( minHz + maxHz ) / 2 , BaseRef : newest . ref , BaseCycles : newest . after , } ) return c . params , true }
Update runs the update step of the clock, updating its synchronization with
the reference clock.
Update runs the update step of the clock updating its synchronization with the reference clock .
// Not ready yet. // freq hz = count / (interval ns) * (nsPerS ns) / (1 s)