package locking
import "gvisor.dev/gvisor/pkg/sync/locking"
Package locking implements lock primitives with the correctness validator.
All mutexes are divided on classes and the validator check following conditions:
- Mutexes of the same class are not taken more than once except cases when that is expected.
- Mutexes are never locked in a reverse order. Lock dependencies are tracked on the class level.
The validator is implemented in a very straightforward way. For each mutex class, we maintain the ancestors list of all classes that have ever been taken before the target one. For each goroutine, we have the list of currently locked mutexes. And finally, all lock methods check that ancestors of currently locked mutexes don't contain the target one.
Index ¶
- func AddGLock(*MutexClass, int)
- func DelGLock(*MutexClass, int)
- type Mutex
- func (m *Mutex) Lock()
- func (m *Mutex) NestedLock(i lockNameIndex)
- func (m *Mutex) NestedUnlock(i lockNameIndex)
- func (m *Mutex) Unlock()
- type MutexClass
- type RWMutex
Functions ¶
func AddGLock ¶
func AddGLock(*MutexClass, int)
AddGLock is no-op without the lockdep tag.
func DelGLock ¶
func DelGLock(*MutexClass, int)
DelGLock is no-op without the lockdep tag.
Types ¶
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
Mutex is sync.Mutex with the correctness validator.
func (*Mutex) Lock ¶
func (m *Mutex) Lock()
Lock locks m. +checklocksignore
func (*Mutex) NestedLock ¶
func (m *Mutex) NestedLock(i lockNameIndex)
NestedLock locks m knowing that another lock of the same type is held. +checklocksignore
func (*Mutex) NestedUnlock ¶
func (m *Mutex) NestedUnlock(i lockNameIndex)
NestedUnlock unlocks m knowing that another lock of the same type is held. +checklocksignore
func (*Mutex) Unlock ¶
func (m *Mutex) Unlock()
Unlock unlocks m. +checklocksignore
type MutexClass ¶
type MutexClass struct{}
MutexClass is a stub class without the lockdep tag.
func NewMutexClass ¶
func NewMutexClass(reflect.Type, []string) *MutexClass
NewMutexClass is no-op without the lockdep tag.
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
RWMutex is sync.RWMutex with the correctness validator.
func (*RWMutex) DowngradeLock ¶
func (m *RWMutex) DowngradeLock()
DowngradeLock atomically unlocks rw for writing and locks it for reading. +checklocksignore
func (*RWMutex) Lock ¶
func (m *RWMutex) Lock()
Lock locks m. +checklocksignore
func (*RWMutex) NestedLock ¶
func (m *RWMutex) NestedLock(i lockNameIndex)
NestedLock locks m knowing that another lock of the same type is held. +checklocksignore
func (*RWMutex) NestedUnlock ¶
func (m *RWMutex) NestedUnlock(i lockNameIndex)
NestedUnlock unlocks m knowing that another lock of the same type is held. +checklocksignore
func (*RWMutex) RLock ¶
func (m *RWMutex) RLock()
RLock locks m for reading. +checklocksignore
func (*RWMutex) RLockBypass ¶
func (m *RWMutex) RLockBypass()
RLockBypass locks m for reading without executing the validator. +checklocksignore
func (*RWMutex) RUnlock ¶
func (m *RWMutex) RUnlock()
RUnlock undoes a single RLock call. +checklocksignore
func (*RWMutex) RUnlockBypass ¶
func (m *RWMutex) RUnlockBypass()
RUnlockBypass undoes a single RLockBypass call. +checklocksignore
func (*RWMutex) Unlock ¶
func (m *RWMutex) Unlock()
Unlock unlocks m. +checklocksignore
Source Files ¶
generic_mutex.go generic_rwmutex.go lockdep_norace.go locking.go
- Version
- v0.0.0-20250508033829-06acafc42203 (latest)
- Published
- May 8, 2025
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 3 hours ago –
Tools for package owners.