package atomicptrmap
import "gvisor.dev/gvisor/pkg/sync/atomicptrmap"
Package atomicptrmap instantiates generic_atomicptrmap for testing.
Package atomicptrmap doesn't exist. This file must be instantiated using the go_template_instance rule in tools/go_generics/defs.bzl.
Index ¶
- Constants
- type AtomicPtrMap
- func (m *AtomicPtrMap) CompareAndSwap(key Key, oldVal, newVal *Value) *Value
- func (m *AtomicPtrMap) Load(key Key) *Value
- func (m *AtomicPtrMap) Range(f func(key Key, val *Value) bool)
- func (m *AtomicPtrMap) RangeRepeatable(f func(key Key, val *Value) bool)
- func (m *AtomicPtrMap) Store(key Key, val *Value)
- func (m *AtomicPtrMap) Swap(key Key, val *Value) *Value
- type Hasher
- type Key
- type Value
Constants ¶
const ( // ShardOrder is an optional parameter specifying the base-2 log of the // number of shards per AtomicPtrMap. Higher values of ShardOrder reduce // unnecessary synchronization between unrelated concurrent operations, // improving performance for write-heavy workloads, but increase memory // usage for small maps. ShardOrder = 0 )
Types ¶
type AtomicPtrMap ¶
type AtomicPtrMap struct {
// contains filtered or unexported fields
}
An AtomicPtrMap maps Keys to non-nil pointers to Values. AtomicPtrMap are safe for concurrent use from multiple goroutines without additional synchronization.
The zero value of AtomicPtrMap is empty (maps all Keys to nil) and ready for use. AtomicPtrMaps must not be copied after first use.
sync.Map may be faster than AtomicPtrMap if most operations on the map are concurrent writes to a fixed set of keys. AtomicPtrMap is usually faster in other circumstances.
func (*AtomicPtrMap) CompareAndSwap ¶
func (m *AtomicPtrMap) CompareAndSwap(key Key, oldVal, newVal *Value) *Value
CompareAndSwap checks that the Value stored for key is oldVal; if it is, it stores the Value newVal for key. CompareAndSwap returns the previous Value stored for key, whether or not it stores newVal.
func (*AtomicPtrMap) Load ¶
func (m *AtomicPtrMap) Load(key Key) *Value
Load returns the Value stored in m for key.
func (*AtomicPtrMap) Range ¶
func (m *AtomicPtrMap) Range(f func(key Key, val *Value) bool)
Range invokes f on each Key-Value pair stored in m. If any call to f returns false, Range stops iteration and returns.
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.
f must not call other methods on m.
func (*AtomicPtrMap) RangeRepeatable ¶
func (m *AtomicPtrMap) RangeRepeatable(f func(key Key, val *Value) bool)
RangeRepeatable is like Range, but:
RangeRepeatable may visit the same Key multiple times in the presence of concurrent mutators, possibly passing different Values to f in different calls.
It is safe for f to call other methods on m.
func (*AtomicPtrMap) Store ¶
func (m *AtomicPtrMap) Store(key Key, val *Value)
Store stores the Value val for key.
func (*AtomicPtrMap) Swap ¶
func (m *AtomicPtrMap) Swap(key Key, val *Value) *Value
Swap stores the Value val for key and returns the previously-mapped Value.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is an optional type parameter. If Hasher is provided, it must define the Init and Hash methods. One Hasher will be shared by all AtomicPtrMaps.
func (*Hasher) Hash ¶
Hash returns the hash value for the given Key.
func (*Hasher) Init ¶
func (h *Hasher) Init()
Init initializes the Hasher.
type Key ¶
type Key struct{}
Key is a required type parameter.
type Value ¶
type Value struct{}
Value is a required type parameter.
Source Files ¶
atomicptrmap.go generic_atomicptrmap_unsafe.go
- Version
- v0.0.0-20250508033829-06acafc42203 (latest)
- Published
- May 8, 2025
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- 5 hours ago –
Tools for package owners.