2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-11-29 19:38:33 +00:00
|
|
|
package locking
|
2020-03-10 20:01:20 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2023-01-11 19:32:05 +00:00
|
|
|
|
|
|
|
"github.com/sasha-s/go-deadlock"
|
2020-03-10 20:01:20 +00:00
|
|
|
)
|
|
|
|
|
2023-01-11 19:32:05 +00:00
|
|
|
// Common mutex interface to allow either built-in or imported deadlock use
|
|
|
|
type Mutex interface {
|
|
|
|
Lock()
|
|
|
|
Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Common r/w mutex interface to allow either built-in or imported deadlock use
|
|
|
|
type RWMutex interface {
|
|
|
|
Lock()
|
|
|
|
RLock()
|
|
|
|
RLocker() sync.Locker
|
|
|
|
RUnlock()
|
|
|
|
Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeadlockMutex (used when requested via config option `detact_deadlocks`),
|
|
|
|
// behaves like a sync.Mutex but does periodic checking to see if outstanding
|
|
|
|
// locks and requests look like a deadlock. If it finds a deadlock candidate it
|
|
|
|
// will output it prefixed with "POTENTIAL DEADLOCK", as described at
|
|
|
|
// https://github.com/sasha-s/go-deadlock
|
2020-03-10 20:01:20 +00:00
|
|
|
type DeadlockMutex struct {
|
2023-01-11 19:32:05 +00:00
|
|
|
deadlock.Mutex
|
2020-03-10 20:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeadlockRWMutex is the RW version of DeadlockMutex.
|
|
|
|
type DeadlockRWMutex struct {
|
2023-01-11 19:32:05 +00:00
|
|
|
deadlock.RWMutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regular sync/mutex.
|
|
|
|
type SyncMutex struct {
|
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeadlockRWMutex is the RW version of SyncMutex.
|
|
|
|
type SyncRWMutex struct {
|
2020-03-10 20:01:20 +00:00
|
|
|
sync.RWMutex
|
|
|
|
}
|