syncx

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashMutex added in v1.24.1

type HashMutex struct {
	KeyMutex
	// contains filtered or unexported fields
}

HashMutex is a KeyMutex which reduces keys to a fixed number of bits so that there will only ever be a fixed number of mutexes. This means that there's no guarantee that two disctinct keys will use separate locks, but it is guaranteed that different calls with the same key, will use the same lock.

func NewHashMutex added in v1.24.1

func NewHashMutex(keybits int) *HashMutex

NewHashMutex creates a new hash mutex with keys reduced to the given number of bits, e.g. if bits is 4, then keys be reduced to 16 possible values.

func (*HashMutex) Lock added in v1.24.1

func (m *HashMutex) Lock(key string) func()

type KeyMutex added in v1.24.1

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

KeyMutex is a key based mutual exclusion lock. Different keys can hold the lock at the same time, same keys block.

m := KeyMutex{} unlock := m.Lock("key1") defer unlock()

Note that mutexes are not removed from the map when they are unlocked. Therefore the underlying map of mutexes can grow indefinitely.

func (*KeyMutex) Lock added in v1.24.1

func (m *KeyMutex) Lock(key string) func()

Lock locks on the given key and returns a function to unlock.

func (*KeyMutex) Range added in v1.24.1

func (m *KeyMutex) Range(f func(key, value any) bool)

Range is the same as sync.Map.Range.

Jump to

Keyboard shortcuts

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