mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
mobile: Lock the OS thread before using mutex
As switching the OS thread by mutex could theoretically happen (I think this is almost 0% in Ebiten's case), locking the OS thread should happen before the mutex.
This commit is contained in:
parent
fa377ce9d1
commit
42cf9d1750
@ -18,7 +18,6 @@ package mobile
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/uidriver/mobile"
|
||||
@ -30,9 +29,6 @@ var (
|
||||
)
|
||||
|
||||
func update() error {
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
if chError == nil {
|
||||
return errors.New("mobile: chError must not be nil: Start is not called yet?")
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
@ -63,7 +64,9 @@ func Start(f func(*ebiten.Image) error, width, height int, scale float64, title
|
||||
//
|
||||
// Update returns error when 1) OpenGL error happens, or 2) f in Start returns error samely as ebiten.Run.
|
||||
func Update() error {
|
||||
// TODO: Is it safe to call Lock before locking the OS thread?
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
mobileMutex.Lock()
|
||||
defer mobileMutex.Unlock()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user