atomicutil

package
v1.128.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: Apache-2.0 Imports: 3 Imported by: 5

Documentation

Index

Constants

View Source
const CacheLineSize = unsafe.Sizeof(cpu.CacheLinePad{})

CacheLineSize is the size of a CPU cache line

Variables

This section is empty.

Functions

This section is empty.

Types

type Slice

type Slice[T any] struct {
	// Init is an optional callback for initializing the created item x.
	Init func(x *T)
	// contains filtered or unexported fields
}

Slice allows goroutine-safe access to []*T items with automatic growth of the slice.

This is a replacement for [workersCount]*T where workersCount isn't known beforehand.

It also prevents from false sharing of the created T items on multi-CPU systems.

func (*Slice[T]) All added in v1.102.20

func (s *Slice[T]) All() []*T

All returns the underlying []*T.

The length of the returned slice equals to the max(workerID)+1 passed to s.Get(). It is guaranteed that all the items in the returned slice are non-nil.

It is unsafe calling this function when concurrent goroutines access s.

All() is relatively slow, so it shouldn't be called in hot paths.

func (*Slice[T]) Get

func (s *Slice[T]) Get(workerID uint) *T

Get returns *T item for the given workerID in a goroutine-safe manner.

The returned item is automatically created via s.New on the first access.

It is expected that only a single goroutine can access *T at workerID index at any given time.

type Uint64 added in v1.102.23

type Uint64 struct {
	atomic.Uint64
	// contains filtered or unexported fields
}

Uint64 is like atomic.Uint64, but is protected from false sharing.

Jump to

Keyboard shortcuts

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