summaryrefslogtreecommitdiff
path: root/sys/src/9/port/segment.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2012-10-10 08:22:35 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2012-10-10 08:22:35 +0200
commit73e7e47d5ba6cb44b159fb0f2cf201b362b6b1b0 (patch)
tree2d05347f0018b6eaed3751780ef05ef673027c9f /sys/src/9/port/segment.c
parentca9f286b6cb434790c2d084117e119b088b49061 (diff)
kenrel: simplify image cache by use of ccloseq()
Diffstat (limited to 'sys/src/9/port/segment.c')
-rw-r--r--sys/src/9/port/segment.c60
1 files changed, 2 insertions, 58 deletions
diff --git a/sys/src/9/port/segment.c b/sys/src/9/port/segment.c
index aa0ab33cc..54c10ebee 100644
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -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);