atomicbitops

package
v0.0.0-...-394d085 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0, MIT Imports: 3 Imported by: 113

Documentation

Overview

Package atomicbitops provides extensions to the sync/atomic package.

All read-modify-write operations implemented by this package have acquire-release memory ordering (like sync/atomic).

+checkalignedignore

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AndUint32

func AndUint32(addr *Uint32, val uint32)

AndUint32 atomically applies bitwise AND operation to *addr with val.

func AndUint64

func AndUint64(addr *Uint64, val uint64)

AndUint64 atomically applies bitwise AND operation to *addr with val.

func CompareAndSwapUint32

func CompareAndSwapUint32(addr *Uint32, old, new uint32) uint32

CompareAndSwapUint32 is like sync/atomic.CompareAndSwapUint32, but returns the value previously stored at addr.

func CompareAndSwapUint64

func CompareAndSwapUint64(addr *Uint64, old, new uint64) uint64

CompareAndSwapUint64 is like sync/atomic.CompareAndSwapUint64, but returns the value previously stored at addr.

func OrUint32

func OrUint32(addr *Uint32, val uint32)

OrUint32 atomically applies bitwise OR operation to *addr with val.

func OrUint64

func OrUint64(addr *Uint64, val uint64)

OrUint64 atomically applies bitwise OR operation to *addr with val.

func XorUint32

func XorUint32(addr *Uint32, val uint32)

XorUint32 atomically applies bitwise XOR operation to *addr with val.

func XorUint64

func XorUint64(addr *Uint64, val uint64)

XorUint64 atomically applies bitwise XOR operation to *addr with val.

Types

type Bool

type Bool struct {
	Uint32
}

Bool is an atomic Boolean.

It is implemented by a Uint32, with value 0 indicating false, and 1 indicating true.

+stateify savable

func FromBool

func FromBool(val bool) Bool

FromBool returns a Bool initialized to value val.

func (*Bool) CompareAndSwap

func (b *Bool) CompareAndSwap(oldVal, newVal bool) bool

CompareAndSwap is analogous to atomic.CompareAndSwapBool, if such a thing existed.

func (*Bool) Load

func (b *Bool) Load() bool

Load is analogous to atomic.LoadBool, if such a thing existed.

func (*Bool) RacyLoad

func (b *Bool) RacyLoad() bool

RacyLoad is analogous to reading an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Bool) RacyStore

func (b *Bool) RacyStore(val bool)

RacyStore is analogous to setting an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Bool) Store

func (b *Bool) Store(val bool)

Store is analogous to atomic.StoreBool, if such a thing existed.

func (*Bool) Swap

func (b *Bool) Swap(val bool) bool

Swap is analogous to atomic.SwapBool, if such a thing existed.

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

Float64 is an atomic 64-bit floating-point number.

+stateify savable

func FromFloat64

func FromFloat64(v float64) Float64

FromFloat64 returns a Float64 initialized to value v.

func (*Float64) Add

func (f *Float64) Add(v float64)

Add increments the float by the given value. Note that unlike an atomic integer, this requires spin-looping until we win the compare-and-swap race, so this may take an indeterminate amount of time.

func (*Float64) CompareAndSwap

func (f *Float64) CompareAndSwap(oldVal, newVal float64) bool

CompareAndSwap does a compare-and-swap operation on the float64 value. Note that unlike typical IEEE 754 semantics, this function will treat NaN as equal to itself if all of its bits exactly match.

func (*Float64) Load

func (f *Float64) Load() float64

Load loads the floating-point value.

func (*Float64) RacyLoad

func (f *Float64) RacyLoad() float64

RacyLoad is analogous to reading an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Float64) RacyStore

func (f *Float64) RacyStore(v float64)

RacyStore is analogous to setting an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Float64) Store

func (f *Float64) Store(v float64)

Store stores the given floating-point value in the Float64.

func (*Float64) Swap

func (f *Float64) Swap(v float64) float64

Swap stores the given value and returns the previously-stored one.

type Int32

type Int32 struct {
	// contains filtered or unexported fields
}

Int32 is an atomic int32.

The default value is zero.

Don't add fields to this struct. It is important that it remain the same size as its builtin analogue.

+stateify savable

func FromInt32

func FromInt32(v int32) Int32

FromInt32 returns an Int32 initialized to value v.

func (*Int32) Add

func (i *Int32) Add(v int32) int32

Add is analogous to atomic.AddInt32.

func (*Int32) CompareAndSwap

func (i *Int32) CompareAndSwap(oldVal, newVal int32) bool

CompareAndSwap is analogous to atomic.CompareAndSwapInt32.

func (*Int32) Load

func (i *Int32) Load() int32

Load is analogous to atomic.LoadInt32.

func (*Int32) RacyAdd

func (i *Int32) RacyAdd(v int32) int32

RacyAdd is analogous to adding to an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Int32) RacyLoad

func (i *Int32) RacyLoad() int32

RacyLoad is analogous to reading an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Int32) RacyStore

func (i *Int32) RacyStore(v int32)

RacyStore is analogous to setting an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Int32) Store

func (i *Int32) Store(v int32)

Store is analogous to atomic.StoreInt32.

func (*Int32) Swap

func (i *Int32) Swap(v int32) int32

Swap is analogous to atomic.SwapInt32.

type Int64

type Int64 struct {
	// contains filtered or unexported fields
}

Int64 is an atomic int64 that is guaranteed to be 64-bit aligned, even on 32-bit systems. On most architectures, it's just a regular int64.

The default value is zero.

Don't add fields to this struct. It is important that it remain the same size as its builtin analogue.

See aligned_32bit_unsafe.go in this directory for justification.

+stateify savable

func FromInt64

func FromInt64(v int64) Int64

FromInt64 returns an Int64 initialized to value v.

func (*Int64) Add

func (i *Int64) Add(v int64) int64

Add is analogous to atomic.AddInt64.

func (*Int64) CompareAndSwap

func (i *Int64) CompareAndSwap(oldVal, newVal int64) bool

CompareAndSwap is analogous to atomic.CompareAndSwapInt64.

func (*Int64) Load

func (i *Int64) Load() int64

Load is analogous to atomic.LoadInt64.

func (*Int64) RacyAdd

func (i *Int64) RacyAdd(v int64) int64

RacyAdd is analogous to adding to an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Int64) RacyLoad

func (i *Int64) RacyLoad() int64

RacyLoad is analogous to reading an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Int64) RacyStore

func (i *Int64) RacyStore(v int64)

RacyStore is analogous to setting an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Int64) Store

func (i *Int64) Store(v int64)

Store is analogous to atomic.StoreInt64.

func (*Int64) Swap

func (i *Int64) Swap(v int64) int64

Swap is analogous to atomic.SwapInt64.

type Uint32

type Uint32 struct {
	// contains filtered or unexported fields
}

Uint32 is an atomic uint32.

Don't add fields to this struct. It is important that it remain the same size as its builtin analogue.

See aligned_unsafe.go in this directory for justification.

+stateify savable

func FromUint32

func FromUint32(v uint32) Uint32

FromUint32 returns an Uint32 initialized to value v.

func (*Uint32) Add

func (u *Uint32) Add(v uint32) uint32

Add is analogous to atomic.AddUint32.

func (*Uint32) CompareAndSwap

func (u *Uint32) CompareAndSwap(oldVal, newVal uint32) bool

CompareAndSwap is analogous to atomic.CompareAndSwapUint32.

func (*Uint32) Load

func (u *Uint32) Load() uint32

Load is analogous to atomic.LoadUint32.

func (*Uint32) RacyAdd

func (u *Uint32) RacyAdd(v uint32) uint32

RacyAdd is analogous to adding to an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Uint32) RacyLoad

func (u *Uint32) RacyLoad() uint32

RacyLoad is analogous to reading an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Uint32) RacyStore

func (u *Uint32) RacyStore(v uint32)

RacyStore is analogous to setting an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Uint32) Store

func (u *Uint32) Store(v uint32)

Store is analogous to atomic.StoreUint32.

func (*Uint32) Swap

func (u *Uint32) Swap(v uint32) uint32

Swap is analogous to atomic.SwapUint32.

type Uint64

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

Uint64 is an atomic uint64 that is guaranteed to be 64-bit aligned, even on 32-bit systems. On most architectures, it's just a regular uint64.

Don't add fields to this struct. It is important that it remain the same size as its builtin analogue.

See aligned_unsafe.go in this directory for justification.

+stateify savable

func FromUint64

func FromUint64(v uint64) Uint64

FromUint64 returns an Uint64 initialized to value v.

func (*Uint64) Add

func (u *Uint64) Add(v uint64) uint64

Add is analogous to atomic.AddUint64.

func (*Uint64) CompareAndSwap

func (u *Uint64) CompareAndSwap(oldVal, newVal uint64) bool

CompareAndSwap is analogous to atomic.CompareAndSwapUint64.

func (*Uint64) Load

func (u *Uint64) Load() uint64

Load is analogous to atomic.LoadUint64.

func (*Uint64) RacyAdd

func (u *Uint64) RacyAdd(v uint64) uint64

RacyAdd is analogous to adding to an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Uint64) RacyLoad

func (u *Uint64) RacyLoad() uint64

RacyLoad is analogous to reading an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Uint64) RacyStore

func (u *Uint64) RacyStore(v uint64)

RacyStore is analogous to setting an atomic value without using synchronization.

It may be helpful to document why a racy operation is permitted.

func (*Uint64) Store

func (u *Uint64) Store(v uint64)

Store is analogous to atomic.StoreUint64.

func (*Uint64) Swap

func (u *Uint64) Swap(v uint64) uint64

Swap is analogous to atomic.SwapUint64.

Jump to

Keyboard shortcuts

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