keymutex

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: MIT Imports: 1 Imported by: 0

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)

Jump to

Keyboard shortcuts

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