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)
|
||||
{
|
||||
char *p;
|
||||
struct run *r, **rr;
|
||||
struct run *r, **rp;
|
||||
|
||||
if(n % PAGE || n <= 0)
|
||||
panic("kalloc");
|
||||
|
||||
acquire(&kalloc_lock);
|
||||
|
||||
rr = &freelist;
|
||||
while(*rr){
|
||||
r = *rr;
|
||||
for(rp=&freelist; (r=*rp) != 0; rp=&r->next){
|
||||
if(r->len == n){
|
||||
*rr = r->next;
|
||||
*rp = r->next;
|
||||
release(&kalloc_lock);
|
||||
return (char*)r;
|
||||
}
|
||||
|
@ -114,9 +111,9 @@ kalloc(int n)
|
|||
release(&kalloc_lock);
|
||||
return p;
|
||||
}
|
||||
rr = &(*rr)->next;
|
||||
}
|
||||
release(&kalloc_lock);
|
||||
|
||||
cprintf("kalloc: out of memory\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue