alloc: fix indent
This commit is contained in:
parent
f3a03f3965
commit
f90b9bd3fd
33
core/alloc.c
33
core/alloc.c
@ -7,7 +7,6 @@
|
|||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "vga.h"
|
#include "vga.h"
|
||||||
|
|
||||||
|
|
||||||
#define IS_SELF_CONTAINED(desc) ((vaddr_t)((desc)->page) == (vaddr_t)(desc))
|
#define IS_SELF_CONTAINED(desc) ((vaddr_t)((desc)->page) == (vaddr_t)(desc))
|
||||||
// Slab will contains object from sizeof(void *) to PAGE_SIZE/2 by pow2
|
// Slab will contains object from sizeof(void *) to PAGE_SIZE/2 by pow2
|
||||||
#define SLUB_SIZE (PAGE_SHIFT - 1)
|
#define SLUB_SIZE (PAGE_SHIFT - 1)
|
||||||
@ -36,7 +35,7 @@ int allocInit(void)
|
|||||||
|
|
||||||
int allocBookSlab(size_t size, int selfContained)
|
int allocBookSlab(size_t size, int selfContained)
|
||||||
{
|
{
|
||||||
//pr_devel("%s for size %d is self %d\n", __func__, size, selfContained );
|
// pr_devel("%s for size %d is self %d\n", __func__, size, selfContained );
|
||||||
struct slabDesc *slabEntry;
|
struct slabDesc *slabEntry;
|
||||||
struct slabDesc *slab;
|
struct slabDesc *slab;
|
||||||
int slabIdx;
|
int slabIdx;
|
||||||
@ -73,13 +72,13 @@ int addSlab(struct slabDesc **desc, size_t size, int selfContained)
|
|||||||
*desc = (struct slabDesc *)alloc;
|
*desc = (struct slabDesc *)alloc;
|
||||||
(*desc)->freeEl = (char *)(*desc) + sizeof(struct slabDesc);
|
(*desc)->freeEl = (char *)(*desc) + sizeof(struct slabDesc);
|
||||||
} else {
|
} else {
|
||||||
*desc = malloc(sizeof(struct slabDesc));
|
*desc = malloc(sizeof(struct slabDesc));
|
||||||
(*desc)->freeEl = (void *)alloc;
|
(*desc)->freeEl = (void *)alloc;
|
||||||
}
|
}
|
||||||
list_singleton(*desc, *desc);
|
list_singleton(*desc, *desc);
|
||||||
(*desc)->page = (vaddr_t)alloc;
|
(*desc)->page = (vaddr_t)alloc;
|
||||||
(*desc)->full = 0;
|
(*desc)->full = 0;
|
||||||
(*desc)->size = size;
|
(*desc)->size = size;
|
||||||
pr_devel("got page %d for size %d first %d", alloc, size, (*desc)->freeEl);
|
pr_devel("got page %d for size %d first %d", alloc, size, (*desc)->freeEl);
|
||||||
return formatPage((*desc), size, selfContained);
|
return formatPage((*desc), size, selfContained);
|
||||||
}
|
}
|
||||||
@ -119,7 +118,7 @@ void *malloc(size_t size)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
struct slabDesc *slubEntry;
|
struct slabDesc *slubEntry;
|
||||||
uint slubIdx = 0;
|
uint slubIdx;
|
||||||
list_foreach(slub, slubEntry, slubIdx)
|
list_foreach(slub, slubEntry, slubIdx)
|
||||||
{
|
{
|
||||||
if (size <= slubEntry->size)
|
if (size <= slubEntry->size)
|
||||||
@ -130,7 +129,8 @@ void *malloc(size_t size)
|
|||||||
list_foreach(slubEntry, slab, slabIdx)
|
list_foreach(slubEntry, slab, slabIdx)
|
||||||
{
|
{
|
||||||
if (!slab->full) {
|
if (!slab->full) {
|
||||||
pr_devel("found place in slub %d at idx %d for size %d\n", slubIdx, slabIdx, size);
|
pr_devel("found place in slub %d at idx %d for size %d\n", slubIdx,
|
||||||
|
slabIdx, size);
|
||||||
return allocFromSlab(slab);
|
return allocFromSlab(slab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,30 +146,33 @@ void *malloc(size_t size)
|
|||||||
return allocFromSlab(newSlab);
|
return allocFromSlab(newSlab);
|
||||||
}
|
}
|
||||||
|
|
||||||
int slabFree(void *ptr, struct slabDesc *slab){
|
int slabFree(void *ptr, struct slabDesc *slab)
|
||||||
|
{
|
||||||
struct slabDesc *slabEntry;
|
struct slabDesc *slabEntry;
|
||||||
int slabIdx;
|
int slabIdx;
|
||||||
list_foreach(slab, slabEntry, slabIdx)
|
list_foreach(slab, slabEntry, slabIdx)
|
||||||
{
|
{
|
||||||
if ((slabEntry->page <= (vaddr_t)ptr) &&
|
if ((slabEntry->page <= (vaddr_t)ptr) &&
|
||||||
((vaddr_t)ptr < (slabEntry->page + PAGE_SIZE))){
|
((vaddr_t)ptr < (slabEntry->page + PAGE_SIZE))) {
|
||||||
pr_devel("free place! was %d is now %d\n", slabEntry->freeEl, ptr);
|
pr_devel("free place! was %d is now %d\n", slabEntry->freeEl, ptr);
|
||||||
*((vaddr_t *)ptr) = (vaddr_t)slabEntry->freeEl;
|
*((vaddr_t *)ptr) = (vaddr_t)slabEntry->freeEl;
|
||||||
slabEntry->freeEl = ptr;
|
slabEntry->freeEl = ptr;
|
||||||
slabEntry->full = 0;
|
slabEntry->full = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void free(void *ptr){
|
void free(void *ptr)
|
||||||
if(!ptr)
|
{
|
||||||
|
if (!ptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct slabDesc *slab;
|
struct slabDesc *slab;
|
||||||
int slabIdx;
|
int slabIdx;
|
||||||
list_foreach(slub, slab, slabIdx){
|
list_foreach(slub, slab, slabIdx)
|
||||||
if(slabFree(ptr, slab))
|
{
|
||||||
|
if (slabFree(ptr, slab))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pr_devel("free: slab not found\n");
|
pr_devel("free: slab not found\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user