Skip to content

Commit

Permalink
fix negative slice index error
Browse files Browse the repository at this point in the history
  • Loading branch information
danielqsj committed Feb 21, 2019
1 parent cdba024 commit 9740b4c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions keymutex/hashed.go
Expand Up @@ -42,17 +42,17 @@ type hashedKeyMutex struct {

// Acquires a lock associated with the specified ID.
func (km *hashedKeyMutex) LockKey(id string) {
km.mutexes[km.hash(id)%len(km.mutexes)].Lock()
km.mutexes[km.hash(id)%uint32(len(km.mutexes))].Lock()
}

// Releases the lock associated with the specified ID.
func (km *hashedKeyMutex) UnlockKey(id string) error {
km.mutexes[km.hash(id)%len(km.mutexes)].Unlock()
km.mutexes[km.hash(id)%uint32(len(km.mutexes))].Unlock()
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 9740b4c

Please sign in to comment.