locks

package
v1.24.0-m3.4 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConditionVariable added in v1.11.0

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 added in v1.11.0

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

func NewConditionVariable added in v1.11.0

func NewConditionVariable(
	lock Locker,
) *ConditionVariableImpl

func (*ConditionVariableImpl) Broadcast added in v1.11.0

func (c *ConditionVariableImpl) Broadcast()

Broadcast wakes all goroutines waiting on this condition variable.

func (*ConditionVariableImpl) Signal added in v1.11.0

func (c *ConditionVariableImpl) Signal()

Signal wakes one goroutine waiting on this condition variable, if there is any.

func (*ConditionVariableImpl) Wait added in v1.11.0

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 HashFunc

type HashFunc func(interface{}) uint32

HashFunc represents a hash function for string

type IDMutex

type IDMutex interface {
	LockID(identifier interface{})
	UnlockID(identifier interface{})
}

IDMutex is an interface which can lock on specific comparable identifier

func NewIDMutex

func NewIDMutex(numShard uint32, hashFn HashFunc) IDMutex

NewIDMutex create a new IDLock

type Locker added in v1.11.0

type Locker interface {
	// Lock locks
	Lock()
	// Unlock unlocks
	Unlock()
}

Locker is the interface for lock

type PriorityMutex added in v1.11.0

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 added in v1.11.0

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

func NewPriorityMutex added in v1.11.0

func NewPriorityMutex() *PriorityMutexImpl

func (*PriorityMutexImpl) IsLocked added in v1.14.0

func (c *PriorityMutexImpl) IsLocked() bool

func (*PriorityMutexImpl) LockHigh added in v1.11.0

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 added in v1.11.0

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 added in v1.14.0

func (c *PriorityMutexImpl) TryLockHigh() bool

func (*PriorityMutexImpl) TryLockLow added in v1.14.0

func (c *PriorityMutexImpl) TryLockLow() bool

func (*PriorityMutexImpl) UnlockHigh added in v1.11.0

func (c *PriorityMutexImpl) UnlockHigh()

UnlockHigh unlock with high priority, use LockHigh / UnlockHigh pair to lock / unlock

func (*PriorityMutexImpl) UnlockLow added in v1.11.0

func (c *PriorityMutexImpl) UnlockLow()

UnlockLow unlock with low priority, use LockLow / UnlockLow pair to lock / unlock

type PriorityMutexState added in v1.11.0

type PriorityMutexState int
const (
	PriorityMutexStateUnlocked     PriorityMutexState = 0
	PriorityMutexStateLockedByHigh PriorityMutexState = 1
	PriorityMutexStateLockedByLow  PriorityMutexState = 2
)

Jump to

Keyboard shortcuts

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