aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-01-05 14:01:29 -0800
committerChristian Cunningham <cc@localhost>2022-01-05 14:01:29 -0800
commit3a8ed19bf83f11ff00c4904fab2cc083b7e33478 (patch)
tree9d9a6f92f9d74001e969d23ea79ad26f6227fea2 /src/lib
parentf3ea4cd0c22f351d8dfffb0e937194c4b526b665 (diff)
Cleaned up/ Standardized
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ll.c6
-rw-r--r--src/lib/ll.h8
-rw-r--r--src/lib/mem.c7
-rw-r--r--src/lib/q.c6
-rw-r--r--src/lib/q.h8
5 files changed, 20 insertions, 15 deletions
diff --git a/src/lib/ll.c b/src/lib/ll.c
index 6d96f45..7f1a47e 100644
--- a/src/lib/ll.c
+++ b/src/lib/ll.c
@@ -1,7 +1,7 @@
#include "../lib/ll.h"
#include "../lib/mem.h"
-struct LL* new(void* val)
+struct LL* new_ll(void* val)
{
struct LL* ll = (struct LL*)malloc(sizeof(struct LL));
ll->prev = ll;
@@ -10,7 +10,7 @@ struct LL* new(void* val)
return ll;
}
-void push(struct LL* l, void* val)
+void push_ll(struct LL* l, void* val)
{
struct LL* ll = (struct LL*)malloc(sizeof(struct LL));
ll->prev = l->prev;
@@ -20,7 +20,7 @@ void push(struct LL* l, void* val)
ll->data = val;
}
-void remove(struct LL* l, unsigned long idx)
+void remove_ll(struct LL* l, unsigned long idx)
{
struct LL* t = l;
for(unsigned long i = 0; i < idx; i++) {
diff --git a/src/lib/ll.h b/src/lib/ll.h
index 4a11620..ab4148d 100644
--- a/src/lib/ll.h
+++ b/src/lib/ll.h
@@ -7,11 +7,11 @@ struct LL {
void* data;
};
-struct LL* new(void* val);
-void push(struct LL* l, void* val);
-void remove(struct LL* l, unsigned long idx);
+struct LL* new_ll(void* val);
+void push_ll(struct LL* l, void* val);
+void remove_ll(struct LL* l, unsigned long idx);
-#define showl(L, TYPE) { \
+#define show_ll(L, TYPE) { \
struct LL* t = L; \
do { \
uart_hex(*(TYPE*)t->data); \
diff --git a/src/lib/mem.c b/src/lib/mem.c
index d738305..2b495ef 100644
--- a/src/lib/mem.c
+++ b/src/lib/mem.c
@@ -73,6 +73,7 @@ void* malloca(unsigned char size, unsigned char amnt)
unsigned long diff = (unsigned long)mem + i + 2;
diff %= amnt;
diff = amnt - diff;
+ diff %= amnt;
if((mem[i] == size) && mem[i+1]==0) {
if(diff == 0) {
mem[i] = size;
@@ -90,7 +91,6 @@ void* malloca(unsigned char size, unsigned char amnt)
diff += amnt;
}
mem[i] = diff-2;
- mem[i+1] = 0;
i += diff;
mem[i] = size;
mem[i+1] = 1;
@@ -116,6 +116,11 @@ void free(void* memloc)
for(unsigned int i = 0; i < size; i++) {
base[i+2] = 0;
}
+ // If it is the last entry, clear it and move the heap top down
+ if (base + size + 2 == rpi_heap_top) {
+ base[0] = 0;
+ rpi_heap_top = base;
+ }
}
void* heap_base(void)
diff --git a/src/lib/q.c b/src/lib/q.c
index 494c712..1f5a871 100644
--- a/src/lib/q.c
+++ b/src/lib/q.c
@@ -1,7 +1,7 @@
#include "../lib/q.h"
#include "../lib/mem.h"
-struct Q_base* newq()
+struct Q_base* new_q()
{
struct Q_base* q = (struct Q_base*)malloc(sizeof(struct Q_base));
q->next = 0;
@@ -9,7 +9,7 @@ struct Q_base* newq()
return q;
}
-void pushq(struct Q_base* qb, void* val)
+void push_q(struct Q_base* qb, void* val)
{
struct Q* n = (struct Q*)malloc(sizeof(struct Q));
n->next = 0;
@@ -22,7 +22,7 @@ void pushq(struct Q_base* qb, void* val)
qb->last = n;
}
-void popq(struct Q_base* qb)
+void pop_q(struct Q_base* qb)
{
if (qb->next == 0)
return;
diff --git a/src/lib/q.h b/src/lib/q.h
index 51ff1a1..cf75c6d 100644
--- a/src/lib/q.h
+++ b/src/lib/q.h
@@ -11,11 +11,11 @@ struct Q {
void* data;
};
-struct Q_base* newq();
-void pushq(struct Q_base* qb, void* val);
-void popq(struct Q_base* qb);
+struct Q_base* new_q();
+void push_q(struct Q_base* qb, void* val);
+void pop_q(struct Q_base* qb);
-#define showq(QQ, TYPE) { \
+#define show_q(QQ, TYPE) { \
if (QQ->next != 0) { \
struct Q* t = QQ->next; \
while (t->next != 0) { \