From 2c23860226e5071619997f227123942a242616fa Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 19 Aug 2019 02:25:01 +0900 Subject: [PATCH] uidriver/mobile: Prefer sync.Once to sync.Mutex --- internal/uidriver/mobile/ui.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/uidriver/mobile/ui.go b/internal/uidriver/mobile/ui.go index a98f28f87..53abfb9bc 100644 --- a/internal/uidriver/mobile/ui.go +++ b/internal/uidriver/mobile/ui.go @@ -105,17 +105,14 @@ type UserInterface struct { } var ( - deviceScaleVal float64 - deviceScaleM sync.Mutex + deviceScaleVal float64 + deviceScaleOnce sync.Once ) func getDeviceScale() float64 { - deviceScaleM.Lock() - defer deviceScaleM.Unlock() - - if deviceScaleVal == 0 { + deviceScaleOnce.Do(func() { deviceScaleVal = devicescale.GetAt(0, 0) - } + }) return deviceScaleVal }