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
var scale = 0.0
import (
"sync"
)
var (
scale = 0.0
m sync.Mutex
)
func DeviceScale() float64 {
if scale != 0.0 {
return scale
s := 0.0
m.Lock()
if scale == 0.0 {
scale = impl()
}
scale = impl()
return scale
s = scale
m.Unlock()
return s
}