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 (
deviceScaleVal float64
deviceScaleM sync.Mutex
deviceScaleOnce sync.Once
)
func getDeviceScale() float64 {
deviceScaleM.Lock()
defer deviceScaleM.Unlock()
if deviceScaleVal == 0 {
deviceScaleOnce.Do(func() {
deviceScaleVal = devicescale.GetAt(0, 0)
}
})
return deviceScaleVal
}