Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Opts = struct { // Mutex/RWMutex would work exactly as their sync counterparts // -- almost no runtime penalty, no deadlock detection if Disable == true. Disable bool // Would disable lock order based deadlock detection if DisableLockOrderDetection == true. DisableLockOrderDetection bool // Waiting for a lock for longer than DeadlockTimeout is considered a deadlock. // Ignored is DeadlockTimeout <= 0. DeadlockTimeout time.Duration // OnPotentialDeadlock is called each time a potential deadlock is detected -- either based on // lock order or on lock wait time. OnPotentialDeadlock func() // Will keep MaxMapSize lock pairs (happens before // happens after) in the map. // The map resets once the threshold is reached. MaxMapSize int // Will dump stacktraces of all goroutines when inconsistent locking is detected. PrintAllCurrentGoroutines bool mu *sync.Mutex // Protects the LogBuf. // Will print deadlock info to log buffer. LogBuf io.Writer }{ DeadlockTimeout: time.Second * 30, OnPotentialDeadlock: func() { os.Exit(2) }, MaxMapSize: 1024 * 64, LogBuf: os.Stderr, // contains filtered or unexported fields }
Opts control how deadlock detection behaves. Options are supposed to be set once at a startup (say, when parsing flags).
Functions ¶
This section is empty.
Types ¶
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
A Mutex is a drop-in replacement for sync.Mutex. Performs deadlock detection unless disabled in Opts.
type MutexLog ¶
type MutexLog interface {
// contains filtered or unexported methods
}
MutexLog allows you to implement/attach your own logger
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
An RWMutex is a drop-in replacement for sync.RWMutex. Performs deadlock detection unless disabled in Opts.
func (*RWMutex) Lock ¶
func (m *RWMutex) Lock()
Lock locks rw for writing. If the lock is already locked for reading or writing, Lock blocks until the lock is available. To ensure that the lock eventually becomes available, a blocked Lock call excludes new readers from acquiring the lock.
Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf, calling Opts.OnPotentialDeadlock on each occasion.
func (*RWMutex) RLock ¶
func (m *RWMutex) RLock()
RLock locks the mutex for reading.
Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf, calling Opts.OnPotentialDeadlock on each occasion.
func (*RWMutex) RUnlock ¶
func (m *RWMutex) RUnlock()
RUnlock undoes a single RLock call; it does not affect other simultaneous readers. It is a run-time error if rw is not locked for reading on entry to RUnlock.
func (*RWMutex) Unlock ¶
func (m *RWMutex) Unlock()
Unlock unlocks the mutex for writing. It is a run-time error if rw is not locked for writing on entry to Unlock.
As with Mutexes, a locked RWMutex is not associated with a particular goroutine. One goroutine may RLock (Lock) an RWMutex and then arrange for another goroutine to RUnlock (Unlock) it.
type SmartMutex ¶
type SmartMutex struct {
// contains filtered or unexported fields
}
SmartMutex is a more extensive Mutex structure with Deadlock-detection and metrics of lock aquisition queues while most Mutexes in Go should be extremely localized in Scope and retain locks for a minimal time this Mutex structure is optimized for uses by a great many goroutines from multiple code scopes
func (*SmartMutex) Lock ¶
func (m *SmartMutex) Lock()
Lock provides deadlock-aware, queue-tracking Mutex Locks
func (*SmartMutex) Locked ¶
func (m *SmartMutex) Locked() bool
func (SmartMutex) Name ¶
func (m SmartMutex) Name() string
func (*SmartMutex) Queue ¶
func (m *SmartMutex) Queue() int
Queue returns the number of goroutines currently waiting to obtain a lock on this mutex
func (*SmartMutex) SoftLock ¶
func (m *SmartMutex) SoftLock()
SoftLock is intended to test if object is locked, usually to wait for a mutex'ed resource to stabilize but then just to wait for changes to complete before proceeding if you wish to make modifications during during the lock, call Lock() and Unlock() explicitly.
func (*SmartMutex) Unlock ¶
func (m *SmartMutex) Unlock()
Unlock implements standard Mutex Unlocking, with lock wait queue tracking support