From b198a4dfec53a15eac5cdca9fe9d91c145a0119c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 11 Aug 2014 14:16:23 -0400 Subject: [PATCH] Settled race condition TODOs across all platforms... as an unfortunate case :( --- redo/table_darwin.go | 14 +++++++++----- redo/table_unix.go | 18 +++++++++++------- redo/table_windows.go | 14 +++++++++----- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/redo/table_darwin.go b/redo/table_darwin.go index c80dbdc..95344c1 100644 --- a/redo/table_darwin.go +++ b/redo/table_darwin.go @@ -36,11 +36,15 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table { func (t *table) Unlock() { t.unlock() - // TODO RACE CONDITION HERE - // not sure about this one... - t.RLock() - defer t.RUnlock() - C.tableUpdate(t._id) + // there's a possibility that user actions can happen at this point, before the view is updated + // alas, this is something we have to deal with, because Unlock() can be called from any thread + go func() { + Do(func() { + t.RLock() + defer t.RUnlock() + C.tableUpdate(t._id) + }) + }() } //export goTableDataSource_getValue diff --git a/redo/table_unix.go b/redo/table_unix.go index 611beae..d618663 100644 --- a/redo/table_unix.go +++ b/redo/table_unix.go @@ -58,13 +58,17 @@ func (t *table) Lock() { func (t *table) Unlock() { t.unlock() - // TODO RACE CONDITION HERE - // not sure about this one... - t.RLock() - defer t.RUnlock() - d := reflect.Indirect(reflect.ValueOf(t.data)) - new := C.gint(d.Len()) - C.tableUpdate(t.model, t.old, new) + // there's a possibility that user actions can happen at this point, before the view is updated + // alas, this is something we have to deal with, because Unlock() can be called from any thread + go func() { + Do(func() { + t.RLock() + defer t.RUnlock() + d := reflect.Indirect(reflect.ValueOf(t.data)) + new := C.gint(d.Len()) + C.tableUpdate(t.model, t.old, new) + }) + }() } //export goTableModel_get_n_columns diff --git a/redo/table_windows.go b/redo/table_windows.go index 576ae4a..be9427e 100644 --- a/redo/table_windows.go +++ b/redo/table_windows.go @@ -38,11 +38,15 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table { func (t *table) Unlock() { t.unlock() - // TODO RACE CONDITION HERE - // I think there's a way to set the item count without causing a refetch of data that works around this... - t.RLock() - defer t.RUnlock() - C.tableUpdate(t._hwnd, C.int(reflect.Indirect(reflect.ValueOf(t.data)).Len())) + // there's a possibility that user actions can happen at this point, before the view is updated + // alas, this is something we have to deal with, because Unlock() can be called from any thread + go func() { + Do(func() { + t.RLock() + defer t.RUnlock() + C.tableUpdate(t._hwnd, C.int(reflect.Indirect(reflect.ValueOf(t.data)).Len())) + }) + }() } //export tableGetCellText