Skip to content

Commit

Permalink
review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Nov 14, 2022
1 parent 8c0e3c0 commit 5fc0986
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions controllers/remote/keyedmutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import (
// A second Lock call if the lock is already held for a key returns false.
type keyedMutex struct {
locksMtx sync.Mutex
locks map[client.ObjectKey]bool
locks map[client.ObjectKey]struct{}
}

// newKeyedMutex creates a new keyed mutex ready for use.
func newKeyedMutex() *keyedMutex {
return &keyedMutex{
locks: make(map[client.ObjectKey]bool),
locks: make(map[client.ObjectKey]struct{}),
}
}

Expand All @@ -51,7 +51,7 @@ func (k *keyedMutex) TryLock(key client.ObjectKey) bool {
}

// Lock doesn't exist yet, create the lock.
k.locks[key] = true
k.locks[key] = struct{}{}

return true
}
Expand All @@ -61,7 +61,6 @@ func (k *keyedMutex) Unlock(key client.ObjectKey) {
k.locksMtx.Lock()
defer k.locksMtx.Unlock()

if k.locks[key] {
delete(k.locks, key)
}
// Remove the lock if it exists.
delete(k.locks, key)
}

0 comments on commit 5fc0986

Please sign in to comment.