mirror of
https://github.com/restic/restic.git
synced 2026-06-17 14:14:19 +00:00
repository: remove redundant mutex in checkForOtherLocks
forAllLocks already serializes the callback calls. Still has to create a copy of checkedIDs to prevent a data race between forAllLocks and the callback.
This commit is contained in:
@@ -173,8 +173,7 @@ func (l *lockHandle) checkForOtherLocks(ctx context.Context) error {
|
||||
delay *= 2
|
||||
}
|
||||
|
||||
// Store updates in new IDSet to prevent data races
|
||||
var m sync.Mutex
|
||||
// Store updates in new IDSet to prevent data races with Has() check in forAllLocks
|
||||
newCheckedIDs := checkedIDs.Clone()
|
||||
err = forAllLocks(ctx, l.repo, checkedIDs, func(id restic.ID, lock *lockHandle, err error) error {
|
||||
if err != nil {
|
||||
@@ -189,9 +188,7 @@ func (l *lockHandle) checkForOtherLocks(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// valid locks will remain valid
|
||||
m.Lock()
|
||||
newCheckedIDs.Insert(id)
|
||||
m.Unlock()
|
||||
return nil
|
||||
})
|
||||
checkedIDs = newCheckedIDs
|
||||
|
||||
Reference in New Issue
Block a user