devicescale: Make DeviceScale concurrent-safe

This commit is contained in:
Hajime Hoshi 2018-01-03 16:50:54 +09:00
parent d398cb14c2
commit 5a17497723

View File

@ -14,12 +14,22 @@
package devicescale package devicescale
var scale = 0.0 import (
"sync"
)
var (
scale = 0.0
m sync.Mutex
)
func DeviceScale() float64 { func DeviceScale() float64 {
if scale != 0.0 { s := 0.0
return scale m.Lock()
if scale == 0.0 {
scale = impl()
} }
scale = impl() s = scale
return scale m.Unlock()
return s
} }