From 826329f42605fa53b0cece44eae410076f74992f Mon Sep 17 00:00:00 2001 From: Peter Waller Date: Wed, 21 May 2014 07:54:07 +0100 Subject: [PATCH] Move mutex onto OutletFactory It's bad form for the mutex to live in the global namespace when it doesn't need to. --- outlet.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/outlet.go b/outlet.go index a98613a..df2ea45 100644 --- a/outlet.go +++ b/outlet.go @@ -13,6 +13,8 @@ import ( type OutletFactory struct { Outlets map[string]*Outlet Padding int + + sync.Mutex } type Outlet struct { @@ -22,8 +24,6 @@ type Outlet struct { Factory *OutletFactory } -var mx sync.Mutex - var colors = []ct.Color{ ct.Cyan, ct.Yellow, @@ -68,8 +68,8 @@ func (of *OutletFactory) ErrorOutput(str string) { // Write out a single coloured line func (of *OutletFactory) WriteLine(left, right string, leftC, rightC ct.Color, isError bool) { - mx.Lock() - defer mx.Unlock() + of.Lock() + defer of.Unlock() ct.ChangeColor(leftC, true, ct.None, false) formatter := fmt.Sprintf("%%-%ds | ", of.Padding)