shithub: pplay

Download patch

ref: 7ce3aecba011c42b3ae9e13230110dc73fa48a28
parent: 972c000fd317b151248c2ca73c3a40666e2eb955
author: qwx <qwx@sciops.net>
date: Sun Nov 20 08:54:55 EST 2022

avoid races between sample drawing and edits, fix lmb click behavior

--- a/draw.c
+++ b/draw.c
@@ -5,6 +5,8 @@
 #include "dat.h"
 #include "fns.h"
 
+QLock synclock;
+
 enum{
 	Cbg,
 	Csamp,
@@ -84,13 +86,18 @@
 		m = viewe - views;
 		x = 0;
 		while(m > 0){
-			if(nbrecvul(drawc) == 1)
+			qlock(&synclock);
+			if(nbrecvul(drawc) == 1){
+				qunlock(&synclock);
 				goto again;
+			}
 			n = m < T ? m : T;
 			if((p = getbuf(d, n, sbuf, &n)) == nil){
+				qunlock(&synclock);
 				fprint(2, "getbuf: %r\n");
 				goto end;
 			}
+				qunlock(&synclock);
 			d.pos += n;
 			e = p + n;
 			lmin = lmax = 0;
@@ -254,14 +261,11 @@
 }
 
 void
-setcur(usize off, int jumponly)
+setcur(usize off)
 {
 	if(off < dot.from.pos || off > dot.to.pos - Outsz)
 		return;
-	if(jumponly)
-		jump(off);
-	else
-		setpos(off);
+	jump(off);
 	update();
 }
 
@@ -268,13 +272,13 @@
 void
 setjump(usize off)
 {
-	setcur(off, 1);
+	setcur(off);
 }
 
 void
 setofs(usize ofs)
 {
-	setcur(views + ofs * T, 0);
+	setcur(views + ofs * T);
 }
 
 static void
--- a/pplay.c
+++ b/pplay.c
@@ -7,6 +7,8 @@
 #include "dat.h"
 #include "fns.h"
 
+extern QLock synclock;
+
 int stereo, zoom = 1;
 int debug;
 
@@ -151,6 +153,7 @@
 			default:
 				if((p = prompt(r)) == nil || strlen(p) == 0)
 					break;
+				qlock(&synclock);
 				switch(cmd(p)){
 				case -1: fprint(2, "cmd \"%s\" failed: %r\n", p); break;
 				case 0: update(); break;
@@ -157,6 +160,7 @@
 				case 1: redraw(0); break;
 				case 2: redraw(1); break;
 				}
+				qunlock(&synclock);
 			}
 		}
 	}