Versions in this module Expand all Collapse all v0 v0.1.0 Jul 12, 2026 Changes in this version + const DefaultHoldThreshold + const DefaultMaxKeys + const DefaultMaxWaiting + const DefaultWaitThreshold + var ErrBusy = errors.New("powerlock: lock is busy") + var ErrCancelled = errors.New("powerlock: lock was cancelled") + var ErrInvalidConfig = errors.New("powerlock: invalid configuration") + var ErrMaxKeys = errors.New("powerlock: maximum keyed locks reached") + var ErrMaxWaiting = errors.New("powerlock: maximum waiting acquisitions reached") + type AcquisitionError struct + Cause error + MaxWaiting int + Mode LockMode + Name string + Result LockResult + State LockState + func (e *AcquisitionError) Error() string + func (e *AcquisitionError) Unwrap() error + type CancelMutex struct + func NewCancelMutex(name string) *CancelMutex + func (m *CancelMutex) Cancel() + func (m *CancelMutex) Cancelled() bool + func (m *CancelMutex) Lock() + func (m *CancelMutex) LockContext(ctx context.Context) error + func (m *CancelMutex) Name() string + func (m *CancelMutex) SetLocation(name string) + func (m *CancelMutex) Snapshot() LockState + func (m *CancelMutex) TryLock() bool + func (m *CancelMutex) Unlock() + type CancelRWMutex struct + func NewCancelRWMutex(location string) *CancelRWMutex + func (m *CancelRWMutex) Cancel() + func (m *CancelRWMutex) Cancelled() bool + func (m *CancelRWMutex) Lock() + func (m *CancelRWMutex) LockContext(ctx context.Context) error + func (m *CancelRWMutex) Name() string + func (m *CancelRWMutex) RLock() + func (m *CancelRWMutex) RLockContext(ctx context.Context) error + func (m *CancelRWMutex) RLocker() sync.Locker + func (m *CancelRWMutex) RUnlock() + func (m *CancelRWMutex) SetLocation(location string) + func (m *CancelRWMutex) Snapshot() LockState + func (m *CancelRWMutex) TryLock() bool + func (m *CancelRWMutex) TryRLock() bool + func (m *CancelRWMutex) Unlock() + type ContextMutex struct + func NewContextMutex(name string) *ContextMutex + func (m *ContextMutex) Lock() + func (m *ContextMutex) LockContext(ctx context.Context) error + func (m *ContextMutex) Name() string + func (m *ContextMutex) SetLocation(name string) + func (m *ContextMutex) Snapshot() LockState + func (m *ContextMutex) TryLock() bool + func (m *ContextMutex) Unlock() + type ContextRWMutex struct + func NewContextRWMutex(location string) *ContextRWMutex + func (m *ContextRWMutex) Lock() + func (m *ContextRWMutex) LockContext(ctx context.Context) error + func (m *ContextRWMutex) Name() string + func (m *ContextRWMutex) RLock() + func (m *ContextRWMutex) RLockContext(ctx context.Context) error + func (m *ContextRWMutex) RLocker() sync.Locker + func (m *ContextRWMutex) RUnlock() + func (m *ContextRWMutex) SetLocation(location string) + func (m *ContextRWMutex) Snapshot() LockState + func (m *ContextRWMutex) TryLock() bool + func (m *ContextRWMutex) TryRLock() bool + func (m *ContextRWMutex) Unlock() + type FairMutex = ContextMutex + func NewFairMutex(name string) *FairMutex + type FairRWMutex = ContextRWMutex + func NewFairRWMutex(name string) *FairRWMutex + type FlightRecorderCallback func(LockEvent) + type KeyGuard struct + func (g *KeyGuard[K]) AttemptID() LockAttemptID + func (g *KeyGuard[K]) Key() K + func (g *KeyGuard[K]) Released() bool + func (g *KeyGuard[K]) Unlock() + type KeyedAcquisitionError struct + ActiveKeys int + Cause error + Key K + MaxKeys int + Name string + func (e *KeyedAcquisitionError[K]) Error() string + func (e *KeyedAcquisitionError[K]) Unwrap() error + type KeyedMutex struct + func NewKeyedMutexWithLimit[K comparable](name string, maxKeys int) *KeyedMutex[K] + func NewKeyedMutex[K comparable](name string) *KeyedMutex[K] + func (m *KeyedMutex[K]) ActiveKeys() int + func (m *KeyedMutex[K]) Lock(key K) + func (m *KeyedMutex[K]) LockContext(ctx context.Context, key K) error + func (m *KeyedMutex[K]) LockGuard(ctx context.Context, key K) (*KeyGuard[K], error) + func (m *KeyedMutex[K]) MaxKeys() int + func (m *KeyedMutex[K]) Name() string + func (m *KeyedMutex[K]) SetLocation(name string) + func (m *KeyedMutex[K]) Snapshot(key K) (LockState, bool) + func (m *KeyedMutex[K]) TryLock(key K) bool + func (m *KeyedMutex[K]) Unlock(key K) + type LockAttemptID uint64 + type LockEvent struct + AttemptID LockAttemptID + Callers []uintptr + Contended bool + ExactHold bool + HoldDuration time.Duration + HoldDurationKnown bool + Kind LockEventKind + Mode LockMode + Name string + Result LockResult + State LockState + WaitDuration time.Duration + func (e LockEvent) Caller() string + func (e LockEvent) String() string + type LockEventKind uint8 + const LockEventAcquired + const LockEventHoldExceeded + const LockEventRejected + const LockEventReleased + const LockEventTryFailed + const LockEventWaitExceeded + const LockEventWaitStarted + func (k LockEventKind) String() string + type LockGuard struct + func (g *LockGuard) AttemptID() LockAttemptID + func (g *LockGuard) Mode() LockMode + func (g *LockGuard) Released() bool + func (g *LockGuard) Unlock() + type LockMode uint8 + const LockModeRead + const LockModeWrite + func (m LockMode) String() string + type LockObserver interface + ObserveLock func(LockEvent) + type LockObserverFunc func(LockEvent) + func (f LockObserverFunc) ObserveLock(event LockEvent) + type LockObserverGroup []LockObserver + func (g LockObserverGroup) ObserveLock(event LockEvent) + type LockResult uint8 + const LockResultAcquired + const LockResultBusy + const LockResultCancelled + const LockResultDeadlineExceeded + const LockResultQueueFull + func (r LockResult) String() string + type LockState struct + Cancelled bool + Name string + OldestWaitDuration time.Duration + ReaderCohortHoldDuration time.Duration + Readers int + Version uint64 + WaitingReaders int + WaitingWriters int + Writer bool + WriterHoldDuration time.Duration + type MaxMutex struct + func NewMaxMutex(name string) *MaxMutex + func NewMaxMutexWithLimit(name string, maxWaiting int) *MaxMutex + func (m *MaxMutex) Lock() + func (m *MaxMutex) LockContext(ctx context.Context) error + func (m *MaxMutex) MaxWaiting() int + func (m *MaxMutex) Name() string + func (m *MaxMutex) SetLocation(name string) + func (m *MaxMutex) Snapshot() LockState + func (m *MaxMutex) TryLock() bool + func (m *MaxMutex) Unlock() + type MaxRWMutex struct + func NewMaxRWMutex(location string) *MaxRWMutex + func NewMaxRWMutexWithLimit(location string, maxWaiting int) *MaxRWMutex + func (m *MaxRWMutex) Lock() + func (m *MaxRWMutex) LockContext(ctx context.Context) error + func (m *MaxRWMutex) MaxWaiting() int + func (m *MaxRWMutex) Name() string + func (m *MaxRWMutex) RLock() + func (m *MaxRWMutex) RLockContext(ctx context.Context) error + func (m *MaxRWMutex) RLocker() sync.Locker + func (m *MaxRWMutex) RUnlock() + func (m *MaxRWMutex) SetLocation(location string) + func (m *MaxRWMutex) Snapshot() LockState + func (m *MaxRWMutex) TryLock() bool + func (m *MaxRWMutex) TryRLock() bool + func (m *MaxRWMutex) Unlock() + type ObservedMutex struct + func NewObservedMutex(name string, observer LockObserver) *ObservedMutex + func (m *ObservedMutex) Lock() + func (m *ObservedMutex) LockContext(ctx context.Context) error + func (m *ObservedMutex) LockGuard(ctx context.Context) (*LockGuard, error) + func (m *ObservedMutex) Name() string + func (m *ObservedMutex) SetLocation(name string) + func (m *ObservedMutex) Snapshot() LockState + func (m *ObservedMutex) TryLock() bool + func (m *ObservedMutex) TryLockGuard() (*LockGuard, bool) + func (m *ObservedMutex) Unlock() + type ObservedRWMutex struct + func NewObservedRWMutex(name string, observer LockObserver) *ObservedRWMutex + func (m *ObservedRWMutex) Lock() + func (m *ObservedRWMutex) LockContext(ctx context.Context) error + func (m *ObservedRWMutex) LockGuard(ctx context.Context) (*LockGuard, error) + func (m *ObservedRWMutex) Name() string + func (m *ObservedRWMutex) RLock() + func (m *ObservedRWMutex) RLockContext(ctx context.Context) error + func (m *ObservedRWMutex) RLockGuard(ctx context.Context) (*LockGuard, error) + func (m *ObservedRWMutex) RLocker() sync.Locker + func (m *ObservedRWMutex) RUnlock() + func (m *ObservedRWMutex) SetLocation(location string) + func (m *ObservedRWMutex) Snapshot() LockState + func (m *ObservedRWMutex) TryLock() bool + func (m *ObservedRWMutex) TryLockGuard() (*LockGuard, bool) + func (m *ObservedRWMutex) TryRLock() bool + func (m *ObservedRWMutex) TryRLockGuard() (*LockGuard, bool) + func (m *ObservedRWMutex) Unlock() + type ProfileObserver struct + func DefaultProfileObserver() *ProfileObserver + func (o *ProfileObserver) HolderCount() int + func (o *ProfileObserver) HolderProfileName() string + func (o *ProfileObserver) ObserveLock(event LockEvent) + func (o *ProfileObserver) WaiterCount() int + func (o *ProfileObserver) WaiterProfileName() string + type RuntimeTraceObserver struct + func NewRuntimeTraceObserver(onThreshold FlightRecorderCallback) *RuntimeTraceObserver + func (o *RuntimeTraceObserver) ObserveLock(event LockEvent) + type WatchdogMutex struct + func NewWatchdogMutex(name string, observer LockObserver) *WatchdogMutex + func NewWatchdogMutexWithThresholds(name string, waitThreshold time.Duration, holdThreshold time.Duration, ...) *WatchdogMutex + func (m *WatchdogMutex) HoldThreshold() time.Duration + func (m *WatchdogMutex) Lock() + func (m *WatchdogMutex) LockContext(ctx context.Context) error + func (m *WatchdogMutex) LockGuard(ctx context.Context) (*LockGuard, error) + func (m *WatchdogMutex) Name() string + func (m *WatchdogMutex) SetLocation(name string) + func (m *WatchdogMutex) Snapshot() LockState + func (m *WatchdogMutex) TryLock() bool + func (m *WatchdogMutex) TryLockGuard() (*LockGuard, bool) + func (m *WatchdogMutex) Unlock() + func (m *WatchdogMutex) WaitThreshold() time.Duration + type WatchdogRWMutex struct + func NewWatchdogRWMutex(name string, observer LockObserver) *WatchdogRWMutex + func NewWatchdogRWMutexWithThresholds(name string, waitThreshold time.Duration, holdThreshold time.Duration, ...) *WatchdogRWMutex + func (m *WatchdogRWMutex) HoldThreshold() time.Duration + func (m *WatchdogRWMutex) Lock() + func (m *WatchdogRWMutex) LockContext(ctx context.Context) error + func (m *WatchdogRWMutex) LockGuard(ctx context.Context) (*LockGuard, error) + func (m *WatchdogRWMutex) Name() string + func (m *WatchdogRWMutex) RLock() + func (m *WatchdogRWMutex) RLockContext(ctx context.Context) error + func (m *WatchdogRWMutex) RLockGuard(ctx context.Context) (*LockGuard, error) + func (m *WatchdogRWMutex) RLocker() sync.Locker + func (m *WatchdogRWMutex) RUnlock() + func (m *WatchdogRWMutex) SetLocation(name string) + func (m *WatchdogRWMutex) Snapshot() LockState + func (m *WatchdogRWMutex) TryLock() bool + func (m *WatchdogRWMutex) TryLockGuard() (*LockGuard, bool) + func (m *WatchdogRWMutex) TryRLock() bool + func (m *WatchdogRWMutex) TryRLockGuard() (*LockGuard, bool) + func (m *WatchdogRWMutex) Unlock() + func (m *WatchdogRWMutex) WaitThreshold() time.Duration