Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NewCond = sync.NewCond
NewCond is a sync.NewCond wrapper
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 if 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 // Controls timer pooling behavior. // TimerPoolDefault: Automatically choose based on build environment // TimerPoolEnabled: Always use timer pooling // TimerPoolDisabled: Never use timer pooling TimerPool TimerPoolMode 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.
func (*Mutex) Lock ¶
func (m *Mutex) Lock()
Lock locks the mutex. If the lock is already in use, the calling goroutine blocks until the mutex is available.
Unless deadlock detection is disabled, logs potential deadlocks to Opts.LogBuf, calling Opts.OnPotentialDeadlock on each occasion.
type MutexImpl ¶ added in v0.3.7
type MutexImpl interface {
Lock()
Unlock()
TryLock() bool
}
MutexImpl defines the interface for mutex implementations
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) RLocker ¶
RLocker returns a Locker interface that implements the Lock and Unlock methods by calling RLock and RUnlock.
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) TryLock ¶ added in v0.3.2
TryLock tries to lock rw for writing. Returns false if the lock is already locked for reading or writing, true otherwise.
func (*RWMutex) TryRLock ¶ added in v0.3.2
TryRLock tries to lock rw for reading. Returns false if the lock is already locked for writing, true otherwise.
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 RWMutexImpl ¶ added in v0.3.7
type RWMutexImpl interface {
Lock()
Unlock()
RLock()
RUnlock()
TryLock() bool
TryRLock() bool
RLocker() sync.Locker
}
RWMutexImpl defines the interface for rwmutex implementations
type StandardMutex ¶ added in v0.3.7
type StandardMutex struct {
// contains filtered or unexported fields
}
StandardMutex wraps sync.Mutex
func (*StandardMutex) Lock ¶ added in v0.3.7
func (m *StandardMutex) Lock()
func (*StandardMutex) TryLock ¶ added in v0.3.7
func (m *StandardMutex) TryLock() bool
func (*StandardMutex) Unlock ¶ added in v0.3.7
func (m *StandardMutex) Unlock()
type StandardRWMutex ¶ added in v0.3.7
type StandardRWMutex struct {
// contains filtered or unexported fields
}
StandardRWMutex wraps sync.RWMutex
func (*StandardRWMutex) Lock ¶ added in v0.3.7
func (m *StandardRWMutex) Lock()
func (*StandardRWMutex) RLock ¶ added in v0.3.7
func (m *StandardRWMutex) RLock()
func (*StandardRWMutex) RLocker ¶ added in v0.3.7
func (m *StandardRWMutex) RLocker() sync.Locker
func (*StandardRWMutex) RUnlock ¶ added in v0.3.7
func (m *StandardRWMutex) RUnlock()
func (*StandardRWMutex) TryLock ¶ added in v0.3.7
func (m *StandardRWMutex) TryLock() bool
func (*StandardRWMutex) TryRLock ¶ added in v0.3.7
func (m *StandardRWMutex) TryRLock() bool
func (*StandardRWMutex) Unlock ¶ added in v0.3.7
func (m *StandardRWMutex) Unlock()
type TimerPoolMode ¶ added in v0.3.7
type TimerPoolMode int
TimerPoolMode controls timer pooling behavior
const ( // TimerPoolDefault automatically chooses based on build environment TimerPoolDefault TimerPoolMode = iota // TimerPoolEnabled always uses timer pooling for performance TimerPoolEnabled // TimerPoolDisabled disables timer pooling (required for testing/synctest) TimerPoolDisabled )