make kfree loop same as kalloc
This commit is contained in:
parent
7bb73cdbc7
commit
e0240674f5
1 changed files with 5 additions and 8 deletions
11
kalloc.c
11
kalloc.c
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue