Skip to content

Commit cabe147

Browse files
committed
[bugfix] Protect against concurrent modifications
1 parent d16ecfe commit cabe147

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/visualization/receiver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (r *Receiver) Receive(multicastAddress string) {
4343
break
4444
} else {
4545
r.mutex.Lock()
46+
r.cleanupDetections()
4647
r.frames[frame.SenderId] = frame
4748
r.receivedTimes[frame.SenderId] = time.Now()
4849
r.mutex.Unlock()
@@ -90,16 +91,20 @@ func (r *Receiver) cleanupDetections() {
9091

9192
func (r *Receiver) GetLineSegments() map[string][]*LineSegment {
9293
lines := map[string][]*LineSegment{}
94+
r.mutex.Lock()
9395
for _, frame := range r.frames {
9496
lines[frame.SenderId] = frame.Lines
9597
}
98+
r.mutex.Unlock()
9699
return lines
97100
}
98101

99102
func (r *Receiver) GetCircles() map[string][]*Circle {
100103
lines := map[string][]*Circle{}
104+
r.mutex.Lock()
101105
for _, frame := range r.frames {
102106
lines[frame.SenderId] = frame.Circles
103107
}
108+
r.mutex.Unlock()
104109
return lines
105110
}

0 commit comments

Comments
 (0)