mutexpool

package
v0.0.0-...-c912a3c Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 2 Imported by: 5

Documentation

Overview

Package mutexpool implements P, a pool of keyed mutexes. These mutexes are created on-demand and deleted when no longer referenced, so the pool's maximum size is a function of the maximum number of concurrent mutexes held at any given time.

Package mutexpool is useful when coordinating access to resources that are not managed by the accessor such as remote resource accesses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type P

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

P is a pool of keyed mutexes. The zero value is a valid empty pool.

A user can grab an arbitrary Mutex's lock by calling WithMutex with a key. If something else currently holds that Mutex's lock, WithMutex will block until it can claim the lock. When a key is no longer in use, it will be removed from P.

func (*P) WithMutex

func (pc *P) WithMutex(key any, fn func())

WithMutex locks the Mutex matching the specified key and executes fn while holding its lock.

If a mutex for key doesn't exist, one will be created, and will be automatically cleaned up when no longer referenced.

Jump to

Keyboard shortcuts

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