From fea802b39d20441ada04c3b18b0a42a08f459f4a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 11 Feb 2021 02:38:12 +0900 Subject: [PATCH] internal/uidriver: Replace mutex usages with atomic Updates #1073 --- internal/uidriver/glfw/ui.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index d0c013ed5..9118a48bb 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -24,6 +24,7 @@ import ( "os" "runtime" "sync" + "sync/atomic" "time" "github.com/hajimehoshi/ebiten/v2/internal/devicescale" @@ -43,7 +44,7 @@ type UserInterface struct { windowWidth int windowHeight int - running bool + running uint32 toChangeSize bool origPosX int origPosY int @@ -198,16 +199,15 @@ func getCachedMonitor(wx, wy int) *cachedMonitor { } func (u *UserInterface) isRunning() bool { - u.m.RLock() - v := u.running - u.m.RUnlock() - return v + return atomic.LoadUint32(&u.running) != 0 } func (u *UserInterface) setRunning(running bool) { - u.m.Lock() - u.running = running - u.m.Unlock() + if running { + atomic.StoreUint32(&u.running, 1) + } else { + atomic.StoreUint32(&u.running, 0) + } } func (u *UserInterface) getInitTitle() string {