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:
Hajime Hoshi 2019-06-08 02:00:40 +09:00
parent fa377ce9d1
commit 42cf9d1750
2 changed files with 4 additions and 5 deletions

View File

@ -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?")
}

View File

@ -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()