Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix negative slice index error in keymutex #84

Merged
merged 1 commit into from Feb 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And yes, this is fine.

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()
}