keyedmutex

package
v1.0.549 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package keyedmutex provides a per-key mutual-exclusion lock: callers that name the same string key run one at a time, and callers that name different keys do not wait for one another (ADR-0054).

A Mutex keeps one entry per key that is currently held or waited for, and removes the entry when its last holder or waiter releases it, so the set of keys a long-lived Mutex has seen does not grow without bound. The lock that guards the entry table is never held during a caller's critical section.

Each Mutex is independent: the package has no package-level state, no init, no goroutine, no I/O and no logging. The owner of a Mutex decides what a key means. Package main has two: the SaaS feed generation store serializes in-process writers of one generation id, and the CDR control plane serializes renewal, revoke, delete and enroll for one instance name (and one "op:"-prefixed operation id).

It is not a reader/writer lock, it is not reentrant (a goroutine that locks a key it already holds deadlocks, exactly as with sync.Mutex), and it takes no context: acquisition cannot be cancelled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

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

Mutex serializes work per string key without holding a global lock during the critical section. Construct one with New; the zero value is not usable.

func New

func New() *Mutex

New returns an empty Mutex.

func (*Mutex) Lock

func (k *Mutex) Lock(key string) func()

Lock acquires the per-key mutex and returns an unlock func that releases it and garbage-collects the entry when no waiters remain. The unlock func must be called exactly once.

Jump to

Keyboard shortcuts

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