ref: 73e7e47d5ba6cb44b159fb0f2cf201b362b6b1b0
parent: ca9f286b6cb434790c2d084117e119b088b49061
author: cinap_lenrek <[email protected]>
date: Wed Oct 10 04:22:35 EDT 2012
kenrel: simplify image cache by use of ccloseq()
--- a/sys/src/9/port/chan.c
+++ b/sys/src/9/port/chan.c
@@ -14,7 +14,7 @@
PATHMSLOP = 20,
};
-struct
+static struct Chanalloc
{
Lock;
int fid;
@@ -223,8 +223,10 @@
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 @@
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);
--- 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 Lock physseglock;
-#define NFREECHAN 64
#define IHASHSIZE 64
#define ihash(s) imagealloc.hash[s%IHASHSIZE]
static struct Imagealloc
@@ -30,11 +28,6 @@
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 @@
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 @@
{
Image *i, **l;
- /* reclaim any free channels from reclaimed segments */
- if(imagealloc.nfreechan)
- imagechanreclaim();
-
lock(&imagealloc);
/*
@@ -362,41 +347,11 @@
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 @@
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);