Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver/glfw: Merge waitForStart and done channels #5327

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions internal/driver/glfw/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ var curWindow *window
var _ fyne.Driver = (*gLDriver)(nil)

type gLDriver struct {
windowLock sync.RWMutex
windows []fyne.Window
done chan struct{}
waitForStart chan struct{}
windowLock sync.RWMutex
windows []fyne.Window
waitForTransition chan struct{} // wait for transitioning first from starting and later on to quiting.

animation animation.Runner

Expand Down Expand Up @@ -99,7 +98,7 @@ func (d *gLDriver) Quit() {

// Only call close once to avoid panic.
if running.CompareAndSwap(true, false) {
close(d.done)
close(d.waitForTransition)
}
}

Expand Down Expand Up @@ -174,7 +173,6 @@ func NewGLDriver() *gLDriver {
repository.Register("file", intRepo.NewFileRepository())

return &gLDriver{
done: make(chan struct{}),
waitForStart: make(chan struct{}),
waitForTransition: make(chan struct{}),
}
}
4 changes: 0 additions & 4 deletions internal/driver/glfw/glfw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ func ensureCanvasSize(t *testing.T, w *window, size fyne.Size) {
}

func repaintWindow(w *window) {
// Wait for GLFW loop to be running.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this can be removed? I have a vague recollection this may have been an order-of-operations issue in the tests, so may not be disposable

// If we try to paint windows before the context is created, we will end up on the wrong thread.
<-w.driver.waitForStart

runOnMainWithContext(w, func() {
d.repaintWindow(w)
})
Expand Down
6 changes: 4 additions & 2 deletions internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func (d *gLDriver) runGL() {
if !running.CompareAndSwap(false, true) {
return // Run was called twice.
}
close(d.waitForStart) // Signal that execution can continue.

close(d.waitForTransition) // Signal that execution can continue.
d.waitForTransition = make(chan struct{}) // Prepare for transitioning into done.

d.initGLFW()
if d.trayStart != nil {
Expand All @@ -109,7 +111,7 @@ func (d *gLDriver) runGL() {
eventTick := time.NewTicker(time.Second / 60)
for {
select {
case <-d.done:
case <-d.waitForTransition:
eventTick.Stop()
d.Terminate()
l := fyne.CurrentApp().Lifecycle().(*app.Lifecycle)
Expand Down
2 changes: 0 additions & 2 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ func (w *window) doShow() {
return
}

<-w.driver.waitForStart

w.createLock.Do(w.create)
if w.view() == nil {
return
Expand Down
3 changes: 0 additions & 3 deletions internal/driver/glfw/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ func init() {
func TestMain(m *testing.M) {
d.initGLFW()
go func() {
// Wait for GLFW loop to be running.
// If we try to create windows before the context is created, this will fail with an exception.
<-d.waitForStart

initMainMenu()
os.Exit(m.Run())
Expand Down
Loading