From c2f3eee5af29a605833029854bd1756131a26815 Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Wed, 4 Nov 2020 09:51:20 +0100 Subject: [PATCH] Don't separately allocate sync.{Mutex,Once} if not necessary Separate allocation of synchronization devices suggests they're shared between objects, but they're not. --- internal/fs/fs_local_vss.go | 3 +-- internal/restic/progress.go | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/fs/fs_local_vss.go b/internal/fs/fs_local_vss.go index 60e134626..7deef8f05 100644 --- a/internal/fs/fs_local_vss.go +++ b/internal/fs/fs_local_vss.go @@ -21,7 +21,7 @@ type LocalVss struct { FS snapshots map[string]VssSnapshot failedSnapshots map[string]struct{} - mutex *sync.RWMutex + mutex sync.RWMutex msgError ErrorHandler msgMessage MessageHandler } @@ -36,7 +36,6 @@ func NewLocalVss(msgError ErrorHandler, msgMessage MessageHandler) *LocalVss { FS: Local{}, snapshots: make(map[string]VssSnapshot), failedSnapshots: make(map[string]struct{}), - mutex: &sync.RWMutex{}, msgError: msgError, msgMessage: msgMessage, } diff --git a/internal/restic/progress.go b/internal/restic/progress.go index 12d2b8710..cbbd6313d 100644 --- a/internal/restic/progress.go +++ b/internal/restic/progress.go @@ -40,7 +40,7 @@ type Progress struct { start time.Time c *time.Ticker cancel chan struct{} - o *sync.Once + once sync.Once d time.Duration lastUpdate time.Time @@ -79,7 +79,6 @@ func (p *Progress) Start() { return } - p.o = &sync.Once{} p.cancel = make(chan struct{}) p.running = true p.Reset() @@ -187,7 +186,7 @@ func (p *Progress) Done() { } p.running = false - p.o.Do(func() { + p.once.Do(func() { close(p.cancel) })