kmutex

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: GPL-3.0 Imports: 1 Imported by: 15

README

GoDoc

kmutex

Synchronization primitive that allows locking individual resources by unique ID.

This is not a distributed lock.

See golang.org/x/sync/singleflight if you want to reduce the number of calls to the same resource. Use kmutex if you want only one caller to use a resource at time.

Kubernetes kmutex hashes keys to a fixed set of locks, and is useful if you do not always need a separate lock for each resource. Take a look at the implementation, it is very straight forward.

GO PLAYGROUND EXAMPLE

Documentation

Overview

Package kmutex is a synchronization primitive that allows locking individual resources by unique ID.

Key + Mutex = Kmutex

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kmutex

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

Can be locked by unique ID

func New

func New() *Kmutex

Create new Kmutex

func WithLock

func WithLock(l sync.Locker) *Kmutex

Create new Kmutex with user provided lock

func (*Kmutex) Lock

func (km *Kmutex) Lock(key interface{})

Lock Kmutex by unique ID

func (Kmutex) Locker

func (km Kmutex) Locker(key interface{}) sync.Locker

Return a object which implement sync.Locker interface A Locker represents an object that can be locked and unlocked.

func (*Kmutex) Unlock

func (km *Kmutex) Unlock(key interface{})

Unlock Kmutex by unique ID

Jump to

Keyboard shortcuts

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