Skip to content

Commit

Permalink
Test non-main thread mac graph
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Apr 25, 2024
1 parent c1d3c7b commit 186a89d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/worker/caged/libretro/nanoarch/nanoarch.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func (n *Nanoarch) CoreLoad(meta Metadata) {
n.Video.gl.autoCtx = meta.AutoGlContext
n.Video.gl.enabled = meta.IsGlAllowed

thread.SwitchGraphics(n.Video.gl.enabled)

// hacks
Nan0.hackSkipHwContextDestroy = meta.HasHack("skip_hw_context_destroy")

Expand Down Expand Up @@ -934,6 +936,7 @@ func deinitVideo() {
Nan0.Video.gl.enabled = false
Nan0.Video.gl.autoCtx = false
Nan0.hackSkipHwContextDestroy = false
thread.SwitchGraphics(false)
}

type limit struct {
Expand Down
10 changes: 10 additions & 0 deletions pkg/worker/thread/mainthread_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type fun struct {
var dPool = sync.Pool{New: func() any { return make(chan struct{}) }}
var fq = make(chan fun, runtime.GOMAXPROCS(0))

var isGraphics = false

func init() {
runtime.LockOSThread()
}
Expand All @@ -38,8 +40,16 @@ func Run(run func()) {

// Call queues function f on the main thread and blocks until the function f finishes.
func Call(f func()) {
if !isGraphics {
return
}

done := dPool.Get().(chan struct{})
defer dPool.Put(done)
fq <- fun{fn: f, done: done}
<-done
}

func Switch(s bool) {
graphics = s

Check failure on line 54 in pkg/worker/thread/mainthread_darwin.go

View workflow job for this annotation

GitHub Actions / build (macos-12)

undefined: graphics
}
5 changes: 3 additions & 2 deletions pkg/worker/thread/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

package thread

func Wrap(f func()) { f() }
func Main(f func()) { f() }
func Wrap(f func()) { f() }
func Main(f func()) { f() }
func SwitchGraphics(s bool) {}
2 changes: 2 additions & 0 deletions pkg/worker/thread/thread_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ func Wrap(f func()) { Run(f) }

// Main calls a function on the main thread.
func Main(f func()) { Call(f) }

func SwitchGraphics(s bool) { Switch(s) }

0 comments on commit 186a89d

Please sign in to comment.