kenrel: simplify image cache by use of ccloseq()
This commit is contained in:
parent
ca9f286b6c
commit
73e7e47d5b
2 changed files with 7 additions and 61 deletions
|
@ -14,7 +14,7 @@ enum
|
|||
PATHMSLOP = 20,
|
||||
};
|
||||
|
||||
struct
|
||||
static struct Chanalloc
|
||||
{
|
||||
Lock;
|
||||
int fid;
|
||||
|
@ -223,8 +223,10 @@ newchan(void)
|
|||
|
||||
lock(&chanalloc);
|
||||
c = chanalloc.free;
|
||||
if(c != 0)
|
||||
if(c != 0){
|
||||
chanalloc.free = c->next;
|
||||
c->next = 0;
|
||||
}
|
||||
unlock(&chanalloc);
|
||||
|
||||
if(c == nil){
|
||||
|
@ -532,7 +534,7 @@ closechanq(Chan *c)
|
|||
clunkq.tail = c;
|
||||
unlock(&clunkq.l);
|
||||
|
||||
if(canqlock(&clunkq.q)){
|
||||
if(up != 0 && palloc.Lock.p != up && canqlock(&clunkq.q)){
|
||||
c = up->dot;
|
||||
up->dot = nil;
|
||||
kproc("closeproc", closeproc, nil);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "../port/error.h"
|
||||
|
||||
static void imagereclaim(void);
|
||||
static void imagechanreclaim(void);
|
||||
|
||||
#include "io.h"
|
||||
|
||||
|
@ -21,7 +20,6 @@ static Physseg physseg[10] = {
|
|||
|
||||
static Lock physseglock;
|
||||
|
||||
#define NFREECHAN 64
|
||||
#define IHASHSIZE 64
|
||||
#define ihash(s) imagealloc.hash[s%IHASHSIZE]
|
||||
static struct Imagealloc
|
||||
|
@ -30,11 +28,6 @@ static struct Imagealloc
|
|||
Image *free;
|
||||
Image *hash[IHASHSIZE];
|
||||
QLock ireclaim; /* mutex on reclaiming free images */
|
||||
|
||||
Chan **freechan; /* free image channels */
|
||||
int nfreechan; /* number of free channels */
|
||||
int szfreechan; /* size of freechan array */
|
||||
QLock fcreclaim; /* mutex on reclaiming free channels */
|
||||
}imagealloc;
|
||||
|
||||
Segment* (*_globalsegattach)(Proc*, char*);
|
||||
|
@ -51,10 +44,6 @@ initseg(void)
|
|||
for(i = imagealloc.free; i < ie; i++)
|
||||
i->next = i+1;
|
||||
i->next = 0;
|
||||
imagealloc.freechan = malloc(NFREECHAN * sizeof(Chan*));
|
||||
if(imagealloc.freechan == nil)
|
||||
panic("initseg: no memory for Chan");
|
||||
imagealloc.szfreechan = NFREECHAN;
|
||||
}
|
||||
|
||||
Segment *
|
||||
|
@ -249,10 +238,6 @@ attachimage(int type, Chan *c, ulong base, ulong len)
|
|||
{
|
||||
Image *i, **l;
|
||||
|
||||
/* reclaim any free channels from reclaimed segments */
|
||||
if(imagealloc.nfreechan)
|
||||
imagechanreclaim();
|
||||
|
||||
lock(&imagealloc);
|
||||
|
||||
/*
|
||||
|
@ -362,41 +347,11 @@ imagereclaim(void)
|
|||
qunlock(&imagealloc.ireclaim);
|
||||
}
|
||||
|
||||
/*
|
||||
* since close can block, this has to be called outside of
|
||||
* spin locks.
|
||||
*/
|
||||
static void
|
||||
imagechanreclaim(void)
|
||||
{
|
||||
Chan *c;
|
||||
|
||||
/* Somebody is already cleaning the image chans */
|
||||
if(!canqlock(&imagealloc.fcreclaim))
|
||||
return;
|
||||
|
||||
/*
|
||||
* We don't have to recheck that nfreechan > 0 after we
|
||||
* acquire the lock, because we're the only ones who decrement
|
||||
* it (the other lock contender increments it), and there's only
|
||||
* one of us thanks to the qlock above.
|
||||
*/
|
||||
while(imagealloc.nfreechan > 0){
|
||||
lock(&imagealloc);
|
||||
imagealloc.nfreechan--;
|
||||
c = imagealloc.freechan[imagealloc.nfreechan];
|
||||
unlock(&imagealloc);
|
||||
cclose(c);
|
||||
}
|
||||
|
||||
qunlock(&imagealloc.fcreclaim);
|
||||
}
|
||||
|
||||
void
|
||||
putimage(Image *i)
|
||||
{
|
||||
Chan *c, **cp;
|
||||
Image *f, **l;
|
||||
Chan *c;
|
||||
|
||||
if(i->notext)
|
||||
return;
|
||||
|
@ -419,20 +374,9 @@ putimage(Image *i)
|
|||
|
||||
i->next = imagealloc.free;
|
||||
imagealloc.free = i;
|
||||
|
||||
/* defer freeing channel till we're out of spin lock's */
|
||||
if(imagealloc.nfreechan == imagealloc.szfreechan){
|
||||
imagealloc.szfreechan += NFREECHAN;
|
||||
cp = malloc(imagealloc.szfreechan*sizeof(Chan*));
|
||||
if(cp == nil)
|
||||
panic("putimage");
|
||||
memmove(cp, imagealloc.freechan, imagealloc.nfreechan*sizeof(Chan*));
|
||||
free(imagealloc.freechan);
|
||||
imagealloc.freechan = cp;
|
||||
}
|
||||
imagealloc.freechan[imagealloc.nfreechan++] = c;
|
||||
unlock(&imagealloc);
|
||||
|
||||
ccloseq(c); /* does not block */
|
||||
return;
|
||||
}
|
||||
unlock(i);
|
||||
|
|
Loading…
Reference in a new issue