make kfree loop same as kalloc

This commit is contained in:
rsc 2007-08-27 12:50:36 +00:00
parent 7bb73cdbc7
commit e0240674f5

View file

@ -93,18 +93,15 @@ char*
kalloc(int n) kalloc(int n)
{ {
char *p; char *p;
struct run *r, **rr; struct run *r, **rp;
if(n % PAGE || n <= 0) if(n % PAGE || n <= 0)
panic("kalloc"); panic("kalloc");
acquire(&kalloc_lock); acquire(&kalloc_lock);
for(rp=&freelist; (r=*rp) != 0; rp=&r->next){
rr = &freelist;
while(*rr){
r = *rr;
if(r->len == n){ if(r->len == n){
*rr = r->next; *rp = r->next;
release(&kalloc_lock); release(&kalloc_lock);
return (char*)r; return (char*)r;
} }
@ -114,9 +111,9 @@ kalloc(int n)
release(&kalloc_lock); release(&kalloc_lock);
return p; return p;
} }
rr = &(*rr)->next;
} }
release(&kalloc_lock); release(&kalloc_lock);
cprintf("kalloc: out of memory\n"); cprintf("kalloc: out of memory\n");
return 0; return 0;
} }