Source File
time.go
Belonging Package
github.com/tetratelabs/wazero/internal/platform
package platformimport ()const (ms = int64(time.Millisecond)// FakeEpochNanos is midnight UTC 2022-01-01 and exposed for testingFakeEpochNanos = 1640995200000 * ms)// NewFakeWalltime implements sys.Walltime with FakeEpochNanos that increases by 1ms each reading.// See /RATIONALE.mdfunc () sys.Walltime {// AddInt64 returns the new value. Adjust so the first reading will be FakeEpochNanos:= FakeEpochNanos - msreturn func() ( int64, int32) {:= atomic.AddInt64(&, ms)return / 1e9, int32( % 1e9)}}// NewFakeNanotime implements sys.Nanotime that increases by 1ms each reading.// See /RATIONALE.mdfunc () sys.Nanotime {// AddInt64 returns the new value. Adjust so the first reading will be zero.:= int64(0) - msreturn 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())}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |