Deadlock fix: no channel sends during frame rendering while mutex is locked.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package editor
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"pad/internal/browser"
|
||||
@@ -81,8 +82,8 @@ func NewLogic() *Logic {
|
||||
configChan: make(chan ConfigUpdate),
|
||||
frameChan: make(chan []ui.Element),
|
||||
inputChan: make(chan []ui.InputEvent),
|
||||
lastLineYChan: make(chan int),
|
||||
resultChan: make(chan ResultEvent),
|
||||
lastLineYChan: make(chan int),
|
||||
resultChan: make(chan ResultEvent),
|
||||
searchQueryChan: make(chan string),
|
||||
openFileChan: make(chan string), // Initialized
|
||||
workerPool: wp,
|
||||
@@ -136,6 +137,7 @@ func (l *Logic) Scale() float32 {
|
||||
// Run runs the logic goroutine loop.
|
||||
func (l *Logic) Run() {
|
||||
// Dispatch initial directory index build on startup
|
||||
log.Printf("Logic: Dispatching BuildIndexTask")
|
||||
l.workerPool.Dispatch(pool.NewBuildIndexTask(l.state.Browser.CurrentPath, l.mockFS))
|
||||
|
||||
for {
|
||||
@@ -143,6 +145,7 @@ func (l *Logic) Run() {
|
||||
case <-l.done:
|
||||
return
|
||||
case update := <-l.configChan:
|
||||
log.Printf("Logic: ConfigEvent")
|
||||
update.apply(l.state)
|
||||
l.frameChan <- l.state.layout(l.browserManager)
|
||||
case y := <-l.lastLineYChan:
|
||||
@@ -151,11 +154,13 @@ func (l *Logic) Run() {
|
||||
l.frameChan <- l.state.layout(l.browserManager)
|
||||
}
|
||||
case events := <-l.inputChan:
|
||||
log.Printf("Logic: InputEvents")
|
||||
for _, evt := range events {
|
||||
evt.Handler(evt.Data)
|
||||
}
|
||||
l.frameChan <- l.state.layout(l.browserManager)
|
||||
case query := <-l.searchQueryChan:
|
||||
log.Printf("Logic: SearchQuery")
|
||||
if query != l.state.Browser.Query {
|
||||
l.state.Browser.Query = query
|
||||
if l.state.page == BrowserPage {
|
||||
@@ -164,9 +169,11 @@ func (l *Logic) Run() {
|
||||
}
|
||||
l.frameChan <- l.state.layout(l.browserManager)
|
||||
case path := <-l.openFileChan:
|
||||
log.Printf("Logic: OpenFileChan %s", path)
|
||||
// Dispatch ReadFileTask to worker pool
|
||||
l.workerPool.Dispatch(pool.NewReadFileTask(path, l.mockFS))
|
||||
case res := <-l.workerPool.ResultChan():
|
||||
log.Printf("Logic: WorkerResult %s", res.TaskType)
|
||||
l.handleWorkerResult(res)
|
||||
case <-l.resultChan:
|
||||
l.frameChan <- l.state.layout(l.browserManager)
|
||||
@@ -179,6 +186,7 @@ func (l *Logic) handleWorkerResult(res pool.Result) {
|
||||
if res.IsBrowserResult() {
|
||||
l.browserManager.HandleResult(res)
|
||||
} else if res.TaskType == pool.TypeReadFile {
|
||||
log.Printf("Logic: TypeReadFile result success=%v", res.Success)
|
||||
if res.Success {
|
||||
if content, ok := res.Data.([]byte); ok {
|
||||
l.state.ActiveFileContent = string(content)
|
||||
|
||||
Reference in New Issue
Block a user