mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +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()
|
||||
}
|
||||
scale = impl()
|
||||
return scale
|
||||
s = scale
|
||||
m.Unlock()
|
||||
return s
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user