platform

package
v1.0.0-beta.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package platform includes runtime-specific code needed for the compiler or otherwise.

Note: This is a dependency-free alternative to depending on parts of Go's x/sys. See /RATIONALE.md for more context.

Index

Constants

View Source
const (

	// FakeEpochNanos is midnight UTC 2022-01-01 and exposed for testing
	FakeEpochNanos = 1640995200000 * ms
)

Variables

This section is empty.

Functions

func CompilerSupported

func CompilerSupported() bool

CompilerSupported is exported for tests and includes constraints here and also the assembler.

func FakeNanosleep

func FakeNanosleep(context.Context, int64)

FakeNanosleep implements sys.Nanosleep by returning without sleeping.

func MmapCodeSegment

func MmapCodeSegment(code io.Reader, size int) ([]byte, error)

MmapCodeSegment copies the code into the executable region and returns the byte slice of the region.

See https://man7.org/linux/man-pages/man2/mmap.2.html for mmap API and flags.

func MunmapCodeSegment

func MunmapCodeSegment(code []byte) error

MunmapCodeSegment unmaps the given memory region.

func Nanosleep

func Nanosleep(_ context.Context, ns int64)

Nanosleep implements sys.Nanosleep with time.Sleep.

func Nanotime

func Nanotime(context.Context) int64

Nanotime implements sys.Nanotime with runtime.nanotime() if CGO is available and time.Since if not.

func NewFakeNanotime

func NewFakeNanotime() *sys.Nanotime

NewFakeNanotime implements sys.Nanotime that increases by 1ms each reading. See /RATIONALE.md

func NewFakeRandSource

func NewFakeRandSource() io.Reader

NewFakeRandSource returns a deterministic source of random values.

func NewFakeWalltime

func NewFakeWalltime() *sys.Walltime

NewFakeWalltime implements sys.Walltime with FakeEpochNanos that increases by 1ms each reading. See /RATIONALE.md

func Walltime

func Walltime(context.Context) (sec int64, nsec int32)

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL