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 ( import (
"errors" "errors"
"runtime"
"github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/internal/uidriver/mobile" "github.com/hajimehoshi/ebiten/internal/uidriver/mobile"
@ -30,9 +29,6 @@ var (
) )
func update() error { func update() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if chError == nil { if chError == nil {
return errors.New("mobile: chError must not be nil: Start is not called yet?") return errors.New("mobile: chError must not be nil: Start is not called yet?")
} }

View File

@ -21,6 +21,7 @@
package mobile package mobile
import ( import (
"runtime"
"sync" "sync"
"github.com/hajimehoshi/ebiten" "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. // Update returns error when 1) OpenGL error happens, or 2) f in Start returns error samely as ebiten.Run.
func Update() error { func Update() error {
// TODO: Is it safe to call Lock before locking the OS thread? runtime.LockOSThread()
defer runtime.UnlockOSThread()
mobileMutex.Lock() mobileMutex.Lock()
defer mobileMutex.Unlock() defer mobileMutex.Unlock()