aboutsummaryrefslogtreecommitdiffstats
path: root/src/heap.c
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2018-02-21 16:43:38 -0500
committerClyne Sullivan <tullivan99@gmail.com>2018-02-21 16:43:38 -0500
commiteee1be766d35a3ab76b10fc0aeaf1bbe7a88bfbc (patch)
tree15901f324ca613e960619c6928b700b0052622f4 /src/heap.c
parent5a6c8f4c22e6581f1b970afd68bf4c2c4db4ebf2 (diff)
rejoice! tasks suck no more
Diffstat (limited to 'src/heap.c')
-rw-r--r--src/heap.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/heap.c b/src/heap.c
index 2157aad..5d32a14 100644
--- a/src/heap.c
+++ b/src/heap.c
@@ -1,4 +1,5 @@
-#include "heap.h"
+#include <heap.h>
+#include <task.h>
#define HEAP_ALIGN 16
@@ -20,6 +21,9 @@ void heap_init(void *buf)
void *malloc(uint32_t size)
{
+ task_hold(1);
+ if (size < 16)
+ size = 16;
alloc_t *node = &root;
while (node->next & 1 || node->size < size) {
if ((node->next & ~(1)) == 0) {
@@ -34,6 +38,7 @@ void *malloc(uint32_t size)
}
node->next |= 1;
+ task_hold(0);
return (void *)((uint32_t)node + sizeof(alloc_t));
}
@@ -53,4 +58,3 @@ void free(void *buf)
alloc_t *alloc = (alloc_t *)((uint32_t)buf - sizeof(alloc_t));
alloc->next &= ~(1);
}
-