aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel/src/chheap.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-01-24 09:04:55 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-01-24 09:04:55 +0000
commit86eb39129b8ac6ba74778c72261f2048c2da1114 (patch)
tree076701c638a3d332f175afedd0623d8af3417813 /os/kernel/src/chheap.c
parentedc56330a91f1f646d8b78ead8a89c46a5d841e6 (diff)
downloadChibiOS-86eb39129b8ac6ba74778c72261f2048c2da1114.tar.gz
ChibiOS-86eb39129b8ac6ba74778c72261f2048c2da1114.tar.bz2
ChibiOS-86eb39129b8ac6ba74778c72261f2048c2da1114.zip
Changes suggested by Adamo and Enrico.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1543 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/kernel/src/chheap.c')
-rw-r--r--os/kernel/src/chheap.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/os/kernel/src/chheap.c b/os/kernel/src/chheap.c
index d9d88d78b..e434fd2ab 100644
--- a/os/kernel/src/chheap.c
+++ b/os/kernel/src/chheap.c
@@ -53,7 +53,7 @@ static MemoryHeap default_heap;
*/
void heap_init(void) {
default_heap.h_provider = chCoreAlloc;
- default_heap.h_free.h_next = NULL;
+ default_heap.h_free.h_u.next = (struct heap_header *)NULL;
default_heap.h_free.h_size = 0;
#if CH_USE_MUTEXES
chMtxInit(&default_heap.h_mtx);
@@ -70,17 +70,17 @@ void heap_init(void) {
* @param[in] size heap size
*
* @note Both the heap buffer base and the heap size must be aligned to
- * the @p align_t type size.
+ * the @p align_t type size.
*/
void chHeapInit(MemoryHeap *heapp, void *buf, size_t size) {
struct heap_header *hp;
chDbgCheck(MEM_IS_ALIGNED(buf) && MEM_IS_ALIGNED(size), "chHeapInit");
- heapp->h_provider = NULL;
- heapp->h_free.h_next = hp = buf;
+ heapp->h_provider = (memgetfunc_t)NULL;
+ heapp->h_free.h_u.next = hp = buf;
heapp->h_free.h_size = 0;
- hp->h_next = NULL;
+ hp->h_u.next = NULL;
hp->h_size = size - sizeof(struct heap_header);
#if CH_USE_MUTEXES
chMtxInit(&heapp->h_mtx);
@@ -113,8 +113,8 @@ void *chHeapAlloc(MemoryHeap *heapp, size_t size) {
qp = &heapp->h_free;
H_LOCK(heapp);
- while (qp->h_next != NULL) {
- hp = qp->h_next;
+ while (qp->h_u.next != NULL) {
+ hp = qp->h_u.next;
if (hp->h_size >= size) {
if (hp->h_size < size + sizeof(struct heap_header)) {
/*
@@ -122,19 +122,19 @@ void *chHeapAlloc(MemoryHeap *heapp, size_t size) {
* requested size because the fragment would be too small to be
* useful.
*/
- qp->h_next = hp->h_next;
+ qp->h_u.next = hp->h_u.next;
}
else {
/*
* Block bigger enough, must split it.
*/
fp = (void *)((uint8_t *)(hp) + sizeof(struct heap_header) + size);
- fp->h_next = hp->h_next;
+ fp->h_u.next = hp->h_u.next;
fp->h_size = hp->h_size - sizeof(struct heap_header) - size;
- qp->h_next = fp;
+ qp->h_u.next = fp;
hp->h_size = size;
}
- hp->h_heap = heapp;
+ hp->h_u.heap = heapp;
H_UNLOCK(heapp);
return (void *)(hp + 1);
@@ -150,7 +150,7 @@ void *chHeapAlloc(MemoryHeap *heapp, size_t size) {
if (heapp->h_provider) {
hp = heapp->h_provider(size + sizeof(struct heap_header));
if (hp != NULL) {
- hp->h_heap = heapp;
+ hp->h_u.heap = heapp;
hp->h_size = size;
hp++;
return (void *)hp;
@@ -175,7 +175,7 @@ void chHeapFree(void *p) {
chDbgCheck(p != NULL, "chHeapFree");
hp = (struct heap_header *)p - 1;
- heapp = hp->h_heap;
+ heapp = hp->h_u.heap;
qp = &heapp->h_free;
H_LOCK(heapp);
@@ -185,32 +185,32 @@ void chHeapFree(void *p) {
"within free block");
if (((qp == &heapp->h_free) || (hp > qp)) &&
- ((qp->h_next == NULL) || (hp < qp->h_next))) {
+ ((qp->h_u.next == NULL) || (hp < qp->h_u.next))) {
/*
* Insertion after qp.
*/
- hp->h_next = qp->h_next;
- qp->h_next = hp;
+ hp->h_u.next = qp->h_u.next;
+ qp->h_u.next = hp;
/*
* Verifies if the newly inserted block should be merged.
*/
- if (LIMIT(hp) == hp->h_next) {
+ if (LIMIT(hp) == hp->h_u.next) {
/*
* Merge with the next block.
*/
- hp->h_size += hp->h_next->h_size + sizeof(struct heap_header);
- hp->h_next = hp->h_next->h_next;
+ hp->h_size += hp->h_u.next->h_size + sizeof(struct heap_header);
+ hp->h_u.next = hp->h_u.next->h_u.next;
}
if ((LIMIT(qp) == hp)) {
/*
* Merge with the previous block.
*/
qp->h_size += hp->h_size + sizeof(struct heap_header);
- qp->h_next = hp->h_next;
+ qp->h_u.next = hp->h_u.next;
}
break;
}
- qp = qp->h_next;
+ qp = qp->h_u.next;
}
H_UNLOCK(heapp);
@@ -240,8 +240,8 @@ size_t chHeapStatus(MemoryHeap *heapp, size_t *sizep) {
H_LOCK(heapp);
sz = 0;
- for (n = 0, qp = &heapp->h_free; qp->h_next; n++, qp = qp->h_next)
- sz += qp->h_next->h_size;
+ for (n = 0, qp = &heapp->h_free; qp->h_u.next; n++, qp = qp->h_u.next)
+ sz += qp->h_u.next->h_size;
if (sizep)
*sizep = sz;