atomics

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 5 Imported by: 1

README

go-atomics

This library provides a variety of types for atomic operations on common Go types.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool uint32

Bool provides user-friendly means of performing atomic operations on bool types.

func NewBool

func NewBool() *Bool

NewBool will return a new Bool instance initialized with zero value.

func (*Bool) CAS

func (b *Bool) CAS(cmp, swp bool) bool

CAS performs a compare-and-swap for a(n) bool value at address contained within i.

func (*Bool) Load

func (b *Bool) Load() bool

Load will atomically load bool value at address contained within i.

func (*Bool) Store

func (b *Bool) Store(val bool)

Store will atomically store bool value in address contained within i.

func (*Bool) Swap

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

Swap atomically stores new bool value into address contained within i, and returns previous value.

type Bytes

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

Bytes provides user-friendly means of performing atomic operations on []byte types.

func NewBytes

func NewBytes() *Bytes

NewBytes will return a new Bytes instance initialized with zero value.

func (*Bytes) CAS

func (v *Bytes) CAS(cmp, swp []byte) bool

CAS performs a compare-and-swap for a(n) []byte value at address contained within v.

func (*Bytes) Load

func (v *Bytes) Load() []byte

Load will atomically load []byte value at address contained within v.

func (*Bytes) Store

func (v *Bytes) Store(val []byte)

Store will atomically store []byte value in address contained within v.

func (*Bytes) Swap

func (v *Bytes) Swap(swp []byte) []byte

Swap atomically stores new []byte value into address contained within v, and returns previous value.

type Error

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

Error provides user-friendly means of performing atomic operations on error types.

func NewError

func NewError() *Error

NewError will return a new Error instance initialized with zero value.

func (*Error) CAS

func (v *Error) CAS(cmp, swp error) bool

CAS performs a compare-and-swap for a(n) error value at address contained within v.

func (*Error) Load

func (v *Error) Load() error

Load will atomically load error value at address contained within v.

func (*Error) Store

func (v *Error) Store(val error)

Store will atomically store error value in address contained within v.

func (*Error) Swap

func (v *Error) Swap(swp error) error

Swap atomically stores new error value into address contained within v, and returns previous value.

type Flags32

type Flags32 bitutil.Flags32

Flags32 provides user-friendly means of performing atomic operations on bitutil.Flags32 types.

func NewFlags32

func NewFlags32() *Flags32

NewFlags32 will return a new Flags32 instance initialized with zero value.

func (*Flags32) CAS

func (f *Flags32) CAS(cmp, swp bitutil.Flags32) bool

CAS performs a compare-and-swap for a(n) bitutil.Flags32 value at address contained within f.

func (*Flags32) Get

func (f *Flags32) Get(bit uint8) bool

Get will atomically load a(n) bitutil.Flags32 value contained within f, and check if bit value is set.

func (*Flags32) Load

func (f *Flags32) Load() bitutil.Flags32

Load will atomically load bitutil.Flags32 value at address contained within f.

func (*Flags32) Set

func (f *Flags32) Set(bit uint8) bool

Set performs a compare-and-swap for a(n) bitutil.Flags32 with bit value set, at address contained within f.

func (*Flags32) Store

func (f *Flags32) Store(val bitutil.Flags32)

Store will atomically store bitutil.Flags32 value in address contained within f.

func (*Flags32) Swap

func (f *Flags32) Swap(swp bitutil.Flags32) bitutil.Flags32

Swap atomically stores new bitutil.Flags32 value into address contained within f, and returns previous value.

func (*Flags32) Unset

func (f *Flags32) Unset(bit uint8) bool

Unset performs a compare-and-swap for a(n) bitutil.Flags32 with bit value unset, at address contained within f.

type Flags64

type Flags64 bitutil.Flags64

Flags64 provides user-friendly means of performing atomic operations on bitutil.Flags64 types.

func NewFlags64

func NewFlags64() *Flags64

NewFlags64 will return a new Flags64 instance initialized with zero value.

func (*Flags64) CAS

func (f *Flags64) CAS(cmp, swp bitutil.Flags64) bool

CAS performs a compare-and-swap for a(n) bitutil.Flags64 value at address contained within f.

func (*Flags64) Get

func (f *Flags64) Get(bit uint8) bool

Get will atomically load a(n) bitutil.Flags64 value contained within f, and check if bit value is set.

func (*Flags64) Load

func (f *Flags64) Load() bitutil.Flags64

Load will atomically load bitutil.Flags64 value at address contained within f.

func (*Flags64) Set

func (f *Flags64) Set(bit uint8) bool

Set performs a compare-and-swap for a(n) bitutil.Flags64 with bit value set, at address contained within f.

func (*Flags64) Store

func (f *Flags64) Store(val bitutil.Flags64)

Store will atomically store bitutil.Flags64 value in address contained within f.

func (*Flags64) Swap

func (f *Flags64) Swap(swp bitutil.Flags64) bitutil.Flags64

Swap atomically stores new bitutil.Flags64 value into address contained within f, and returns previous value.

func (*Flags64) Unset

func (f *Flags64) Unset(bit uint8) bool

Unset performs a compare-and-swap for a(n) bitutil.Flags64 with bit value unset, at address contained within f.

type Int32

type Int32 int32

Int32 provides user-friendly means of performing atomic operations on int32 types.

func NewInt32

func NewInt32() *Int32

NewInt32 will return a new Int32 instance initialized with zero value.

func (*Int32) Add

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

Add will atomically add int32 delta to value in address contained within i, returning new value.

func (*Int32) CAS

func (i *Int32) CAS(cmp, swp int32) bool

CAS performs a compare-and-swap for a(n) int32 value at address contained within i.

func (*Int32) Load

func (i *Int32) Load() int32

Load will atomically load int32 value at address contained within i.

func (*Int32) Store

func (i *Int32) Store(val int32)

Store will atomically store int32 value in address contained within i.

func (*Int32) Swap

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

Swap atomically stores new int32 value into address contained within i, and returns previous value.

type Int64

type Int64 int64

Int64 provides user-friendly means of performing atomic operations on int64 types.

func NewInt64

func NewInt64() *Int64

NewInt64 will return a new Int64 instance initialized with zero value.

func (*Int64) Add

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

Add will atomically add int64 delta to value in address contained within i, returning new value.

func (*Int64) CAS

func (i *Int64) CAS(cmp, swp int64) bool

CAS performs a compare-and-swap for a(n) int64 value at address contained within i.

func (*Int64) Load

func (i *Int64) Load() int64

Load will atomically load int64 value at address contained within i.

func (*Int64) Store

func (i *Int64) Store(val int64)

Store will atomically store int64 value in address contained within i.

func (*Int64) Swap

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

Swap atomically stores new int64 value into address contained within i, and returns previous value.

type Interface

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

Interface provides user-friendly means of performing atomic operations on interface{} types.

func NewInterface

func NewInterface() *Interface

NewInterface will return a new Interface instance initialized with zero value.

func (*Interface) CAS

func (v *Interface) CAS(cmp, swp interface{}) bool

CAS performs a compare-and-swap for a(n) interface{} value at address contained within v.

func (*Interface) Load

func (v *Interface) Load() interface{}

Load will atomically load interface{} value at address contained within v.

func (*Interface) Store

func (v *Interface) Store(val interface{})

Store will atomically store interface{} value in address contained within v.

func (*Interface) Swap

func (v *Interface) Swap(swp interface{}) interface{}

Swap atomically stores new interface{} value into address contained within v, and returns previous value.

type State added in v1.1.0

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

State provides user-friendly means of performing atomic-like operations on a uint32 state, and allowing callbacks on successful state change. This is a bit of a misnomer being where it is, as it actually uses a mutex under-the-hood.

func (*State) CAS added in v1.1.0

func (st *State) CAS(cmp, swp uint32, fn func()) (ok bool)

CAS performs a compare-and-swap on State, calling fn on success. Success value is also returned.

func (*State) Load added in v1.1.0

func (st *State) Load() uint32

Load will get value of State safely within mutex lock.

func (*State) Store added in v1.1.0

func (st *State) Store(val uint32)

Store will update State value safely within mutex lock.

func (*State) Update added in v1.1.0

func (st *State) Update(fn func(state uint32) uint32)

Update performs fn within State mutex lock, with the current state value provided as an argument, and return value used to update state.

func (*State) WithLock added in v1.1.0

func (st *State) WithLock(fn func())

WithLock performs fn within State mutex lock, useful if you want to just use State's mutex for locking instead of creating another.

type String

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

String provides user-friendly means of performing atomic operations on string types.

func NewString

func NewString() *String

NewString will return a new String instance initialized with zero value.

func (*String) CAS

func (v *String) CAS(cmp, swp string) bool

CAS performs a compare-and-swap for a(n) string value at address contained within v.

func (*String) Load

func (v *String) Load() string

Load will atomically load string value at address contained within v.

func (*String) Store

func (v *String) Store(val string)

Store will atomically store string value in address contained within v.

func (*String) Swap

func (v *String) Swap(swp string) string

Swap atomically stores new string value into address contained within v, and returns previous value.

type Time

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

Time provides user-friendly means of performing atomic operations on time.Time types.

func NewTime

func NewTime() *Time

NewTime will return a new Time instance initialized with zero value.

func (*Time) CAS

func (v *Time) CAS(cmp, swp time.Time) bool

CAS performs a compare-and-swap for a(n) time.Time value at address contained within v.

func (*Time) Load

func (v *Time) Load() time.Time

Load will atomically load time.Time value at address contained within v.

func (*Time) Store

func (v *Time) Store(val time.Time)

Store will atomically store time.Time value in address contained within v.

func (*Time) Swap

func (v *Time) Swap(swp time.Time) time.Time

Swap atomically stores new time.Time value into address contained within v, and returns previous value.

type Uint32

type Uint32 uint32

Uint32 provides user-friendly means of performing atomic operations on uint32 types.

func NewUint32

func NewUint32() *Uint32

NewUint32 will return a new Uint32 instance initialized with zero value.

func (*Uint32) Add

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

Add will atomically add uint32 delta to value in address contained within i, returning new value.

func (*Uint32) CAS

func (u *Uint32) CAS(cmp, swp uint32) bool

CAS performs a compare-and-swap for a(n) uint32 value at address contained within i.

func (*Uint32) Load

func (u *Uint32) Load() uint32

Load will atomically load uint32 value at address contained within i.

func (*Uint32) Store

func (u *Uint32) Store(val uint32)

Store will atomically store uint32 value in address contained within i.

func (*Uint32) Swap

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

Swap atomically stores new uint32 value into address contained within i, and returns previous value.

type Uint64

type Uint64 uint64

Uint64 provides user-friendly means of performing atomic operations on uint64 types.

func NewUint64

func NewUint64() *Uint64

NewUint64 will return a new Uint64 instance initialized with zero value.

func (*Uint64) Add

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

Add will atomically add uint64 delta to value in address contained within i, returning new value.

func (*Uint64) CAS

func (u *Uint64) CAS(cmp, swp uint64) bool

CAS performs a compare-and-swap for a(n) uint64 value at address contained within i.

func (*Uint64) Load

func (u *Uint64) Load() uint64

Load will atomically load uint64 value at address contained within i.

func (*Uint64) Store

func (u *Uint64) Store(val uint64)

Store will atomically store uint64 value in address contained within i.

func (*Uint64) Swap

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

Swap atomically stores new uint64 value into address contained within i, and returns previous value.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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