Skip to content

Commit

Permalink
修改concurrent文件中对dict加锁方法(xxxWithLock)实际未用锁情况
Browse files Browse the repository at this point in the history
  • Loading branch information
suye committed Jan 14, 2025
1 parent 6aee2f9 commit 14440c0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions datastruct/dict/concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ func (dict *ConcurrentDict) Get(key string) (val interface{}, exists bool) {
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.Lock()
defer s.mutex.Unlock()
val, exists = s.m[key]
return
}
Expand All @@ -102,6 +100,8 @@ func (dict *ConcurrentDict) GetWithLock(key string) (val interface{}, exists boo
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.RLock()
defer s.mutex.RUnlock()
val, exists = s.m[key]
return
}
Expand All @@ -122,8 +122,6 @@ func (dict *ConcurrentDict) Put(key string, val interface{}) (result int) {
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.Lock()
defer s.mutex.Unlock()

if _, ok := s.m[key]; ok {
s.m[key] = val
Expand All @@ -141,6 +139,8 @@ func (dict *ConcurrentDict) PutWithLock(key string, val interface{}) (result int
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.Lock()
defer s.mutex.Unlock()

if _, ok := s.m[key]; ok {
s.m[key] = val
Expand All @@ -159,8 +159,6 @@ func (dict *ConcurrentDict) PutIfAbsent(key string, val interface{}) (result int
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.Lock()
defer s.mutex.Unlock()

if _, ok := s.m[key]; ok {
return 0
Expand All @@ -177,6 +175,8 @@ func (dict *ConcurrentDict) PutIfAbsentWithLock(key string, val interface{}) (re
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.Lock()
defer s.mutex.Unlock()

if _, ok := s.m[key]; ok {
return 0
Expand Down Expand Up @@ -227,8 +227,6 @@ func (dict *ConcurrentDict) Remove(key string) (val interface{}, result int) {
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.Lock()
defer s.mutex.Unlock()

if val, ok := s.m[key]; ok {
delete(s.m, key)
Expand All @@ -245,6 +243,8 @@ func (dict *ConcurrentDict) RemoveWithLock(key string) (val interface{}, result
hashCode := fnv32(key)
index := dict.spread(hashCode)
s := dict.getShard(index)
s.mutex.Lock()
defer s.mutex.Unlock()

if val, ok := s.m[key]; ok {
delete(s.m, key)
Expand Down

0 comments on commit 14440c0

Please sign in to comment.