mirror of
https://github.com/kopia/kopia.git
synced 2026-05-18 11:44:36 -04:00
chore(ci): added checklocks static analyzer (#1838)
From https://github.com/google/gvisor/tree/master/tools/checklocks This will perform static verification that we're using `sync.Mutex`, `sync.RWMutex` and `atomic` correctly to guard access to certain fields. This was mostly just a matter of adding annotations to indicate which fields are guarded by which mutex. In a handful of places the code had to be refactored to allow static analyzer to do its job better or to not be confused by some constructs. In one place this actually uncovered a bug where a function was not releasing a lock properly in an error case. The check is part of `make lint` but can also be invoked by `make check-locks`.
This commit is contained in:
@@ -35,33 +35,47 @@ type cliProgress struct {
|
||||
snapshotfs.NullUploadProgress
|
||||
|
||||
// all int64 must precede all int32 due to alignment requirements on ARM
|
||||
uploadedBytes int64
|
||||
cachedBytes int64
|
||||
// +checkatomic
|
||||
uploadedBytes int64
|
||||
// +checkatomic
|
||||
cachedBytes int64
|
||||
// +checkatomic
|
||||
hashedBytes int64
|
||||
outputThrottle timetrack.Throttle // is int64
|
||||
|
||||
cachedFiles int32
|
||||
// +checkatomic
|
||||
cachedFiles int32
|
||||
// +checkatomic
|
||||
inProgressHashing int32
|
||||
hashedFiles int32
|
||||
uploadedFiles int32
|
||||
// +checkatomic
|
||||
hashedFiles int32
|
||||
// +checkatomic
|
||||
uploadedFiles int32
|
||||
// +checkatomic
|
||||
ignoredErrorCount int32
|
||||
fatalErrorCount int32
|
||||
// +checkatomic
|
||||
fatalErrorCount int32
|
||||
|
||||
uploading int32
|
||||
// +checkatomic
|
||||
uploading int32
|
||||
// +checkatomic
|
||||
uploadFinished int32
|
||||
|
||||
lastLineLength int
|
||||
spinPhase int
|
||||
uploadStartTime timetrack.Estimator
|
||||
outputMutex sync.Mutex
|
||||
|
||||
estimatedFileCount int
|
||||
estimatedTotalBytes int64
|
||||
// +checklocks:outputMutex
|
||||
lastLineLength int
|
||||
// +checklocks:outputMutex
|
||||
spinPhase int
|
||||
|
||||
uploadStartTime timetrack.Estimator // +checklocksignore
|
||||
|
||||
estimatedFileCount int // +checklocksignore
|
||||
estimatedTotalBytes int64 // +checklocksignore
|
||||
|
||||
// indicates shared instance that does not reset counters at the beginning of upload.
|
||||
shared bool
|
||||
|
||||
outputMutex sync.Mutex
|
||||
|
||||
progressFlags
|
||||
}
|
||||
|
||||
@@ -181,6 +195,7 @@ func (p *cliProgress) output(col *color.Color, msg string) {
|
||||
p.out.printStderr("\r%v%v", line, extraSpaces)
|
||||
}
|
||||
|
||||
// +checklocks:p.outputMutex
|
||||
func (p *cliProgress) spinnerCharacter() string {
|
||||
if atomic.LoadInt32(&p.uploadFinished) == 1 {
|
||||
return "*"
|
||||
@@ -193,6 +208,7 @@ func (p *cliProgress) spinnerCharacter() string {
|
||||
return s
|
||||
}
|
||||
|
||||
// +checklocksignore.
|
||||
func (p *cliProgress) StartShared() {
|
||||
*p = cliProgress{
|
||||
uploading: 1,
|
||||
@@ -207,6 +223,7 @@ func (p *cliProgress) FinishShared() {
|
||||
p.output(defaultColor, "")
|
||||
}
|
||||
|
||||
// +checklocksignore.
|
||||
func (p *cliProgress) UploadStarted() {
|
||||
if p.shared {
|
||||
// do nothing
|
||||
|
||||
Reference in New Issue
Block a user