From 5ee5d42511836d581b649d57251de996d7dba17a Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 9 Jun 2025 16:21:10 +0200 Subject: [PATCH] Instantiate Mutexes's fields by value Instead, pass the entire Mutexes struct by pointer to controllers. This is better because Mutexes now has a zero value and doesn't need to be initialized. --- pkg/gui/gui.go | 11 ----------- pkg/gui/gui_common.go | 4 ++-- pkg/gui/types/common.go | 22 ++++++++++------------ 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 49643791e..c38685d3a 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -681,17 +681,6 @@ func NewGui( // real value after loading the user config: ShowExtrasWindow: true, - Mutexes: types.Mutexes{ - RefreshingFilesMutex: &deadlock.Mutex{}, - RefreshingBranchesMutex: &deadlock.Mutex{}, - RefreshingStatusMutex: &deadlock.Mutex{}, - LocalCommitsMutex: &deadlock.Mutex{}, - SubCommitsMutex: &deadlock.Mutex{}, - AuthorsMutex: &deadlock.Mutex{}, - SubprocessMutex: &deadlock.Mutex{}, - PopupMutex: &deadlock.Mutex{}, - PtyMutex: &deadlock.Mutex{}, - }, InitialDir: initialDir, afterLayoutFuncs: make(chan func() error, 1000), diff --git a/pkg/gui/gui_common.go b/pkg/gui/gui_common.go index 41b409544..4a40c4f8b 100644 --- a/pkg/gui/gui_common.go +++ b/pkg/gui/gui_common.go @@ -100,8 +100,8 @@ func (self *guiCommon) Model() *types.Model { return self.gui.State.Model } -func (self *guiCommon) Mutexes() types.Mutexes { - return self.gui.Mutexes +func (self *guiCommon) Mutexes() *types.Mutexes { + return &self.gui.Mutexes } func (self *guiCommon) GocuiGui() *gocui.Gui { diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index 2ca016825..47d51bb6b 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -94,7 +94,7 @@ type IGuiCommon interface { Modes() *Modes - Mutexes() Mutexes + Mutexes() *Mutexes State() IStateAccessor @@ -313,18 +313,16 @@ type Model struct { HashPool *utils.StringPool } -// if you add a new mutex here be sure to instantiate it. We're using pointers to -// mutexes so that we can pass the mutexes to controllers. type Mutexes struct { - RefreshingFilesMutex *deadlock.Mutex - RefreshingBranchesMutex *deadlock.Mutex - RefreshingStatusMutex *deadlock.Mutex - LocalCommitsMutex *deadlock.Mutex - SubCommitsMutex *deadlock.Mutex - AuthorsMutex *deadlock.Mutex - SubprocessMutex *deadlock.Mutex - PopupMutex *deadlock.Mutex - PtyMutex *deadlock.Mutex + RefreshingFilesMutex deadlock.Mutex + RefreshingBranchesMutex deadlock.Mutex + RefreshingStatusMutex deadlock.Mutex + LocalCommitsMutex deadlock.Mutex + SubCommitsMutex deadlock.Mutex + AuthorsMutex deadlock.Mutex + SubprocessMutex deadlock.Mutex + PopupMutex deadlock.Mutex + PtyMutex deadlock.Mutex } // A long-running operation associated with an item. For example, we'll show