mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
devicescale: Make DeviceScale concurrent-safe
This commit is contained in:
parent
d398cb14c2
commit
5a17497723
@ -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()
|
||||
return scale
|
||||
}
|
||||
s = scale
|
||||
m.Unlock()
|
||||
return s
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user