From 9ffe43bc3a5c24250a6299bb57942aaa7e1161c2 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 4 Sep 2021 09:57:00 +0200 Subject: [PATCH] app: delete workarounds for driver callback deadlocks Driver methods are invoked during event processing, but some of them may generate events that would in turn deadlock because event processing is not re-entrant. However, a previous change moved all such calls outside event processing and so chained events can no longer deadlock. This change deletes the workarounds. Signed-off-by: Elias Naur --- app/os_android.go | 4 ++-- app/os_ios.go | 2 +- app/os_macos.go | 10 ++-------- app/os_windows.go | 4 +--- app/window.go | 10 +++++----- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/os_android.go b/app/os_android.go index 3063abaa..932c09c5 100644 --- a/app/os_android.go +++ b/app/os_android.go @@ -427,7 +427,7 @@ func Java_org_gioui_GioView_onBack(env *C.JNIEnv, class C.jclass, view C.jlong) //export Java_org_gioui_GioView_onFocusChange func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) { w := views[view] - go w.callbacks.Event(key.FocusEvent{Focus: focus == C.JNI_TRUE}) + w.callbacks.Event(key.FocusEvent{Focus: focus == C.JNI_TRUE}) } //export Java_org_gioui_GioView_onWindowInsets @@ -783,7 +783,7 @@ func (w *window) ReadClipboard() { return } content := goString(env, C.jstring(c)) - go w.callbacks.Event(clipboard.Event{Text: content}) + w.callbacks.Event(clipboard.Event{Text: content}) }) } diff --git a/app/os_ios.go b/app/os_ios.go index 7d34b904..a6a2bb3e 100644 --- a/app/os_ios.go +++ b/app/os_ios.go @@ -256,7 +256,7 @@ func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.C func (w *window) ReadClipboard() { content := nsstringToString(C.readClipboard()) - go w.w.Event(clipboard.Event{Text: content}) + w.w.Event(clipboard.Event{Text: content}) } func (w *window) WriteClipboard(s string) { diff --git a/app/os_macos.go b/app/os_macos.go index d74bbd6f..b9e4893e 100644 --- a/app/os_macos.go +++ b/app/os_macos.go @@ -198,7 +198,7 @@ func (w *window) contextView() C.CFTypeRef { func (w *window) ReadClipboard() { content := nsstringToString(C.readClipboard()) - go w.w.Event(clipboard.Event{Text: content}) + w.w.Event(clipboard.Event{Text: content}) } func (w *window) WriteClipboard(s string) { @@ -283,13 +283,7 @@ func (w *window) runOnMain(f func()) { } func (w *window) Close() { - // close immediately calls gio_onClose which sends events - // causing a deadlock because Close is called during an event. - // Break the deadlock by deferring the close, making Close more - // akin to a message like the other platforms. - go w.runOnMain(func() { - C.closeWindow(w.window) - }) + C.closeWindow(w.window) } func (w *window) setStage(stage system.Stage) { diff --git a/app/os_windows.go b/app/os_windows.go index 1bdacb76..46b1acb0 100644 --- a/app/os_windows.go +++ b/app/os_windows.go @@ -511,9 +511,7 @@ func (w *window) readClipboard() error { } defer windows.GlobalUnlock(mem) content := gowindows.UTF16PtrToString((*uint16)(unsafe.Pointer(ptr))) - go func() { - w.w.Event(clipboard.Event{Text: content}) - }() + w.w.Event(clipboard.Event{Text: content}) return nil } diff --git a/app/window.go b/app/window.go index f0cf100b..c7f7797a 100644 --- a/app/window.go +++ b/app/window.go @@ -261,7 +261,7 @@ func (w *Window) Invalidate() { // Option applies the options to the window. func (w *Window) Option(opts ...Option) { - go w.driverDefer(func(d driver) { + w.driverDefer(func(d driver) { c := new(config) for _, opt := range opts { opt(c) @@ -274,21 +274,21 @@ func (w *Window) Option(opts ...Option) { // of a clipboard.Event. Multiple reads may be coalesced // to a single event. func (w *Window) ReadClipboard() { - go w.driverDefer(func(d driver) { + w.driverDefer(func(d driver) { d.ReadClipboard() }) } // WriteClipboard writes a string to the clipboard. func (w *Window) WriteClipboard(s string) { - go w.driverDefer(func(d driver) { + w.driverDefer(func(d driver) { d.WriteClipboard(s) }) } // SetCursorName changes the current window cursor to name. func (w *Window) SetCursorName(name pointer.CursorName) { - go w.driverDefer(func(d driver) { + w.driverDefer(func(d driver) { d.SetCursor(name) }) } @@ -299,7 +299,7 @@ func (w *Window) SetCursorName(name pointer.CursorName) { // Currently, only macOS, Windows and X11 drivers implement this functionality, // all others are stubbed. func (w *Window) Close() { - go w.driverDefer(func(d driver) { + w.driverDefer(func(d driver) { d.Close() }) }