Documentation
¶
Index ¶
- func DecrementQueueSize(lockID string)
- func IncrementQueueSize(lockID string)
- func Lock(ctx context.Context, lockContext, lockID string)
- func Unlock(ctx context.Context, lockContext, lockID string)
- func WaitQueueSize(lockID string) uint32
- type GCNamedMutex
- type Guard
- type LockedResource
- type NamedLocker
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 ¶
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 ¶
Unlock releases a mutex with the specified ID. The semantics of this method are intentionally identical to sync.Mutex.Unlock().
func WaitQueueSize ¶
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 ¶
NamedLocker provides garbage-collected named write locks. *GCNamedMutex is the production implementation; tests may inject gomock.MockNamedLocker to assert lock scope.