summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-06 16:01:07 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-04-06 19:34:32 +1000
commit8c93289a728991c51e787bcf7dc72813ce0e1a0e (patch)
tree637cea41eb0cc6dc34330cacfbbaae2f8ea3f7c0 /pkg
parentb1df0fafa216bb2784bedb82bdbeace9df931a02 (diff)
reduce chance of deadlock by using a RW mutex on the context stack
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/arrangement.go8
-rw-r--r--pkg/gui/context.go12
-rw-r--r--pkg/gui/gui.go4
3 files changed, 12 insertions, 12 deletions
diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go
index 422941243..125e089d2 100644
--- a/pkg/gui/arrangement.go
+++ b/pkg/gui/arrangement.go
@@ -181,8 +181,8 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map
// the default behaviour when accordian mode is NOT in effect. If it is in effect
// then when it's accessed it will have weight 2, not 1.
func (gui *Gui) getDefaultStashWindowBox() *boxlayout.Box {
- gui.State.ContextManager.Lock()
- defer gui.State.ContextManager.Unlock()
+ gui.State.ContextManager.RLock()
+ defer gui.State.ContextManager.RUnlock()
box := &boxlayout.Box{Window: "stash"}
stashWindowAccessed := false
@@ -281,8 +281,8 @@ func (gui *Gui) sidePanelChildren(width int, height int) []*boxlayout.Box {
func (gui *Gui) currentSideWindowName() string {
// there is always one and only one cyclable context in the context stack. We'll look from top to bottom
- gui.State.ContextManager.Lock()
- defer gui.State.ContextManager.Unlock()
+ gui.State.ContextManager.RLock()
+ defer gui.State.ContextManager.RUnlock()
for idx := range gui.State.ContextManager.ContextStack {
reversedIdx := len(gui.State.ContextManager.ContextStack) - 1 - idx
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index 736f773b7..ec3656720 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -356,8 +356,8 @@ func (tree ContextTree) initialViewTabContextMap() map[string][]tabContext {
}
func (gui *Gui) currentContextKeyIgnoringPopups() ContextKey {
- gui.State.ContextManager.Lock()
- defer gui.State.ContextManager.Unlock()
+ gui.State.ContextManager.RLock()
+ defer gui.State.ContextManager.RUnlock()
stack := gui.State.ContextManager.ContextStack
@@ -577,8 +577,8 @@ func (gui *Gui) activateContext(c Context) error {
// }
func (gui *Gui) currentContext() Context {
- gui.State.ContextManager.Lock()
- defer gui.State.ContextManager.Unlock()
+ gui.State.ContextManager.RLock()
+ defer gui.State.ContextManager.RUnlock()
if len(gui.State.ContextManager.ContextStack) == 0 {
return gui.defaultSideContext()
@@ -599,8 +599,8 @@ func (gui *Gui) currentSideListContext() *ListContext {
}
func (gui *Gui) currentSideContext() Context {
- gui.State.ContextManager.Lock()
- defer gui.State.ContextManager.Unlock()
+ gui.State.ContextManager.RLock()
+ defer gui.State.ContextManager.RUnlock()
stack := gui.State.ContextManager.ContextStack
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 780e9531a..3da085f2f 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -51,13 +51,13 @@ var OverlappingEdges = false
type ContextManager struct {
ContextStack []Context
- sync.Mutex
+ sync.RWMutex
}
func NewContextManager(initialContext Context) ContextManager {
return ContextManager{
ContextStack: []Context{initialContext},
- Mutex: sync.Mutex{},
+ RWMutex: sync.RWMutex{},
}
}