Skip to content

Commit

Permalink
used defer to release the mutex
Browse files Browse the repository at this point in the history
Signed-off-by: Shriram Sharma <shriram_sharma@intuit.com>
  • Loading branch information
shriramsharma committed May 24, 2022
1 parent 2b742c2 commit 7be81eb
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions admiral/pkg/controller/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ func (s *SidecarEgressMap) Put(identity string, namespace string, fqdn string, c
}

func (s *SidecarEgressMap) Get(key string) map[string]SidecarEgress {
defer s.mutex.Unlock()
s.mutex.Lock()
val := s.cache[key]
s.mutex.Unlock()
return val
return s.cache[key]
}

func (s *SidecarEgressMap) Delete(key string) {
Expand All @@ -198,9 +197,9 @@ func (s *SidecarEgressMap) Map() map[string]map[string]SidecarEgress {

// Range is a thread safe iterator to iterate through the SidecarEgress map
func (s *SidecarEgressMap) Range(fn func(k string, v map[string]SidecarEgress)) {
defer s.mutex.Unlock()
s.mutex.Lock()
for k, v := range s.cache {
fn(k, v)
}
s.mutex.Unlock()
}

0 comments on commit 7be81eb

Please sign in to comment.