shithub: plan9front

Download patch

ref: 5dba948712bce034bdedb8b14afcc47293e94ebc
parent: 41c959afd6f41c8151c57685fabe7e148f9e2e88
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Jan 3 17:06:33 EST 2023

audio/mixfs: implement flush

--- a/sys/src/cmd/audio/mixfs/mixfs.c
+++ b/sys/src/cmd/audio/mixfs/mixfs.c
@@ -16,6 +16,7 @@
 {
 	int	used;
 	int	mode;
+	int	flush;
 	int	run;
 	ulong	rp;
 	ulong	wp;
@@ -66,6 +67,7 @@
 		if(s->used == 0 && s->run == 0){
 			s->used = 1;
 			s->mode = r->ifcall.mode;
+			s->flush = 0;
 			qunlock(s);
 
 			r->fid->aux = s;
@@ -78,6 +80,23 @@
 }
 
 void
+fsflush(Req *r)
+{
+	Fid *f = r->oldreq->fid;
+	Stream *s;
+
+	if(f->file != nil && strcmp(f->file->name, "audio") == 0 && (s = f->aux) != nil){
+		qlock(s);
+		if(s->used && s->run){
+			s->flush = 1;
+			rwakeup(s);
+		}
+		qunlock(s);
+	}
+	respond(r, nil);
+}
+
+void
 fsclunk(Fid *f)
 {
 	Stream *s;
@@ -203,6 +222,8 @@
 		}
 		m = (long)(mixrp - s->rp);
 		if(m <= 0){
+			if(s->flush)
+				break;
 			s->run = 1;
 			rsleep(s);
 			continue;
@@ -225,6 +246,7 @@
 
 		n -= m;
 	}
+	s->flush = 0;
 	qunlock(s);
 	respond(r, nil);
 	srvacquire(srv);
@@ -255,6 +277,8 @@
 		m = NBUF-1 - (long)(s->wp - mixrp);
 
 		if(m <= 0){
+			if(s->flush)
+				break;
 			s->run = 1;
 			rsleep(s);
 			continue;
@@ -274,10 +298,11 @@
 
 		n -= m;
 	}
-	if((long)(s->wp - mixrp) >= NDELAY){
+	if((long)(s->wp - mixrp) >= NDELAY && !s->flush){
 		s->run = 1;
 		rsleep(s);
 	}
+	s->flush = 0;
 	qunlock(s);
 	respond(r, nil);
 	srvacquire(srv);
@@ -329,6 +354,7 @@
 	.write=		fswrite,
 	.stat=		fsstat,
 	.destroyfid=	fsclunk,
+	.flush=		fsflush,
 	.start=		fsstart,
 	.end=		fsend,
 };