cockroach: github.com/cockroachdb/cockroach/pkg/util/syncutil Index | Files | Directories

package syncutil

import "github.com/cockroachdb/cockroach/pkg/util/syncutil"

Index

Package Files

atomic.go int_map.go mutex_sync.go

func LoadFloat64 Uses

func LoadFloat64(addr *AtomicFloat64) (val float64)

LoadFloat64 atomically loads tha float64 value from the provided address.

func StoreFloat64 Uses

func StoreFloat64(addr *AtomicFloat64, val float64)

StoreFloat64 atomically stores a float64 value into the provided address.

type AtomicFloat64 Uses

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 Uses

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 Uses

func (m *IntMap) Delete(key int64)

Delete deletes the value for a key.

func (*IntMap) Load Uses

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 Uses

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 Uses

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 Uses

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

Store sets the value for a key.

type Mutex Uses

type Mutex struct {
    sync.Mutex
}

A Mutex is a mutual exclusion lock.

func (*Mutex) AssertHeld Uses

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 Uses

type RWMutex struct {
    sync.RWMutex
}

An RWMutex is a reader/writer mutual exclusion lock.

func (*RWMutex) AssertHeld Uses

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 Uses

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

PathSynopsis
singleflightPackage singleflight provides a duplicate function call suppression mechanism.

Package syncutil imports 4 packages (graph) and is imported by 530 packages. Updated 2019-09-25. Refresh now. Tools for package owners.