Skip to content

Commit

Permalink
Merge pull request #74386 from danielqsj/keymutex-1.13
Browse files Browse the repository at this point in the history
fix negative slice index error in keymutex in 1.13
  • Loading branch information
k8s-ci-robot authored Feb 27, 2019
2 parents 50f6dc4 + 2bc81c2 commit a3bf928
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/util/keymutex/hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ type hashedKeyMutex struct {
// Acquires a lock associated with the specified ID.
func (km *hashedKeyMutex) LockKey(id string) {
klog.V(5).Infof("hashedKeyMutex.LockKey(...) called for id %q\r\n", id)
km.mutexes[km.hash(id)%len(km.mutexes)].Lock()
km.mutexes[km.hash(id)%uint32(len(km.mutexes))].Lock()
klog.V(5).Infof("hashedKeyMutex.LockKey(...) for id %q completed.\r\n", id)
}

// Releases the lock associated with the specified ID.
func (km *hashedKeyMutex) UnlockKey(id string) error {
klog.V(5).Infof("hashedKeyMutex.UnlockKey(...) called for id %q\r\n", id)
km.mutexes[km.hash(id)%len(km.mutexes)].Unlock()
km.mutexes[km.hash(id)%uint32(len(km.mutexes))].Unlock()
klog.V(5).Infof("hashedKeyMutex.UnlockKey(...) for id %q completed.\r\n", id)
return nil
}

func (km *hashedKeyMutex) hash(id string) int {
func (km *hashedKeyMutex) hash(id string) uint32 {
h := fnv.New32a()
h.Write([]byte(id))
return int(h.Sum32())
return h.Sum32()
}

0 comments on commit a3bf928

Please sign in to comment.