package platform

import (
	
	

	
)

const (
	ms = int64(time.Millisecond)
	// FakeEpochNanos is midnight UTC 2022-01-01 and exposed for testing
	FakeEpochNanos = 1640995200000 * ms
)

// NewFakeWalltime implements sys.Walltime with FakeEpochNanos that increases by 1ms each reading.
// See /RATIONALE.md
func () sys.Walltime {
	// AddInt64 returns the new value. Adjust so the first reading will be FakeEpochNanos
	 := FakeEpochNanos - ms
	return func() ( int64,  int32) {
		 := atomic.AddInt64(&, ms)
		return  / 1e9, int32( % 1e9)
	}
}

// NewFakeNanotime implements sys.Nanotime that increases by 1ms each reading.
// See /RATIONALE.md
func () sys.Nanotime {
	// AddInt64 returns the new value. Adjust so the first reading will be zero.
	 := int64(0) - ms
	return func() int64 {
		return atomic.AddInt64(&, ms)
	}
}

// FakeNanosleep implements sys.Nanosleep by returning without sleeping.
var FakeNanosleep = sys.Nanosleep(func(int64) {})

// FakeOsyield implements sys.Osyield by returning without yielding.
var FakeOsyield = sys.Osyield(func() {})

// Walltime implements sys.Walltime with time.Now.
//
// Note: This is only notably less efficient than it could be is reading
// runtime.walltime(). time.Now defensively reads nanotime also, just in case
// time.Since is used. This doubles the performance impact. However, wall time
// is likely to be read less frequently than Nanotime. Also, doubling the cost
// matters less on fast platforms that can return both in <=100ns.
func () ( int64,  int32) {
	 := time.Now()
	return .Unix(), int32(.Nanosecond())
}

// nanoBase uses time.Now to ensure a monotonic clock reading on all platforms
// via time.Since.
var nanoBase = time.Now()

// nanotimePortable implements sys.Nanotime with time.Since.
//
// Note: This is less efficient than it could be is reading runtime.nanotime(),
// Just to do that requires CGO.
func nanotimePortable() int64 {
	return time.Since(nanoBase).Nanoseconds()
}

// Nanotime implements sys.Nanotime with runtime.nanotime() if CGO is available
// and time.Since if not.
func () int64 {
	return nanotime()
}

// Nanosleep implements sys.Nanosleep with time.Sleep.
func ( int64) {
	time.Sleep(time.Duration())
}