From 9740b4c1ffa7a9edc4bbbc459438cda242ab842b Mon Sep 17 00:00:00 2001 From: danielqsj Date: Tue, 19 Feb 2019 17:00:39 +0800 Subject: [PATCH] fix negative slice index error --- keymutex/hashed.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/keymutex/hashed.go b/keymutex/hashed.go index 54e28b00..4ddb0086 100644 --- a/keymutex/hashed.go +++ b/keymutex/hashed.go @@ -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() }