locker

package
v0.0.0-...-cf2fa2e Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package locker provides a concurrency control mechanism to manage locks based on unique identifiers. It allows multiple goroutines to safely acquire and release locks associated with specific IDs, ensuring that resources tied to these IDs are not accessed concurrently. The package uses reference counting to clean up unused locks, optimizing memory usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

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

Locker is a struct that manages a collection of locks. Each lock is associated with a unique ID and is reference counted.

func New

func New() *Locker

func (*Locker) Acquire

func (l *Locker) Acquire(id string)

Acquire obtains a lock for the specified ID. If the lock does not exist, it is created. Acquire increments the reference count for the lock, indicating that it is in use.

func (*Locker) Release

func (l *Locker) Release(id string)

Release releases the lock for the specified ID. It decrements the reference count for the lock, and if the count reaches zero, the lock is removed from the Locker. This frees up resources for locks that are no longer in use.

Jump to

Keyboard shortcuts

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