mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-10 22:42:00 +02:00
reduce chance of deadlock by using a RW mutex on the context stack
This commit is contained in:
@@ -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
|
// 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.
|
// then when it's accessed it will have weight 2, not 1.
|
||||||
func (gui *Gui) getDefaultStashWindowBox() *boxlayout.Box {
|
func (gui *Gui) getDefaultStashWindowBox() *boxlayout.Box {
|
||||||
gui.State.ContextManager.Lock()
|
gui.State.ContextManager.RLock()
|
||||||
defer gui.State.ContextManager.Unlock()
|
defer gui.State.ContextManager.RUnlock()
|
||||||
|
|
||||||
box := &boxlayout.Box{Window: "stash"}
|
box := &boxlayout.Box{Window: "stash"}
|
||||||
stashWindowAccessed := false
|
stashWindowAccessed := false
|
||||||
@@ -281,8 +281,8 @@ func (gui *Gui) sidePanelChildren(width int, height int) []*boxlayout.Box {
|
|||||||
|
|
||||||
func (gui *Gui) currentSideWindowName() string {
|
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
|
// there is always one and only one cyclable context in the context stack. We'll look from top to bottom
|
||||||
gui.State.ContextManager.Lock()
|
gui.State.ContextManager.RLock()
|
||||||
defer gui.State.ContextManager.Unlock()
|
defer gui.State.ContextManager.RUnlock()
|
||||||
|
|
||||||
for idx := range gui.State.ContextManager.ContextStack {
|
for idx := range gui.State.ContextManager.ContextStack {
|
||||||
reversedIdx := len(gui.State.ContextManager.ContextStack) - 1 - idx
|
reversedIdx := len(gui.State.ContextManager.ContextStack) - 1 - idx
|
||||||
|
@@ -356,8 +356,8 @@ func (tree ContextTree) initialViewTabContextMap() map[string][]tabContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) currentContextKeyIgnoringPopups() ContextKey {
|
func (gui *Gui) currentContextKeyIgnoringPopups() ContextKey {
|
||||||
gui.State.ContextManager.Lock()
|
gui.State.ContextManager.RLock()
|
||||||
defer gui.State.ContextManager.Unlock()
|
defer gui.State.ContextManager.RUnlock()
|
||||||
|
|
||||||
stack := gui.State.ContextManager.ContextStack
|
stack := gui.State.ContextManager.ContextStack
|
||||||
|
|
||||||
@@ -577,8 +577,8 @@ func (gui *Gui) activateContext(c Context) error {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
func (gui *Gui) currentContext() Context {
|
func (gui *Gui) currentContext() Context {
|
||||||
gui.State.ContextManager.Lock()
|
gui.State.ContextManager.RLock()
|
||||||
defer gui.State.ContextManager.Unlock()
|
defer gui.State.ContextManager.RUnlock()
|
||||||
|
|
||||||
if len(gui.State.ContextManager.ContextStack) == 0 {
|
if len(gui.State.ContextManager.ContextStack) == 0 {
|
||||||
return gui.defaultSideContext()
|
return gui.defaultSideContext()
|
||||||
@@ -599,8 +599,8 @@ func (gui *Gui) currentSideListContext() *ListContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) currentSideContext() Context {
|
func (gui *Gui) currentSideContext() Context {
|
||||||
gui.State.ContextManager.Lock()
|
gui.State.ContextManager.RLock()
|
||||||
defer gui.State.ContextManager.Unlock()
|
defer gui.State.ContextManager.RUnlock()
|
||||||
|
|
||||||
stack := gui.State.ContextManager.ContextStack
|
stack := gui.State.ContextManager.ContextStack
|
||||||
|
|
||||||
|
@@ -51,13 +51,13 @@ var OverlappingEdges = false
|
|||||||
|
|
||||||
type ContextManager struct {
|
type ContextManager struct {
|
||||||
ContextStack []Context
|
ContextStack []Context
|
||||||
sync.Mutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContextManager(initialContext Context) ContextManager {
|
func NewContextManager(initialContext Context) ContextManager {
|
||||||
return ContextManager{
|
return ContextManager{
|
||||||
ContextStack: []Context{initialContext},
|
ContextStack: []Context{initialContext},
|
||||||
Mutex: sync.Mutex{},
|
RWMutex: sync.RWMutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user