Skip to content

Commit

Permalink
Use standard lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Teoh committed Dec 16, 2024
1 parent 0d0f64b commit c81ee05
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
type SizeLimitedMap struct {
ids map[string][]string
size int
mu sync.RWMutex
mu sync.Mutex
}

func newSizeLimitedMap(size int) *SizeLimitedMap {
Expand Down Expand Up @@ -35,8 +35,8 @@ func (sizeLimitedMap *SizeLimitedMap) add(key string, element string) {
}

func (sizeLimitedMap *SizeLimitedMap) contains(key string, element string) bool {
sizeLimitedMap.mu.RLock()
defer sizeLimitedMap.mu.RUnlock()
sizeLimitedMap.mu.Lock()
defer sizeLimitedMap.mu.Unlock()

if val, ok := sizeLimitedMap.ids[key]; ok {
for _, v := range val {
Expand All @@ -50,8 +50,8 @@ func (sizeLimitedMap *SizeLimitedMap) contains(key string, element string) bool
}

func (sizeLimitedMap *SizeLimitedMap) count() int {
sizeLimitedMap.mu.RLock()
defer sizeLimitedMap.mu.RUnlock()
sizeLimitedMap.mu.Lock()
defer sizeLimitedMap.mu.Unlock()

return len(sizeLimitedMap.ids)
}

0 comments on commit c81ee05

Please sign in to comment.