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 <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-09-04 09:57:00 +02:00
parent 1796f24a38
commit 9ffe43bc3a
5 changed files with 11 additions and 19 deletions
+2 -2
View File
@@ -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 //export Java_org_gioui_GioView_onFocusChange
func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) { func Java_org_gioui_GioView_onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
w := views[view] 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 //export Java_org_gioui_GioView_onWindowInsets
@@ -783,7 +783,7 @@ func (w *window) ReadClipboard() {
return return
} }
content := goString(env, C.jstring(c)) content := goString(env, C.jstring(c))
go w.callbacks.Event(clipboard.Event{Text: content}) w.callbacks.Event(clipboard.Event{Text: content})
}) })
} }
+1 -1
View File
@@ -256,7 +256,7 @@ func onTouch(last C.int, view, touchRef C.CFTypeRef, phase C.NSInteger, x, y C.C
func (w *window) ReadClipboard() { func (w *window) ReadClipboard() {
content := nsstringToString(C.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) { func (w *window) WriteClipboard(s string) {
+2 -8
View File
@@ -198,7 +198,7 @@ func (w *window) contextView() C.CFTypeRef {
func (w *window) ReadClipboard() { func (w *window) ReadClipboard() {
content := nsstringToString(C.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) { func (w *window) WriteClipboard(s string) {
@@ -283,13 +283,7 @@ func (w *window) runOnMain(f func()) {
} }
func (w *window) Close() { func (w *window) Close() {
// close immediately calls gio_onClose which sends events C.closeWindow(w.window)
// 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)
})
} }
func (w *window) setStage(stage system.Stage) { func (w *window) setStage(stage system.Stage) {
+1 -3
View File
@@ -511,9 +511,7 @@ func (w *window) readClipboard() error {
} }
defer windows.GlobalUnlock(mem) defer windows.GlobalUnlock(mem)
content := gowindows.UTF16PtrToString((*uint16)(unsafe.Pointer(ptr))) 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 return nil
} }
+5 -5
View File
@@ -261,7 +261,7 @@ func (w *Window) Invalidate() {
// Option applies the options to the window. // Option applies the options to the window.
func (w *Window) Option(opts ...Option) { func (w *Window) Option(opts ...Option) {
go w.driverDefer(func(d driver) { w.driverDefer(func(d driver) {
c := new(config) c := new(config)
for _, opt := range opts { for _, opt := range opts {
opt(c) opt(c)
@@ -274,21 +274,21 @@ func (w *Window) Option(opts ...Option) {
// of a clipboard.Event. Multiple reads may be coalesced // of a clipboard.Event. Multiple reads may be coalesced
// to a single event. // to a single event.
func (w *Window) ReadClipboard() { func (w *Window) ReadClipboard() {
go w.driverDefer(func(d driver) { w.driverDefer(func(d driver) {
d.ReadClipboard() d.ReadClipboard()
}) })
} }
// WriteClipboard writes a string to the clipboard. // WriteClipboard writes a string to the clipboard.
func (w *Window) WriteClipboard(s string) { func (w *Window) WriteClipboard(s string) {
go w.driverDefer(func(d driver) { w.driverDefer(func(d driver) {
d.WriteClipboard(s) d.WriteClipboard(s)
}) })
} }
// SetCursorName changes the current window cursor to name. // SetCursorName changes the current window cursor to name.
func (w *Window) SetCursorName(name pointer.CursorName) { func (w *Window) SetCursorName(name pointer.CursorName) {
go w.driverDefer(func(d driver) { w.driverDefer(func(d driver) {
d.SetCursor(name) d.SetCursor(name)
}) })
} }
@@ -299,7 +299,7 @@ func (w *Window) SetCursorName(name pointer.CursorName) {
// Currently, only macOS, Windows and X11 drivers implement this functionality, // Currently, only macOS, Windows and X11 drivers implement this functionality,
// all others are stubbed. // all others are stubbed.
func (w *Window) Close() { func (w *Window) Close() {
go w.driverDefer(func(d driver) { w.driverDefer(func(d driver) {
d.Close() d.Close()
}) })
} }