From aad69a1653bce57073b30027c9e1e64323df51c7 Mon Sep 17 00:00:00 2001 From: Nicolai Ommer Date: Wed, 24 Apr 2019 20:09:57 +0200 Subject: [PATCH] [bugfix] Synchronize access to state between publish and write --- internal/app/controller/controller.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/app/controller/controller.go b/internal/app/controller/controller.go index 61b0a223..bee70776 100644 --- a/internal/app/controller/controller.go +++ b/internal/app/controller/controller.go @@ -28,6 +28,7 @@ type GameController struct { outstandingTeamChoice *TeamChoice ConnectionMutex sync.Mutex PublishMutex sync.Mutex + StateMutex sync.Mutex VisionReceiver *vision.Receiver } @@ -118,12 +119,16 @@ func (c *GameController) setupTimeProvider() { func (c *GameController) updateLoop() { for { time.Sleep(time.Millisecond * 10) + c.StateMutex.Lock() c.update() + c.StateMutex.Unlock() } } // updateCi updates the current time to the given time and returns the updated referee message func (c *GameController) updateCi(t time.Time) *refproto.Referee { + c.StateMutex.Lock() + defer c.StateMutex.Unlock() c.Engine.TimeProvider = func() time.Time { return t } c.update() c.Publisher.Publish(c.Engine.State) @@ -178,13 +183,16 @@ func (c *GameController) updateOnlineStates() { func (c *GameController) publishToNetwork() { for { time.Sleep(25 * time.Millisecond) + c.StateMutex.Lock() c.Publisher.Publish(c.Engine.State) + c.StateMutex.Unlock() } } // OnNewEvent processes the given event func (c *GameController) OnNewEvent(event Event) { - + c.StateMutex.Lock() + defer c.StateMutex.Unlock() if event.GameEvent != nil && !c.Engine.disabledGameEvent(event.GameEvent.Type) && c.askForTeamDecisionIfRequired(event) { return }