rename: stack -> list
This commit is contained in:
parent
765d519010
commit
476fd1f2c2
1 changed files with 12 additions and 12 deletions
24
src/jalloc.c
24
src/jalloc.c
|
|
@ -22,7 +22,7 @@ struct Footer {
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint8_t heap[HEAP_SIZE];
|
static uint8_t heap[HEAP_SIZE];
|
||||||
static struct Header *free_stack;
|
static struct Header *free_list;
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
|
|
||||||
struct Footer *footer(struct Header *hdr) {
|
struct Footer *footer(struct Header *hdr) {
|
||||||
|
|
@ -30,17 +30,17 @@ struct Footer *footer(struct Header *hdr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Header *pop_first_fit(size_t size) {
|
struct Header *pop_first_fit(size_t size) {
|
||||||
if (free_stack == NULL) return NULL;
|
if (free_list == NULL) return NULL;
|
||||||
struct Header *head = free_stack;
|
struct Header *head = free_list;
|
||||||
if (head->size >= size) {
|
if (head->size >= size) {
|
||||||
free_stack = head->next_free; // remove from free stack
|
free_list = head->next_free; // remove from free list
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
while (head != NULL) {
|
while (head != NULL) {
|
||||||
struct Header *next = head->next_free;
|
struct Header *next = head->next_free;
|
||||||
if (next == NULL) return NULL;
|
if (next == NULL) return NULL;
|
||||||
if (next->size >= size) {
|
if (next->size >= size) {
|
||||||
head->next_free = next->next_free; // remove from free stack
|
head->next_free = next->next_free; // remove from free list
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
head = next;
|
head = next;
|
||||||
|
|
@ -49,10 +49,10 @@ struct Header *pop_first_fit(size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Header *pop(struct Header *ptr) {
|
struct Header *pop(struct Header *ptr) {
|
||||||
if (free_stack == NULL) return NULL;
|
if (free_list == NULL) return NULL;
|
||||||
struct Header *head = free_stack;
|
struct Header *head = free_list;
|
||||||
if (head == ptr) {
|
if (head == ptr) {
|
||||||
free_stack = head->next_free;
|
free_list = head->next_free;
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
while (head != NULL) {
|
while (head != NULL) {
|
||||||
|
|
@ -68,8 +68,8 @@ struct Header *pop(struct Header *ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_header(struct Header *hdr) {
|
void push_header(struct Header *hdr) {
|
||||||
hdr->next_free = free_stack;
|
hdr->next_free = free_list;
|
||||||
free_stack = hdr;
|
free_list = hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize() {
|
void initialize() {
|
||||||
|
|
@ -92,7 +92,7 @@ struct Header *shrink(struct Header *hdr, size_t size) {
|
||||||
// given a size, shrink a block down to the appropriate alignment.
|
// given a size, shrink a block down to the appropriate alignment.
|
||||||
// if align(size) + ALIGNMENT*3 is equal to current size, just return initial ptr with noop
|
// if align(size) + ALIGNMENT*3 is equal to current size, just return initial ptr with noop
|
||||||
// otherwise, shrink it down so that we have two blocks.
|
// otherwise, shrink it down so that we have two blocks.
|
||||||
// Push the right block to the free stack
|
// Push the right block to the free list
|
||||||
// Return left block
|
// Return left block
|
||||||
|
|
||||||
if (size + HEADER_SIZE + FOOTER_SIZE > hdr->size) return hdr;
|
if (size + HEADER_SIZE + FOOTER_SIZE > hdr->size) return hdr;
|
||||||
|
|
@ -113,7 +113,7 @@ struct Header *shrink(struct Header *hdr, size_t size) {
|
||||||
struct Footer *next_ftr = footer(next_hdr);
|
struct Footer *next_ftr = footer(next_hdr);
|
||||||
next_ftr->header = next_hdr;
|
next_ftr->header = next_hdr;
|
||||||
|
|
||||||
// push new block to stack
|
// push new block to list
|
||||||
push_header(next_hdr);
|
push_header(next_hdr);
|
||||||
}
|
}
|
||||||
return hdr;
|
return hdr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue