atomics

package module
v0.0.0-...-dc7a5fc Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: BSD-3-Clause Imports: 4 Imported by: 2

README

atomics

GoDoc Build Status Go Report Card

Package atomics implements efficient and useful atomic types.

See the documentation for use. This package should be self-explanatory.

Documentation

Overview

Package atomics implements efficient atomic types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

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

Bool provides an atomic bool.

func NewBool

func NewBool(val bool) *Bool

NewBool returns an atomic bool with a given value.

func (*Bool) CompareAndSwap

func (b *Bool) CompareAndSwap(old, new bool) (swapped bool)

CompareAndSwap sets the value of the bool to new but only if it currently has the value old. It returns true if the swap succeeded.

func (*Bool) Load

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

Load returns the value of the bool.

func (*Bool) Raw

func (b *Bool) Raw() *uint32

Raw returns a pointer to the underlying uint32.

It is only safe to access the pointer with methods from the sync/atomic package. Use caution if manually dereferencing.

The true value is stored as one, false is stored as zero.

The behaviour of Bool is undefined if this value is set to anything other than zero or one.

func (*Bool) Reset

func (b *Bool) Reset() (old bool)

Reset is a wrapper for Swap(false).

func (*Bool) Set

func (b *Bool) Set() (old bool)

Set is a wrapper for Swap(true).

func (*Bool) Store

func (b *Bool) Store(val bool)

Store sets the value of the bool.

func (*Bool) String

func (b *Bool) String() string

String implements fmt.Stringer.

func (*Bool) Swap

func (b *Bool) Swap(new bool) (old bool)

Swap sets the value of the bool and returns the old value.

type Float32

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

Float32 provides an atomic float32.

func NewFloat32

func NewFloat32(val float32) *Float32

NewFloat32 returns an atomic float32 with a given value.

func (*Float32) Add

func (v *Float32) Add(delta float32) (new float32)

Add adds delta to the float32.

func (*Float32) CompareAndSwap

func (v *Float32) CompareAndSwap(old, new float32) (swapped bool)

CompareAndSwap sets the value of the float32 to new but only if it currently has the value old. It returns true if the swap succeeded.

func (*Float32) Decrement

func (v *Float32) Decrement() (new float32)

Decrement is a wrapper for Add(-1).

func (*Float32) Increment

func (v *Float32) Increment() (new float32)

Increment is a wrapper for Add(1).

func (*Float32) Load

func (v *Float32) Load() (val float32)

Load returns the value of the float32.

func (*Float32) Raw

func (v *Float32) Raw() *uint32

Raw returns a pointer to the float32.

It is only safe to access the pointer with methods from the sync/atomic package. Use caution if manually dereferencing.

This returns the underlying uint32, to convert this to and from a float32, use math.Float32frombits and math.Float32bits respectively.

func (*Float32) Reset

func (v *Float32) Reset() (old float32)

Reset is a wrapper for Swap(0).

func (*Float32) Store

func (v *Float32) Store(val float32)

Store sets the value of the float32.

func (*Float32) String

func (v *Float32) String() string

String implements fmt.Stringer.

func (*Float32) Subtract

func (v *Float32) Subtract(delta float32) (new float32)

Subtract is a wrapper for Add(-delta)

func (*Float32) Swap

func (v *Float32) Swap(new float32) (old float32)

Swap sets the value of the float32 and returns the old value.

type Float64

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

Float64 provides an atomic float64.

func NewFloat64

func NewFloat64(val float64) *Float64

NewFloat64 returns an atomic float64 with a given value.

func (*Float64) Add

func (v *Float64) Add(delta float64) (new float64)

Add adds delta to the float64.

func (*Float64) CompareAndSwap

func (v *Float64) CompareAndSwap(old, new float64) (swapped bool)

CompareAndSwap sets the value of the float64 to new but only if it currently has the value old. It returns true if the swap succeeded.

func (*Float64) Decrement

func (v *Float64) Decrement() (new float64)

Decrement is a wrapper for Add(-1).

func (*Float64) Increment

func (v *Float64) Increment() (new float64)

Increment is a wrapper for Add(1).

func (*Float64) Load

func (v *Float64) Load() (val float64)

Load returns the value of the float64.

func (*Float64) Raw

func (v *Float64) Raw() *uint64

Raw returns a pointer to the float64.

It is only safe to access the pointer with methods from the sync/atomic package. Use caution if manually dereferencing.

This returns the underlying uint64, to convert this to and from a float64, use math.Float64frombits and math.Float64bits respectively.

func (*Float64) Reset

func (v *Float64) Reset() (old float64)

Reset is a wrapper for Swap(0).

func (*Float64) Store

func (v *Float64) Store(val float64)

Store sets the value of the float64.

func (*Float64) String

func (v *Float64) String() string

String implements fmt.Stringer.

func (*Float64) Subtract

func (v *Float64) Subtract(delta float64) (new float64)

Subtract is a wrapper for Add(-delta)

func (*Float64) Swap

func (v *Float64) Swap(new float64) (old float64)

Swap sets the value of the float64 and returns the old value.

type Int32

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

Int32 provides an atomic int32.

func NewInt32

func NewInt32(val int32) *Int32

NewInt32 returns an atomic int32 with a given value.

func (*Int32) Add

func (v *Int32) Add(delta int32) (new int32)

Add adds delta to the int32.

func (*Int32) CompareAndSwap

func (v *Int32) CompareAndSwap(old, new int32) (swapped bool)

CompareAndSwap sets the value of the int32 to new but only if it currently has the value old. It returns true if the swap succeeded.

func (*Int32) Decrement

func (v *Int32) Decrement() (new int32)

Decrement is a wrapper for Add(-1).

func (*Int32) Increment

func (v *Int32) Increment() (new int32)

Increment is a wrapper for Add(1).

func (*Int32) Load

func (v *Int32) Load() (val int32)

Load returns the value of the int32.

func (*Int32) Raw

func (v *Int32) Raw() *int32

Raw returns a pointer to the int32.

It is only safe to access the pointer with methods from the sync/atomic package. Use caution if manually dereferencing.

func (*Int32) Reset

func (v *Int32) Reset() (old int32)

Reset is a wrapper for Swap(0).

func (*Int32) Store

func (v *Int32) Store(val int32)

Store sets the value of the int32.

func (*Int32) String

func (v *Int32) String() string

String implements fmt.Stringer.

func (*Int32) Subtract

func (v *Int32) Subtract(delta int32) (new int32)

Subtract is a wrapper for Add(-delta)

func (*Int32) Swap

func (v *Int32) Swap(new int32) (old int32)

Swap sets the value of the int32 and returns the old value.

type Int64

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

Int64 provides an atomic int64.

func NewInt64

func NewInt64(val int64) *Int64

NewInt64 returns an atomic int64 with a given value.

func (*Int64) Add

func (v *Int64) Add(delta int64) (new int64)

Add adds delta to the int64.

func (*Int64) CompareAndSwap

func (v *Int64) CompareAndSwap(old, new int64) (swapped bool)

CompareAndSwap sets the value of the int64 to new but only if it currently has the value old. It returns true if the swap succeeded.

func (*Int64) Decrement

func (v *Int64) Decrement() (new int64)

Decrement is a wrapper for Add(-1).

func (*Int64) Increment

func (v *Int64) Increment() (new int64)

Increment is a wrapper for Add(1).

func (*Int64) Load

func (v *Int64) Load() (val int64)

Load returns the value of the int64.

func (*Int64) Raw

func (v *Int64) Raw() *int64

Raw returns a pointer to the int64.

It is only safe to access the pointer with methods from the sync/atomic package. Use caution if manually dereferencing.

func (*Int64) Reset

func (v *Int64) Reset() (old int64)

Reset is a wrapper for Swap(0).

func (*Int64) Store

func (v *Int64) Store(val int64)

Store sets the value of the int64.

func (*Int64) String

func (v *Int64) String() string

String implements fmt.Stringer.

func (*Int64) Subtract

func (v *Int64) Subtract(delta int64) (new int64)

Subtract is a wrapper for Add(-delta)

func (*Int64) Swap

func (v *Int64) Swap(new int64) (old int64)

Swap sets the value of the int64 and returns the old value.

type String

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

String provides an atomic string.

func NewString

func NewString(val string) *String

NewString returns an atomic string with a given value.

func (*String) Load

func (s *String) Load() string

Load returns the value of the string.

func (*String) Reset

func (s *String) Reset() (old string)

Reset is a wrapper for Swap("").

func (*String) Store

func (s *String) Store(val string)

Store sets the value of the string.

func (*String) String

func (s *String) String() string

String implements fmt.Stringer.

func (*String) Swap

func (s *String) Swap(new string) (old string)

Swap sets the value of the string and returns the old value.

type Uint32

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

Uint32 provides an atomic uint32.

func NewUint32

func NewUint32(val uint32) *Uint32

NewUint32 returns an atomic uint32 with a given value.

func (*Uint32) Add

func (v *Uint32) Add(delta uint32) (new uint32)

Add adds delta to the uint32.

func (*Uint32) CompareAndSwap

func (v *Uint32) CompareAndSwap(old, new uint32) (swapped bool)

CompareAndSwap sets the value of the uint32 to new but only if it currently has the value old. It returns true if the swap succeeded.

func (*Uint32) Decrement

func (v *Uint32) Decrement() (new uint32)

Decrement is a wrapper for Subtract(1).

func (*Uint32) Increment

func (v *Uint32) Increment() (new uint32)

Increment is a wrapper for Add(1).

func (*Uint32) Load

func (v *Uint32) Load() (val uint32)

Load returns the value of the uint32.

func (*Uint32) Raw

func (v *Uint32) Raw() *uint32

Raw returns a pointer to the uint32.

It is only safe to access the pointer with methods from the sync/atomic package. Use caution if manually dereferencing.

func (*Uint32) Reset

func (v *Uint32) Reset() (old uint32)

Reset is a wrapper for Swap(0).

func (*Uint32) Store

func (v *Uint32) Store(val uint32)

Store sets the value of the uint32.

func (*Uint32) String

func (v *Uint32) String() string

String implements fmt.Stringer.

func (*Uint32) Subtract

func (v *Uint32) Subtract(delta uint32) (new uint32)

Subtract subtracts delta from the uint32.

func (*Uint32) Swap

func (v *Uint32) Swap(new uint32) (old uint32)

Swap sets the value of the uint32 and returns the old value.

type Uint64

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

Uint64 provides an atomic uint64.

func NewUint64

func NewUint64(val uint64) *Uint64

NewUint64 returns an atomic uint64 with a given value.

func (*Uint64) Add

func (v *Uint64) Add(delta uint64) (new uint64)

Add adds delta to the uint64.

func (*Uint64) CompareAndSwap

func (v *Uint64) CompareAndSwap(old, new uint64) (swapped bool)

CompareAndSwap sets the value of the uint64 to new but only if it currently has the value old. It returns true if the swap succeeded.

func (*Uint64) Decrement

func (v *Uint64) Decrement() (new uint64)

Decrement is a wrapper for Subtract(1).

func (*Uint64) Increment

func (v *Uint64) Increment() (new uint64)

Increment is a wrapper for Add(1).

func (*Uint64) Load

func (v *Uint64) Load() (val uint64)

Load returns the value of the uint64.

func (*Uint64) Raw

func (v *Uint64) Raw() *uint64

Raw returns a pointer to the uint64.

It is only safe to access the pointer with methods from the sync/atomic package. Use caution if manually dereferencing.

func (*Uint64) Reset

func (v *Uint64) Reset() (old uint64)

Reset is a wrapper for Swap(0).

func (*Uint64) Store

func (v *Uint64) Store(val uint64)

Store sets the value of the uint64.

func (*Uint64) String

func (v *Uint64) String() string

String implements fmt.Stringer.

func (*Uint64) Subtract

func (v *Uint64) Subtract(delta uint64) (new uint64)

Subtract subtracts delta from the uint64.

func (*Uint64) Swap

func (v *Uint64) Swap(new uint64) (old uint64)

Swap sets the value of the uint64 and returns the old value.

Directories

Path Synopsis
Package maps implements maps of atomic types.
Package maps implements maps of atomic types.

Jump to

Keyboard shortcuts

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