Documentation ¶
Index ¶
Constants ¶
const Debug = false
const Enabled = false
Enabled is true if deadlock checking is enabled
Variables ¶
var Opts = Options{ DeadlockTimeout: time.Second * 30, MaxMapSize: 1024 * 64, LogBuf: os.Stderr, }
Opts control how deadlock detection behaves. To safely read or change options during runtime, use Opts.ReadLocked() and Opts.WriteLocked()
Functions ¶
This section is empty.
Types ¶
type DeadlockMutex ¶
type DeadlockMutex struct {
// contains filtered or unexported fields
}
A DeadlockMutex is a drop-in replacement for sync.Mutex.
func (*DeadlockMutex) Lock ¶
func (m *DeadlockMutex) Lock()
Lock locks the mutex. If the lock is already in use, the calling goroutine blocks until the mutex is available.
Logs potential deadlocks to Opts.LogBuf, calling Opts.OnPotentialDeadlock on each occasion.
func (*DeadlockMutex) TryLock ¶ added in v0.2.0
func (m *DeadlockMutex) TryLock() bool
func (*DeadlockMutex) Unlock ¶
func (m *DeadlockMutex) Unlock()
Unlock unlocks the mutex. It is a run-time error if m is not locked on entry to Unlock.
A locked Mutex is not associated with a particular goroutine. It is allowed for one goroutine to lock a Mutex and then arrange for another goroutine to unlock it.
type DeadlockRWMutex ¶
type DeadlockRWMutex struct {
// contains filtered or unexported fields
}
An DeadlockRWMutex is a drop-in replacement for sync.RWMutex.
func (*DeadlockRWMutex) Lock ¶
func (m *DeadlockRWMutex) 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.
Logs potential deadlocks to Opts.LogBuf, calling Opts.OnPotentialDeadlock on each occasion.
func (*DeadlockRWMutex) RLock ¶
func (m *DeadlockRWMutex) RLock()
RLock locks the mutex for reading.
Logs potential deadlocks to Opts.LogBuf, calling Opts.OnPotentialDeadlock on each occasion.
func (*DeadlockRWMutex) RLocker ¶
func (m *DeadlockRWMutex) RLocker() sync.Locker
RLocker returns a Locker interface that implements the Lock and Unlock methods by calling RLock and RUnlock.
func (*DeadlockRWMutex) RUnlock ¶
func (m *DeadlockRWMutex) 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 (*DeadlockRWMutex) TryLock ¶ added in v0.2.0
func (m *DeadlockRWMutex) TryLock() bool
func (*DeadlockRWMutex) TryRLock ¶ added in v0.3.0
func (m *DeadlockRWMutex) TryRLock() bool
func (*DeadlockRWMutex) Unlock ¶
func (m *DeadlockRWMutex) 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 Options ¶
type Options struct { // Waiting for a lock for longer than a non-zero DeadlockTimeout is considered a deadlock. // Set to 30 seconds by default. DeadlockTimeout time.Duration // OnPotentialDeadlock is called each time a potential deadlock is detected -- either based on // lock order or on lock wait time. If nil, panics instead. OnPotentialDeadlock func() // Sets the maximum size of the map that tracks lock ordering. // Setting this to zero disables tracking of lock order. Default is a reasonable size. MaxMapSize int // Will dump stacktraces of all goroutines when inconsistent locking is detected. PrintAllCurrentGoroutines bool // Where to write reports, set to os.Stderr by default. LogBuf io.Writer }
func (*Options) PotentialDeadlock ¶ added in v0.0.2
func (opts *Options) PotentialDeadlock()
PotentialDeadlock calls OnPotentialDeadlock if it is set, or panics if not.
func (*Options) ReadLocked ¶
func (opts *Options) ReadLocked(fn func())
ReadLocked calls the given function with Opts locked for reading.
func (*Options) WriteLocked ¶
func (opts *Options) WriteLocked(fn func())
WriteLocked calls the given function with Opts locked for writing.