ref: b9bc564345ce7f9c6030377caecb4f7e272c9008
parent: c2884b1bbdd013e9e5bf53ab2a63526cf61756c3
author: qwx <qwx@sciops.net>
date: Fri Aug 25 10:29:53 EDT 2023
cmd: don't freeze all input during long edit operation
--- a/cmd.c
+++ b/cmd.c
@@ -4,7 +4,6 @@
#include "dat.h"
#include "fns.h"
-int treadsoftly;
usize ndots;
Dot *current, *dots;
@@ -44,7 +43,12 @@
static int
paste(char *)
{
- return cpaste(current) == 0 ? 1 : -1;
+ int r;
+
+ qlock(&lsync);
+ r = cpaste(current) == 0 ? 1 : -1;
+ qunlock(&lsync);
+ return r;
}
static int
@@ -62,7 +66,9 @@
werrstr("cut: can't cut entire buffer");
return -1;
}
+ qlock(&lsync);
ccut(current);
+ qunlock(&lsync);
return 1;
}
@@ -70,7 +76,9 @@
crop(char *)
{
dprint(nil, "cmd/crop %Δ\n", current);
+ qlock(&lsync);
ccrop(current);
+ qunlock(&lsync);
return 1;
}
@@ -131,10 +139,8 @@
Chunk *c;
d = *current;
- treadsoftly++;
fd = (intptr)efd;
if((c = loadfile(fd, &cd)) == nil){
- treadsoftly = 0;
fprint(2, "failed reading from pipe: %r");
threadexits("read error");
}
@@ -145,7 +151,6 @@
if(paste(nil) < 0)
fprint(2, "paste: %r\n");
qunlock(&lsync);
- treadsoftly--;
redraw(0);
threadexits(nil);
}
--- a/pplay.c
+++ b/pplay.c
@@ -128,10 +128,12 @@
for(;;){
switch(alt(a)){
case 0:
+ qlock(&lsync);
if(getwindow(display, Refnone) < 0)
sysfatal("resize failed: %r");
mo = mc->Mouse;
redraw(1);
+ qunlock(&lsync);
break;
case 1:
if(eqpt(mo.xy, ZP))
@@ -165,11 +167,6 @@
default:
if((p = prompt(r)) == nil || strlen(p) == 0)
break;
- if(treadsoftly){
- fprint(2, "dropping edit command during ongoing read\n");
- break;
- }
- qlock(&lsync);
switch(cmd(p)){
case -1: fprint(2, "cmd \"%s\" failed: %r\n", p); update(0, 0); break;
case 0: update(0, 0); break;
@@ -176,7 +173,6 @@
case 1: redraw(0); break;
case 2: redraw(1); break;
}
- qunlock(&lsync);
}
}
}