diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-03 12:40:41 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-03 12:54:14 +1000 |
commit | 5d982e1d70aa9a07645a5665130f2e499b7b56c8 (patch) | |
tree | 75978118d1a4cdb8689a241aba5b268eb93501b9 /pkg | |
parent | 4d734d594a3adb225fd592e6649c3e32b292a88d (diff) |
Add mutex to filtered list to avoid concurrency issues
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/context/filtered_list.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pkg/gui/context/filtered_list.go b/pkg/gui/context/filtered_list.go index ce2e12590..298d3d615 100644 --- a/pkg/gui/context/filtered_list.go +++ b/pkg/gui/context/filtered_list.go @@ -2,6 +2,7 @@ package context import ( "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/sasha-s/go-deadlock" ) type FilteredList[T any] struct { @@ -10,12 +11,15 @@ type FilteredList[T any] struct { getList func() []T getFilterFields func(T) []string filter string + + mutex *deadlock.Mutex } func NewFilteredList[T any](getList func() []T, getFilterFields func(T) []string) *FilteredList[T] { return &FilteredList[T]{ getList: getList, getFilterFields: getFilterFields, + mutex: &deadlock.Mutex{}, } } @@ -50,6 +54,9 @@ func (self *FilteredList[T]) UnfilteredLen() int { } func (self *FilteredList[T]) applyFilter() { + self.mutex.Lock() + defer self.mutex.Unlock() + if self.filter == "" { self.filteredIndices = nil } else { @@ -70,6 +77,9 @@ func (self *FilteredList[T]) match(haystack string, needle string) bool { } func (self *FilteredList[T]) UnfilteredIndex(index int) int { + self.mutex.Lock() + defer self.mutex.Unlock() + if self.filteredIndices == nil { return index } @@ -79,6 +89,5 @@ func (self *FilteredList[T]) UnfilteredIndex(index int) int { return -1 } - // TODO: mutex return self.filteredIndices[index] } |