locks

package
v0.0.0-...-eec02a6 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecrementQueueSize

func DecrementQueueSize(lockID string)

DecrementQueueSize decrements the wait queue size by 1

func IncrementQueueSize

func IncrementQueueSize(lockID string)

IncrementQueueSize increments the wait queue size by 1

func Lock

func Lock(ctx context.Context, lockContext, lockID string)

Lock acquires a mutex with the specified ID. The mutex does not need to exist before calling this method. The semantics of this method are intentionally identical to sync.Mutex.Lock().

func Unlock

func Unlock(ctx context.Context, lockContext, lockID string)

Unlock releases a mutex with the specified ID. The semantics of this method are intentionally identical to sync.Mutex.Unlock().

func WaitQueueSize

func WaitQueueSize(lockID string) uint32

WaitQueueSize returns the wait queue size

Types

type GCNamedMutex

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

GCNamedMutex provides garbage-collected named RW mutexes.

func NewGCNamedMutex

func NewGCNamedMutex() *GCNamedMutex

func (*GCNamedMutex) Lock

func (g *GCNamedMutex) Lock(name string)

func (*GCNamedMutex) LockWithGuard

func (g *GCNamedMutex) LockWithGuard(name string) Guard

LockWithGuard acquires a write lock and returns a wrapper for convenient unlock handling. The caller is responsible for calling Unlock() - typically via defer. Usage:

locked := mutex.LockWithGuard("resourceName")
defer locked.Unlock()

func (*GCNamedMutex) RLock

func (g *GCNamedMutex) RLock(name string)

func (*GCNamedMutex) RLockWithGuard

func (g *GCNamedMutex) RLockWithGuard(name string) Guard

RLockWithGuard acquires a read lock and returns a wrapper for convenient unlock handling. The caller is responsible for calling Unlock() - typically via defer. Usage:

locked := mutex.RLockWithGuard("resourceName")
defer locked.Unlock()

func (*GCNamedMutex) RUnlock

func (g *GCNamedMutex) RUnlock(name string)

func (*GCNamedMutex) Unlock

func (g *GCNamedMutex) Unlock(name string)

type Guard

type Guard interface {
	Name() string
	Unlock()
}

Guard is the unlock handle returned by GCNamedMutex.LockWithGuard.

type LockedResource

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

LockedResource is a wrapper that holds a named lock and its unlock function. It provides idempotent unlock behavior - safe to call Unlock() multiple times. Note: Go has no destructors, so the caller must explicitly call Unlock() (typically via defer).

func (*LockedResource) Name

func (lr *LockedResource) Name() string

Name returns the resource name that is locked.

func (*LockedResource) Unlock

func (lr *LockedResource) Unlock()

Unlock releases the lock on this resource. Safe to call multiple times (subsequent calls are no-ops).

type NamedLocker

type NamedLocker interface {
	LockWithGuard(name string) Guard
}

NamedLocker provides garbage-collected named write locks. *GCNamedMutex is the production implementation; tests may inject gomock.MockNamedLocker to assert lock scope.

Jump to

Keyboard shortcuts

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