sync

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MutexMap

type MutexMap[K comparable] struct {
	// contains filtered or unexported fields
}

MutexMap is a map of mutexes by a given key type [K].

The map keeps track of entities trying to lock a certain key. Upon releasing a key, if no entity wants to lock a key, the key is deleted from the map, keeping it as small as possible.

func NewMutexMap

func NewMutexMap[K comparable]() *MutexMap[K]

NewMutexMap creates a new MutexMap.

func (*MutexMap[K]) Count

func (m *MutexMap[K]) Count(key K) int

Count returns the number of locking entities for a given key. If a key is not present, 0 is returned.

func (*MutexMap[K]) Len

func (m *MutexMap[K]) Len() int

Len returns the number of entries in the MutexMap.

func (*MutexMap[K]) Lock

func (m *MutexMap[K]) Lock(key K)

Lock locks the given key.

func (*MutexMap[K]) Locker

func (m *MutexMap[K]) Locker(key K) sync.Locker

Locker returns a sync.Locker that locks / unlocks the given key in the MutexMap.

func (*MutexMap[K]) Unlock

func (m *MutexMap[K]) Unlock(key K)

Unlock unlocks the given key.

Jump to

Keyboard shortcuts

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