internal/uidriver: Replace mutex usages with atomic

Updates #1073
This commit is contained in:
Hajime Hoshi 2021-02-11 02:38:12 +09:00
parent ba674a686c
commit fea802b39d

View File

@ -24,6 +24,7 @@ import (
"os" "os"
"runtime" "runtime"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/hajimehoshi/ebiten/v2/internal/devicescale" "github.com/hajimehoshi/ebiten/v2/internal/devicescale"
@ -43,7 +44,7 @@ type UserInterface struct {
windowWidth int windowWidth int
windowHeight int windowHeight int
running bool running uint32
toChangeSize bool toChangeSize bool
origPosX int origPosX int
origPosY int origPosY int
@ -198,16 +199,15 @@ func getCachedMonitor(wx, wy int) *cachedMonitor {
} }
func (u *UserInterface) isRunning() bool { func (u *UserInterface) isRunning() bool {
u.m.RLock() return atomic.LoadUint32(&u.running) != 0
v := u.running
u.m.RUnlock()
return v
} }
func (u *UserInterface) setRunning(running bool) { func (u *UserInterface) setRunning(running bool) {
u.m.Lock() if running {
u.running = running atomic.StoreUint32(&u.running, 1)
u.m.Unlock() } else {
atomic.StoreUint32(&u.running, 0)
}
} }
func (u *UserInterface) getInitTitle() string { func (u *UserInterface) getInitTitle() string {