shithub: drawterm

Download patch

ref: 15af8dd530c246b1f63ded61a592804d403033aa
parent: 74af129a2094d40e5b3a94c1116cf83cee84b928
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Dec 28 13:28:31 EST 2017

devmnt: use u32int for tagmask, simplify alloctag()

the ~0UL constant is 64 bit on amd64/gcc, which made the
if(v == ~0UL) always false causing every bit to be probed.

--- a/kern/devmnt.c
+++ b/kern/devmnt.c
@@ -32,7 +32,7 @@
 
 enum
 {
-	TAGSHIFT = 5,			/* ulong has to be 32 bits */
+	TAGSHIFT = 5,
 	TAGMASK = (1<<TAGSHIFT)-1,
 	NMASK = (64*1024)>>TAGSHIFT,
 };
@@ -46,7 +46,7 @@
 	ulong	nrpcfree;
 	ulong	nrpcused;
 	ulong	id;
-	ulong	tagmask[NMASK];
+	u32int	tagmask[NMASK];
 } mntalloc;
 
 static Chan*	mntchan(void);
@@ -74,7 +74,7 @@
 {
 	mntalloc.id = 1;
 	mntalloc.tagmask[0] = 1;			/* don't allow 0 as a tag */
-	mntalloc.tagmask[NMASK-1] = 0x80000000UL;	/* don't allow NOTAG */
+	mntalloc.tagmask[NMASK-1] = 0x80000000;		/* don't allow NOTAG */
 	fmtinstall('F', fcallfmt);
 	fmtinstall('D', dirfmt);
 /* We can't install %M since eipfmt does and is used in the kernel [sape] */
@@ -975,17 +975,16 @@
 alloctag(void)
 {
 	int i, j;
-	ulong v;
+	u32int v;
 
 	for(i = 0; i < NMASK; i++){
 		v = mntalloc.tagmask[i];
-		if(v == ~0UL)
+		if(v == -1)
 			continue;
-		for(j = 0; j < 1<<TAGSHIFT; j++)
-			if((v & (1<<j)) == 0){
-				mntalloc.tagmask[i] |= 1<<j;
-				return (i<<TAGSHIFT) + j;
-			}
+		for(j = 0; (v & 1) != 0; j++)
+			v >>= 1;
+		mntalloc.tagmask[i] |= 1<<j;
+		return i<<TAGSHIFT | j;
 	}
 	panic("no friggin tags left");
 	return NOTAG;