keymutex

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 1 Imported by: 2

README

keymutex

Acquire locks on arbitrary strings by hashing over a fixed set of locks.

KeyMutex uses a FNV-1a 32-bit hash of an input string to select a mutex from a list of locks. The hash is computed in a way that does not cause allocation by converting string to bytes, as with the standard library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyMutex

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

func New

func New(n int) *KeyMutex

New returns a new instance of KeyMutex which hashes arbitrary keys to a fixed set of locks, specified by n. Use the default value if n <= 0.

func (*KeyMutex) Lock

func (km *KeyMutex) Lock(k string)

Lock acquires the lock for the specified key.

func (*KeyMutex) LockBytes

func (km *KeyMutex) LockBytes(k []byte)

func (*KeyMutex) Unlock

func (km *KeyMutex) Unlock(k string)

Unlock releases the lock for the specified key.

func (*KeyMutex) UnlockBytes

func (km *KeyMutex) UnlockBytes(k []byte)

type KeyRWMutex added in v0.1.0

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

func NewRW added in v0.1.0

func NewRW(n int) *KeyRWMutex

NewRW returns a new instance of KeyRWMutex which hashes arbitrary keys to a fixed set of RWMutexes, specified by n. Use the default value if n <= 0.

func (*KeyRWMutex) Lock added in v0.1.0

func (km *KeyRWMutex) Lock(k string)

Lock acquires the lock for the specified key.

func (*KeyRWMutex) LockBytes added in v0.1.0

func (km *KeyRWMutex) LockBytes(k []byte)

func (*KeyRWMutex) RLock added in v0.1.0

func (km *KeyRWMutex) RLock(k string)

RLock acquires the shared lock for the specified key.

func (*KeyRWMutex) RLockBytes added in v0.1.0

func (km *KeyRWMutex) RLockBytes(k []byte)

func (*KeyRWMutex) RUnlock added in v0.1.0

func (km *KeyRWMutex) RUnlock(k string)

RUnlock releases the shared lock for the specified key.

func (*KeyRWMutex) RUnlockBytes added in v0.1.0

func (km *KeyRWMutex) RUnlockBytes(k []byte)

func (*KeyRWMutex) Unlock added in v0.1.0

func (km *KeyRWMutex) Unlock(k string)

Unlock releases the lock for the specified key.

func (*KeyRWMutex) UnlockBytes added in v0.1.0

func (km *KeyRWMutex) UnlockBytes(k []byte)

Jump to

Keyboard shortcuts

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