git: 9front

Download patch

ref: 2e2a91f26b4724ae5f9942d545749a16b46c2a3f
parent: 06e69640138aee34fdf5cab5d1b2ef668ae9fc38
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Mon Aug 5 00:21:34 EDT 2013

rio: make sure flush replies are send only *after* the request got flushed or was replied

due to the xfid handlers clearing flushtag too early, xfidflush might respond too early
causing spurious replies send later by the handler. now, we clear the flushtag in
filsysrespond *after* the reply was send. xfidflush will wait for us on the active
qlock.

--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -270,6 +270,7 @@
 		fprint(2, "rio:->%F\n", t);
 	free(x->buf);
 	x->buf = nil;
+	x->flushtag = -1;
 	return x;
 }
 
--- a/sys/src/cmd/rio/xfid.c
+++ b/sys/src/cmd/rio/xfid.c
@@ -416,8 +416,9 @@
 		}
 
 		/* received data */
-		x->flushtag = -1;
+		qlock(&x->active);
 		if(x->flushing){
+			qunlock(&x->active);
 			recv(x->flushc, nil);	/* wake up flushing xfid */
 			pair.s = runemalloc(1);
 			pair.ns = 0;
@@ -425,7 +426,6 @@
 			filsyscancel(x);
 			return;
 		}
-		qlock(&x->active);
 		pair.s = r;
 		pair.ns = nr;
 		send(cwm.cw, &pair);
@@ -641,7 +641,6 @@
 		}
 
 		/* received data */
-		x->flushtag = -1;
 		c1 = crm.c1;
 		c2 = crm.c2;
 		t = malloc(cnt+UTFmax+1);	/* room to unpack partial rune plus */
@@ -648,7 +647,9 @@
 		pair.s = t;
 		pair.ns = cnt;
 		send(c1, &pair);
+		qlock(&x->active);
 		if(x->flushing){
+			qunlock(&x->active);
 			recv(x->flushc, nil);	/* wake up flushing xfid */
 			recv(c2, nil);			/* wake up window and toss data */
 			free(t);
@@ -655,13 +656,12 @@
 			filsyscancel(x);
 			return;
 		}
-		qlock(&x->active);
 		recv(c2, &pair);
 		fc.data = pair.s;
 		fc.count = pair.ns;
 		filsysrespond(x->fs, x, &fc, nil);
-		free(t);
 		qunlock(&x->active);
+		free(t);
 		break;
 
 	case Qlabel:
@@ -695,14 +695,14 @@
 		}
 
 		/* received data */
-		x->flushtag = -1;
+		qlock(&x->active);
 		if(x->flushing){
+			qunlock(&x->active);
 			recv(x->flushc, nil);		/* wake up flushing xfid */
 			recv(mrm.cm, nil);			/* wake up window and toss data */
 			filsyscancel(x);
 			return;
 		}
-		qlock(&x->active);
 		recv(mrm.cm, &ms);
 		c = 'm';
 		if(w->resized)
@@ -736,14 +736,14 @@
 
 		/* received data */
 		t = recvp(krm.ck);
-		x->flushtag = -1;
+		qlock(&x->active);
 		if(x->flushing){
+			qunlock(&x->active);
 			free(t);		/* wake up window and toss data */
 			recv(x->flushc, nil);		/* wake up flushing xfid */
 			filsyscancel(x);
 			return;
 		}
-		qlock(&x->active);
 		fc.data = t;
 		fc.count = strlen(t)+1;
 		filsysrespond(x->fs, x, &fc, nil);
@@ -863,7 +863,6 @@
 		}
 
 		/* received data */
-		x->flushtag = -1;
 		c1 = cwrm.c1;
 		c2 = cwrm.c2;
 		t = malloc(cnt+1);	/* be sure to have room for NUL */
@@ -870,7 +869,9 @@
 		pair.s = t;
 		pair.ns = cnt+1;
 		send(c1, &pair);
+		qlock(&x->active);
 		if(x->flushing){
+			qunlock(&x->active);
 			recv(x->flushc, nil);	/* wake up flushing xfid */
 			recv(c2, nil);			/* wake up window and toss data */
 			free(t);
@@ -877,7 +878,6 @@
 			filsyscancel(x);
 			return;
 		}
-		qlock(&x->active);
 		recv(c2, &pair);
 		fc.data = pair.s;
 		if(pair.ns > cnt)
@@ -884,8 +884,8 @@
 			pair.ns = cnt;
 		fc.count = pair.ns;
 		filsysrespond(x->fs, x, &fc, nil);
-		free(t);
 		qunlock(&x->active);
+		free(t);
 		break;
 
 	default:
--