summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2021-03-08 00:08:10 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2021-03-08 00:08:10 +0900
commitb82c1693c097a53e66ed27dd94d1d0bd9d974d2e (patch)
tree1a06181542e281165e1a21fe55726bfdfa7c0ff1 /src
parent019bfc4e3520aa363246a9ea9d8d2e333758e58b (diff)
downloadfzf-b82c1693c097a53e66ed27dd94d1d0bd9d974d2e.tar.gz
Fix deadlocks
Diffstat (limited to 'src')
-rw-r--r--src/terminal.go36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 34323a65..caafa59c 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -1837,18 +1837,6 @@ func (t *Terminal) cancelPreview() {
t.killPreview(exitCancel)
}
-func (t *Terminal) exit(getCode func() int) {
- t.tui.Close()
- code := getCode()
- if code <= exitNoMatch && t.history != nil {
- t.history.append(string(t.input))
- }
- // prof.Stop()
- t.running = false
- t.mutex.Unlock()
- t.killPreview(code)
-}
-
// Loop is called to start Terminal I/O
func (t *Terminal) Loop() {
// prof := profile.Start(profile.ProfilePath("/tmp/"))
@@ -2073,15 +2061,21 @@ func (t *Terminal) Loop() {
var focusedIndex int32 = minItem.Index()
var version int64 = -1
running := true
+ code := exitError
+ exit := func(getCode func() int) {
+ t.tui.Close()
+ code = getCode()
+ if code <= exitNoMatch && t.history != nil {
+ t.history.append(string(t.input))
+ }
+ running = false
+ t.mutex.Unlock()
+ }
+
for running {
t.reqBox.Wait(func(events *util.Events) {
defer events.Clear()
t.mutex.Lock()
- if !t.running {
- running = false
- t.mutex.Unlock()
- return
- }
for req, value := range *events {
switch req {
case reqPrompt:
@@ -2118,7 +2112,7 @@ func (t *Terminal) Loop() {
case reqRedraw:
t.redraw()
case reqClose:
- t.exit(func() int {
+ exit(func() int {
if t.output() {
return exitOk
}
@@ -2145,13 +2139,13 @@ func (t *Terminal) Loop() {
t.previewer.version = value.(int64)
t.printPreviewDelayed()
case reqPrintQuery:
- t.exit(func() int {
+ exit(func() int {
t.printer(string(t.input))
return exitOk
})
return
case reqQuit:
- t.exit(func() int { return exitInterrupt })
+ exit(func() int { return exitInterrupt })
return
}
}
@@ -2159,6 +2153,8 @@ func (t *Terminal) Loop() {
t.mutex.Unlock()
})
}
+ // prof.Stop()
+ t.killPreview(code)
}()
looping := true