uidriver/mobile: Prefer sync.Once to sync.Mutex

This commit is contained in:
Hajime Hoshi 2019-08-19 02:25:01 +09:00
parent d7aa24c295
commit 2c23860226

View File

@ -106,16 +106,13 @@ type UserInterface struct {
var ( var (
deviceScaleVal float64 deviceScaleVal float64
deviceScaleM sync.Mutex deviceScaleOnce sync.Once
) )
func getDeviceScale() float64 { func getDeviceScale() float64 {
deviceScaleM.Lock() deviceScaleOnce.Do(func() {
defer deviceScaleM.Unlock()
if deviceScaleVal == 0 {
deviceScaleVal = devicescale.GetAt(0, 0) deviceScaleVal = devicescale.GetAt(0, 0)
} })
return deviceScaleVal return deviceScaleVal
} }