syncutil

package
v0.0.0-...-1dc08c0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFloat64

func LoadFloat64(addr *AtomicFloat64) (val float64)

LoadFloat64 atomically loads tha float64 value from the provided address.

func StoreFloat64

func StoreFloat64(addr *AtomicFloat64, val float64)

StoreFloat64 atomically stores a float64 value into the provided address.

Types

type AtomicBool

type AtomicBool uint32

AtomicBool mimics an atomic boolean.

func (*AtomicBool) Get

func (b *AtomicBool) Get() bool

Get atomically gets the boolean.

func (*AtomicBool) Set

func (b *AtomicBool) Set(v bool)

Set atomically sets the boolean.

func (*AtomicBool) Swap

func (b *AtomicBool) Swap(v bool) bool

Swap atomically swaps the value.

type AtomicFloat64

type AtomicFloat64 uint64

AtomicFloat64 mimics the atomic types in the sync/atomic standard library, but for the float64 type. If you'd like to implement additional methods, consider checking out the expvar Float type for guidance: https://golang.org/src/expvar/expvar.go?s=2188:2222#L69

type IntMap

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

IntMap is a concurrent map with amortized-constant-time loads, stores, and deletes. It is safe for multiple goroutines to call a Map's methods concurrently.

It is optimized for use in concurrent loops with keys that are stable over time, and either few steady-state stores, or stores localized to one goroutine per key.

For use cases that do not share these attributes, it will likely have comparable or worse performance and worse type safety than an ordinary map paired with a read-write mutex.

Nil values are not supported; to use an IntMap as a set store a dummy non-nil pointer instead of nil.

The zero Map is valid and empty.

A Map must not be copied after first use.

func (*IntMap) Delete

func (m *IntMap) Delete(key int64)

Delete deletes the value for a key.

func (*IntMap) Load

func (m *IntMap) Load(key int64) (value unsafe.Pointer, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*IntMap) LoadOrStore

func (m *IntMap) LoadOrStore(key int64, value unsafe.Pointer) (actual unsafe.Pointer, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*IntMap) Range

func (m *IntMap) Range(f func(key int64, value unsafe.Pointer) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*IntMap) Store

func (m *IntMap) Store(key int64, value unsafe.Pointer)

Store sets the value for a key.

type Mutex

type Mutex struct {
	sync.Mutex
}

A Mutex is a mutual exclusion lock.

func (*Mutex) AssertHeld

func (m *Mutex) AssertHeld()

AssertHeld may panic if the mutex is not locked (but it is not required to do so). Functions which require that their callers hold a particular lock may use this to enforce this requirement more directly than relying on the race detector.

Note that we do not require the lock to be held by any particular thread, just that some thread holds the lock. This is both more efficient and allows for rare cases where a mutex is locked in one thread and used in another.

type RWMutex

type RWMutex struct {
	sync.RWMutex
}

An RWMutex is a reader/writer mutual exclusion lock.

func (*RWMutex) AssertHeld

func (rw *RWMutex) AssertHeld()

AssertHeld may panic if the mutex is not locked for writing (but it is not required to do so). Functions which require that their callers hold a particular lock may use this to enforce this requirement more directly than relying on the race detector.

Note that we do not require the exclusive lock to be held by any particular thread, just that some thread holds the lock. This is both more efficient and allows for rare cases where a mutex is locked in one thread and used in another.

func (*RWMutex) AssertRHeld

func (rw *RWMutex) AssertRHeld()

AssertRHeld may panic if the mutex is not locked for reading (but it is not required to do so). If the mutex is locked for writing, it is also considered to be locked for reading. Functions which require that their callers hold a particular lock may use this to enforce this requirement more directly than relying on the race detector.

Note that we do not require the shared lock to be held by any particular thread, just that some thread holds the lock. This is both more efficient and allows for rare cases where a mutex is locked in one thread and used in another.

Directories

Path Synopsis
Package singleflight provides a duplicate function call suppression mechanism.
Package singleflight provides a duplicate function call suppression mechanism.

Jump to

Keyboard shortcuts

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