From 1a58ef2acbb6d9617b00e486fee0bc38415cb579 Mon Sep 17 00:00:00 2001 From: Kevin Cotugno Date: Sat, 30 Dec 2017 11:24:00 -0800 Subject: [PATCH] Fix data races --- exhibit/list_widget.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/exhibit/list_widget.go b/exhibit/list_widget.go index ecb7798..90d7dad 100644 --- a/exhibit/list_widget.go +++ b/exhibit/list_widget.go @@ -15,7 +15,9 @@ type ListWidget struct { blockLock sync.Mutex block Block - attributes Attributes + + attributesLock sync.Mutex + attributes Attributes rightAlign bool border bool @@ -26,20 +28,32 @@ type ListWidget struct { listBuf [][]Cell } -func (l ListWidget) Attributes() Attributes { +func (l *ListWidget) Attributes() Attributes { + l.attributesLock.Lock() + defer l.attributesLock.Unlock() + return l.attributes } func (l *ListWidget) SetAttributes(a Attributes) { + l.attributesLock.Lock() l.attributes = a + l.attributesLock.Unlock() + l.recalculateCells() } -func (l ListWidget) Size() image.Point { +func (l *ListWidget) Size() image.Point { + l.blockLock.Lock() + defer l.blockLock.Unlock() + return l.block.Rect.Size() } func (l *ListWidget) SetSize(p image.Point) { + l.blockLock.Lock() + defer l.blockLock.Unlock() + l.block.SetSize(p) }