syncutil

package
v1.1.9-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFloat64 added in v1.1.0

func LoadFloat64(addr *AtomicFloat64) (val float64)

LoadFloat64 atomically loads tha float64 value from the provided address.

func StoreFloat64 added in v1.1.0

func StoreFloat64(addr *AtomicFloat64, val float64)

StoreFloat64 atomically stores a float64 value into the provided address.

Types

type AtomicFloat64 added in v1.1.0

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 added in v1.1.0

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.

The zero Map is valid and empty.

A Map must not be copied after first use.

func (*IntMap) Delete added in v1.1.0

func (m *IntMap) Delete(key int64)

Delete deletes the value for a key.

func (*IntMap) Load added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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 added in v1.1.0

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

Store sets the value for a key.

type Mutex

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

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.

func (*Mutex) Lock

func (m *Mutex) Lock()

Lock implements sync.Locker.

func (*Mutex) Unlock

func (m *Mutex) Unlock()

Unlock implements sync.Locker.

type RWMutex

type RWMutex struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

An RWMutex is a reader/writer mutual exclusion lock.

func (*RWMutex) AssertHeld

func (m *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 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) Lock

func (m *RWMutex) Lock()

Lock implements sync.Locker.

func (*RWMutex) Unlock

func (m *RWMutex) Unlock()

Unlock implements sync.Locker.

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