summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-21 21:23:30 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-21 21:23:30 -0400
commit15b856abccef75361ccd64221757c8b63ef1d441 (patch)
tree724b6bda254f8d27cfe7ab9bf5b98791010ce5e6 /widgets
parentbe2918a6164989aba5b18b4f642501ddb8801c10 (diff)
downloadaerc-15b856abccef75361ccd64221757c8b63ef1d441.tar.gz
Make terminal closure thread safe
Diffstat (limited to 'widgets')
-rw-r--r--widgets/terminal.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/widgets/terminal.go b/widgets/terminal.go
index 7aaeda0..24925ae 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -4,6 +4,7 @@ import (
 	gocolor "image/color"
 	"os"
 	"os/exec"
+	"sync"
 
 	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
 
@@ -92,11 +93,12 @@ type Terminal struct {
 	cmd          *exec.Cmd
 	colors       map[tcell.Color]tcell.Color
 	ctx          *ui.Context
-	cursorShown  bool
 	cursorPos    vterm.Pos
+	cursorShown  bool
 	damage       []vterm.Rect
 	err          error
 	focus        bool
+	mutex        sync.Mutex
 	onInvalidate func(d ui.Drawable)
 	pty          *os.File
 	start        chan interface{}
@@ -189,6 +191,8 @@ func (term *Terminal) flushTerminal() {
 }
 
 func (term *Terminal) Close(err error) {
+	term.mutex.Lock()
+	defer term.mutex.Unlock()
 	term.err = err
 	if term.vterm != nil {
 		term.vterm.Close()
@@ -229,6 +233,9 @@ func (term *Terminal) Draw(ctx *ui.Context) {
 		return
 	}
 
+	term.mutex.Lock()
+	defer term.mutex.Unlock()
+
 	winsize := pty.Winsize{
 		Cols: uint16(ctx.Width()),
 		Rows: uint16(ctx.Height()),
@@ -239,6 +246,7 @@ func (term *Terminal) Draw(ctx *ui.Context) {
 		tty, err := pty.StartWithSize(term.cmd, &winsize)
 		term.pty = tty
 		if err != nil {
+			term.mutex.Unlock()
 			term.Close(err)
 			return
 		}
ref='/akkartik/mu/commit/subx/028translate.cc?h=hlt&id=c442a5ad806b6cccbb3ec4c5744b14b0c1f31a01'>c442a5ad ^
1dcd9350 ^

















55b4627d ^
c442a5ad ^
55b4627d ^

c442a5ad ^
1dcd9350 ^
a988da65 ^
1dcd9350 ^
a988da65 ^

9e5e87ca ^
55b4627d ^


b141a448 ^
d02aa9ac ^



1dcd9350 ^
9e5e87ca ^
1dcd9350 ^

1f56ac64 ^
1dcd9350 ^

ef52bbf9 ^




68ccf4d3 ^
6dff1f28 ^



68ccf4d3 ^




3b798ea2 ^
1f56ac64 ^
3b798ea2 ^
b141a448 ^

3b798ea2 ^
b141a448 ^

















ef52bbf9 ^
8188bbbc ^
b141a448 ^

8188bbbc ^
b141a448 ^

8188bbbc ^
b141a448 ^



1f56ac64 ^
b141a448 ^




1f56ac64 ^
b141a448 ^








1bbbf14f ^
1f56ac64 ^
83c67014 ^
1f56ac64 ^






83c67014 ^
a49bc413 ^
1f56ac64 ^
a49bc413 ^
1f56ac64 ^
83c67014 ^
4a99a6e0 ^
1f56ac64 ^



83c67014 ^
1f56ac64 ^
21d8241b ^
1f56ac64 ^
21d8241b ^









dc9a126e ^
1f56ac64 ^
a49bc413 ^

bcf92ad2 ^


1f56ac64 ^


b141a448 ^
262f6ea8 ^
b141a448 ^

3b798ea2 ^
1f56ac64 ^





b20d9ad3 ^
b20d9ad3 ^

a49bc413 ^
1f56ac64 ^




7b686a02 ^
b141a448 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206