atomic

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2016 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 AtomicArray

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

AtomicArray implement a fixed width array with atomic semantics

func NewAtomicArray

func NewAtomicArray(length int) *AtomicArray

NewAtomicArray generates a new AtomicArray instance.

func (*AtomicArray) Get

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

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

func (*AtomicArray) Length

func (aa *AtomicArray) Length() int

Length returns the array size.

func (*AtomicArray) Set

func (aa *AtomicArray) 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 AtomicBool

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

AtomicBool implements a synchronized boolean value

func NewAtomicBool

func NewAtomicBool(value bool) *AtomicBool

NewAtomicBool generates a new AtomicBoolean instance.

func (*AtomicBool) CompareAndToggle added in v1.3.0

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

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

func (*AtomicBool) Get

func (ab *AtomicBool) Get() bool

Get atomically retrieves the boolean value.

func (*AtomicBool) Set

func (ab *AtomicBool) Set(newVal bool)

Set atomically sets the boolean value.

type AtomicInt

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

AtomicInt implements an int value with atomic semantics

func NewAtomicInt

func NewAtomicInt(value int) *AtomicInt

NewAtomicInt generates a newVal AtomicInt instance.

func (*AtomicInt) AddAndGet

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

AddAndGet atomically adds the given value to the current value.

func (*AtomicInt) CompareAndSet

func (ai *AtomicInt) 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 (*AtomicInt) DecrementAndGet

func (ai *AtomicInt) DecrementAndGet() int

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

func (*AtomicInt) Get

func (ai *AtomicInt) Get() int

Get atomically retrieves the current value.

func (*AtomicInt) GetAndAdd

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

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

func (*AtomicInt) GetAndDecrement

func (ai *AtomicInt) GetAndDecrement() int

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

func (*AtomicInt) GetAndIncrement

func (ai *AtomicInt) GetAndIncrement() int

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

func (*AtomicInt) GetAndSet

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

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

func (*AtomicInt) IncrementAndGet

func (ai *AtomicInt) IncrementAndGet() int

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

func (*AtomicInt) Set

func (ai *AtomicInt) Set(newValue int)

Set atomically sets current value to the given value.

type AtomicQueue

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

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

func NewAtomicQueue

func NewAtomicQueue(size int) *AtomicQueue

NewQueue creates a new queue with initial size.

func (*AtomicQueue) Offer

func (q *AtomicQueue) 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 (*AtomicQueue) Poll

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

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

type SyncVal added in v1.17.0

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

func NewSyncVal added in v1.17.0

func NewSyncVal(val interface{}) *SyncVal

NewSyncVal creates a new instance of SyncVal

func (*SyncVal) Get added in v1.17.0

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

Get returns the value inside the SyncVal

func (*SyncVal) GetSyncedVia added in v1.17.0

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

GetSyncedVia returns the value returned by the function f.

func (*SyncVal) Set added in v1.17.0

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

Set updates the value of SyncVal with the passed argument

func (*SyncVal) Update added in v1.17.0

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