devmnt: use u32int for tagmask, simplify alloctag()

This commit is contained in:
cinap_lenrek 2017-12-28 18:25:15 +01:00
parent b9d2a9efd5
commit 80185daba9

View file

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