Documentation
¶
Index ¶
- Variables
- type ConditionVariable
- type ConditionVariableImpl
- type HashFunc
- type IDMutex
- type Locker
- type Priority
- type PriorityMutex
- type PriorityMutexImpl
- func (c *PriorityMutexImpl) IsLocked() bool
- func (c *PriorityMutexImpl) LockHigh(ctx context.Context) error
- func (c *PriorityMutexImpl) LockLow(ctx context.Context) error
- func (c *PriorityMutexImpl) TryLockHigh() bool
- func (c *PriorityMutexImpl) TryLockLow() bool
- func (c *PriorityMutexImpl) UnlockHigh()
- func (c *PriorityMutexImpl) UnlockLow()
- type PriorityMutexState
- type PrioritySemaphore
- type PrioritySemaphoreImpl
Constants ¶
This section is empty.
Variables ¶
var (
ErrRequestTooLarge = serviceerror.NewInternal("request is larger than the size of semaphore")
)
Functions ¶
This section is empty.
Types ¶
type ConditionVariable ¶
type ConditionVariable interface {
// Signal wakes one goroutine waiting on this condition variable, if there is any.
Signal()
// Broadcast wakes all goroutines waiting on this condition variable.
Broadcast()
// Wait atomically unlocks user provided lock and suspends execution of the calling goroutine.
// After later resuming execution, Wait locks c.L before returning.
// Wait can be awoken by Broadcast, Signal or user provided interrupt channel.
Wait(interrupt <-chan struct{})
}
ConditionVariable is the interface for condition variable
type ConditionVariableImpl ¶
type ConditionVariableImpl struct {
// contains filtered or unexported fields
}
func NewConditionVariable ¶
func NewConditionVariable( lock Locker, ) *ConditionVariableImpl
func (*ConditionVariableImpl) Broadcast ¶
func (c *ConditionVariableImpl) Broadcast()
Broadcast wakes all goroutines waiting on this condition variable.
func (*ConditionVariableImpl) Signal ¶
func (c *ConditionVariableImpl) Signal()
Signal wakes one goroutine waiting on this condition variable, if there is any.
func (*ConditionVariableImpl) Wait ¶
func (c *ConditionVariableImpl) Wait( interrupt <-chan struct{}, )
Wait atomically unlocks user provided lock and suspends execution of the calling goroutine. After later resuming execution, Wait locks c.L before returning. Wait can be awoken by Broadcast, Signal or user provided interrupt channel.
type IDMutex ¶
IDMutex is an interface which can lock on specific comparable identifier
func NewIDMutex ¶
NewIDMutex create a new IDLock
type Locker ¶
type Locker interface {
// Lock locks
Lock()
// Unlock unlocks
Unlock()
}
Locker is the interface for lock
type PriorityMutex ¶
type PriorityMutex interface {
// LockHigh try to lock with high priority, use LockHigh / UnlockHigh pair to lock / unlock
LockHigh(context.Context) error
// LockLow try to lock with low priority, use LockLow / UnlockLow pair to lock / unlock
LockLow(context.Context) error
// UnlockHigh unlock with high priority, use LockHigh / UnlockHigh pair to lock / unlock
UnlockHigh()
// UnlockLow unlock with low priority, use LockLow / UnlockLow pair to lock / unlock
UnlockLow()
// TryLockHigh try to lock with high priority, return true if lock acquired
// use TryLockHigh / UnlockHigh pair to lock / unlock
TryLockHigh() bool
// TryLockLow try to lock with high priority, return true if lock acquired
// use TryLockLow / UnlockLow pair to lock / unlock
TryLockLow() bool
// IsLocked returns true if already locked
IsLocked() bool
}
type PriorityMutexImpl ¶
type PriorityMutexImpl struct {
// contains filtered or unexported fields
}
func NewPriorityMutex ¶
func NewPriorityMutex() *PriorityMutexImpl
func (*PriorityMutexImpl) IsLocked ¶
func (c *PriorityMutexImpl) IsLocked() bool
func (*PriorityMutexImpl) LockHigh ¶
func (c *PriorityMutexImpl) LockHigh( ctx context.Context, ) error
LockHigh try to lock with high priority, use LockHigh / UnlockHigh pair to lock / unlock
func (*PriorityMutexImpl) LockLow ¶
func (c *PriorityMutexImpl) LockLow( ctx context.Context, ) error
LockLow try to lock with low priority, use LockLow / UnlockLow pair to lock / unlock
func (*PriorityMutexImpl) TryLockHigh ¶
func (c *PriorityMutexImpl) TryLockHigh() bool
func (*PriorityMutexImpl) TryLockLow ¶
func (c *PriorityMutexImpl) TryLockLow() bool
func (*PriorityMutexImpl) UnlockHigh ¶
func (c *PriorityMutexImpl) UnlockHigh()
UnlockHigh unlock with high priority, use LockHigh / UnlockHigh pair to lock / unlock
func (*PriorityMutexImpl) UnlockLow ¶
func (c *PriorityMutexImpl) UnlockLow()
UnlockLow unlock with low priority, use LockLow / UnlockLow pair to lock / unlock
type PriorityMutexState ¶
type PriorityMutexState int
const ( PriorityMutexStateUnlocked PriorityMutexState = 0 PriorityMutexStateLockedByHigh PriorityMutexState = 1 PriorityMutexStateLockedByLow PriorityMutexState = 2 )
type PrioritySemaphore ¶
type PrioritySemaphoreImpl ¶
type PrioritySemaphoreImpl struct {
// contains filtered or unexported fields
}
func NewPrioritySemaphore ¶
func NewPrioritySemaphore(n int) *PrioritySemaphoreImpl
NewPrioritySemaphore creates a new semaphore with the given maximum combined weight for concurrent access, capable of handling multiple priority levels. Most of the logic is taken directly from golang's semaphore.Weighted.
func (*PrioritySemaphoreImpl) Acquire ¶
Acquire acquires the semaphore with a weight of n and a priority, blocking until resources are available or ctx is done. On success, returns nil. On failure, returns ctx.Err() and leaves the semaphore unchanged.
func (*PrioritySemaphoreImpl) Release ¶
func (s *PrioritySemaphoreImpl) Release(n int)
func (*PrioritySemaphoreImpl) TryAcquire ¶
func (s *PrioritySemaphoreImpl) TryAcquire(priority Priority, n int) bool
TryAcquire acquires the semaphore with a weight of n without blocking. On success, returns true. On failure, returns false and leaves the semaphore unchanged.