Skip to content

Commit

Permalink
Use defers for locks
Browse files Browse the repository at this point in the history
  • Loading branch information
mellowdrifter committed Oct 30, 2021
1 parent 644fb87 commit 3726782
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,14 @@ func (s *Server) setSerial(serial uint32) {
// be called before the VRPs data is added.
func (s *Server) SetSerial(serial uint32) {
s.vrplock.RLock()
defer s.vrplock.RUnlock()
//s.vrpListSerial = make([]uint32, 0)
s.setSerial(serial)
s.vrplock.RUnlock()
}

func (s *Server) AddVRPs(vrps []VRP) {
s.vrplock.RLock()
defer s.vrplock.RUnlock()

vrpCurrent := s.vrpCurrent

Expand All @@ -356,7 +357,6 @@ func (s *Server) AddVRPs(vrps []VRP) {
s.log.Debugf("Computed diff: added (%d), removed (%d), unchanged (%d)", len(added), len(removed), len(unchanged))
}
curDiff := append(added, removed...)
s.vrplock.RUnlock()

s.AddVRPsDiff(curDiff)
}
Expand All @@ -383,6 +383,7 @@ func (s *Server) AddVRPsDiff(diff []VRP) {
s.vrplock.RUnlock()

s.vrplock.Lock()
defer s.vrplock.Unlock()
newserial := s.generateSerial()
removed := s.addSerial(newserial)

Expand All @@ -407,7 +408,6 @@ func (s *Server) AddVRPsDiff(diff []VRP) {
s.vrpListDiff = nextDiff
s.vrpCurrent = newVrpCurrent
s.setSerial(newserial)
s.vrplock.Unlock()
}

func (s *Server) SetBaseVersion(version uint8) {
Expand Down Expand Up @@ -956,7 +956,6 @@ func (c *Client) Disconnect() {
select {
case c.quit <- true:
default:

}

c.tcpconn.Close()
Expand Down

0 comments on commit 3726782

Please sign in to comment.