atomic

package
v4.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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) 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.

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) 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) 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.

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 struct {
	// contains filtered or unexported fields
}

SyncVal allows synchronized access to a value

func NewSyncVal

func NewSyncVal(val interface{}) *SyncVal

NewSyncVal creates a new instance of SyncVal

func (*SyncVal) Get

func (sv *SyncVal) Get() interface{}

Get returns the value inside the SyncVal

func (*SyncVal) GetSyncedVia

func (sv *SyncVal) GetSyncedVia(f func(interface{}) (interface{}, error)) (interface{}, error)

GetSyncedVia returns the value returned by the function f.

func (*SyncVal) Set

func (sv *SyncVal) Set(val interface{})

Set updates the value of SyncVal with the passed argument

func (*SyncVal) Update

func (sv *SyncVal) Update(f func(interface{}) (interface{}, 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.

Jump to

Keyboard shortcuts

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