atomic

package
v7.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapSyncValue added in v7.7.0

func MapSyncValue[T any, U any](sv *SyncVal[T], f func(T) (U, error)) (U, error)

MapSyncValue returns the value returned by the function f.

Types

type Array

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

Array implement a fixed width array with atomic semantics

func NewArray

func NewArray(length int) *Array

NewArray generates a new Array instance.

func (*Array) Get

func (aa *Array) Get(idx int) interface{}

Get atomically retrieves an element from the Array. If idx is out of range, it will return nil

func (*Array) Length

func (aa *Array) Length() int

Length returns the array size.

func (*Array) Set

func (aa *Array) Set(idx int, node interface{}) error

Set atomically sets an element in the Array. If idx is out of range, it will return an error

type Bool

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

Bool implements a synchronized boolean value

func NewBool

func NewBool(value bool) *Bool

NewBool generates a new Boolean instance.

func (*Bool) CompareAndToggle

func (ab *Bool) CompareAndToggle(expect bool) bool

CompareAndToggle atomically sets the boolean value if the current value is equal to updated value.

func (*Bool) Get

func (ab *Bool) Get() bool

Get atomically retrieves the boolean value.

func (*Bool) GomegaString

func (ab *Bool) GomegaString() string

GomegaString implements the GomegaStringer interface to prevent race conditions in tests

func (*Bool) Or

func (ab *Bool) Or(newVal bool) bool

Or atomically applies OR operation to the boolean value.

func (*Bool) Set

func (ab *Bool) Set(newVal bool)

Set atomically sets the boolean value.

func (*Bool) String

func (ab *Bool) String() string

String implements the Stringer interface

type Guard added in v7.7.0

type Guard[T any] struct {
	// contains filtered or unexported fields
}

Guard allows synchronized access to a value

func NewGuard added in v7.7.0

func NewGuard[T any](val *T) *Guard[T]

NewGuard creates a new instance of Guard

func (*Guard[T]) Do added in v7.7.0

func (g *Guard[T]) Do(f func(*T))

Do calls the passed closure.

func (*Guard[T]) DoVal added in v7.7.0

func (g *Guard[T]) DoVal(f func(T))

DoVal calls the passed closure with a dereferenced internal value.

func (*Guard[T]) InitDo added in v7.7.0

func (g *Guard[T]) InitDo(init func() *T, f func(*T))

Calls the passed closure allowing to replace the content. It will call the init func if the internal values is nil.

func (*Guard[T]) InitDoVal added in v7.7.0

func (g *Guard[T]) InitDoVal(init func() T, f func(T))

Calls the passed closure allowing to replace the content. It will call the init func if the internal values is nil. It is used for reference values like slices and maps.

func (*Guard[T]) Release added in v7.7.0

func (g *Guard[T]) Release() *T

Release returns the internal value and sets it to nil

func (*Guard[T]) Update added in v7.7.0

func (g *Guard[T]) Update(f func(**T))

Call the passed closure allowing to replace the content.

type Int

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

Int implements an int value with atomic semantics

func NewInt

func NewInt(value int) *Int

NewInt generates a newVal Int instance.

func (*Int) AddAndGet

func (ai *Int) AddAndGet(delta int) int

AddAndGet atomically adds the given value to the current value.

func (*Int) Clone

func (ai *Int) Clone() Int

CloneAndSet atomically clones the atomic Int and sets the value to the given updated value.

func (*Int) CloneAndSet

func (ai *Int) CloneAndSet(value int) Int

CloneAndSet atomically clones the atomic Int and sets the value to the given updated value.

func (*Int) CompareAndSet

func (ai *Int) CompareAndSet(expect int, update int) bool

CompareAndSet atomically sets the value to the given updated value if the current value == expected value. Returns true if the expectation was met

func (*Int) DecrementAndGet

func (ai *Int) DecrementAndGet() int

DecrementAndGet atomically decrements current value by one and returns the result.

func (*Int) Get

func (ai *Int) Get() int

Get atomically retrieves the current value.

func (*Int) GetAndAdd

func (ai *Int) GetAndAdd(delta int) int

GetAndAdd atomically adds the given delta to the current value and returns the result.

func (*Int) GetAndDecrement

func (ai *Int) GetAndDecrement() int

GetAndDecrement atomically decrements the current value by one and returns the result.

func (*Int) GetAndIncrement

func (ai *Int) GetAndIncrement() int

GetAndIncrement atomically increments current value by one and returns the result.

func (*Int) GetAndSet

func (ai *Int) GetAndSet(newValue int) int

GetAndSet atomically sets current value to the given value and returns the old value.

func (*Int) GomegaString

func (ai *Int) GomegaString() string

GomegaString implements the GomegaStringer interface to prevent race conditions during tests

func (*Int) IncrementAndGet

func (ai *Int) IncrementAndGet() int

IncrementAndGet atomically increments current value by one and returns the result.

func (*Int) Set

func (ai *Int) Set(newValue int)

Set atomically sets current value to the given value.

func (*Int) String

func (ai *Int) String() string

String implements the Stringer interface

type Queue

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

Queue is a non-blocking FIFO queue. If the queue is empty, nil is returned. if the queue is full, offer will return false

func NewQueue

func NewQueue(size int) *Queue

NewQueue creates a new queue with initial size.

func (*Queue) Offer

func (q *Queue) Offer(obj interface{}) bool

Offer adds an item to the queue unless the queue is full. In case the queue is full, the item will not be added to the queue and false will be returned

func (*Queue) Poll

func (q *Queue) Poll() (res interface{})

Poll removes and returns an item from the queue. If the queue is empty, nil will be returned.

type SyncVal

type SyncVal[T any] struct {
	// contains filtered or unexported fields
}

SyncVal allows synchronized access to a value

func NewSyncVal

func NewSyncVal[T any](val T) *SyncVal[T]

NewSyncVal creates a new instance of SyncVal

func (*SyncVal[T]) Get

func (sv *SyncVal[T]) Get() T

Get returns the value inside the SyncVal

func (*SyncVal[T]) GetSyncedVia

func (sv *SyncVal[T]) GetSyncedVia(f func(T) (T, error)) (T, error)

GetSyncedVia returns the value returned by the function f.

func (*SyncVal[T]) Set

func (sv *SyncVal[T]) Set(val T)

Set updates the value of SyncVal with the passed argument

func (*SyncVal[T]) Update

func (sv *SyncVal[T]) Update(f func(T) (T, error)) error

Update gets a function and passes the value of SyncVal to it. If the resulting err is nil, it will update the value of SyncVal. It will return the resulting error to the caller.

type TypedVal added in v7.7.0

type TypedVal[T any] atomic.Value

TypedVal allows synchronized access to a value

func (*TypedVal[T]) Get added in v7.7.0

func (sv *TypedVal[T]) Get() T

Get returns the value inside the TypedVal

func (*TypedVal[T]) Set added in v7.7.0

func (sv *TypedVal[T]) Set(val T)

Set updates the value of TypedVal with the passed argument

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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