Fix data races

This commit is contained in:
Kevin Cotugno 2017-12-30 11:24:00 -08:00
parent a73e0f6a27
commit 1a58ef2acb

View File

@ -15,6 +15,8 @@ type ListWidget struct {
blockLock sync.Mutex blockLock sync.Mutex
block Block block Block
attributesLock sync.Mutex
attributes Attributes attributes Attributes
rightAlign bool rightAlign bool
@ -26,20 +28,32 @@ type ListWidget struct {
listBuf [][]Cell listBuf [][]Cell
} }
func (l ListWidget) Attributes() Attributes { func (l *ListWidget) Attributes() Attributes {
l.attributesLock.Lock()
defer l.attributesLock.Unlock()
return l.attributes return l.attributes
} }
func (l *ListWidget) SetAttributes(a Attributes) { func (l *ListWidget) SetAttributes(a Attributes) {
l.attributesLock.Lock()
l.attributes = a l.attributes = a
l.attributesLock.Unlock()
l.recalculateCells() 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() return l.block.Rect.Size()
} }
func (l *ListWidget) SetSize(p image.Point) { func (l *ListWidget) SetSize(p image.Point) {
l.blockLock.Lock()
defer l.blockLock.Unlock()
l.block.SetSize(p) l.block.SetSize(p)
} }