diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-01-24 09:04:55 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-01-24 09:04:55 +0000 |
commit | 86eb39129b8ac6ba74778c72261f2048c2da1114 (patch) | |
tree | 076701c638a3d332f175afedd0623d8af3417813 /os | |
parent | edc56330a91f1f646d8b78ead8a89c46a5d841e6 (diff) | |
download | ChibiOS-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')
-rw-r--r-- | os/kernel/include/heap.h | 6 | ||||
-rw-r--r-- | os/kernel/include/vt.h | 2 | ||||
-rw-r--r-- | os/kernel/src/chheap.c | 46 | ||||
-rw-r--r-- | os/kernel/src/chthreads.c | 8 | ||||
-rw-r--r-- | os/kernel/src/chvt.c | 2 |
5 files changed, 34 insertions, 30 deletions
diff --git a/os/kernel/include/heap.h b/os/kernel/include/heap.h index ab784479c..be95a41c5 100644 --- a/os/kernel/include/heap.h +++ b/os/kernel/include/heap.h @@ -47,9 +47,9 @@ typedef struct memory_heap MemoryHeap; */
struct heap_header {
union {
- struct heap_header *h_next; /**< @brief Next block in free list. */
- MemoryHeap *h_heap; /**< @brief Block owner heap. */
- };
+ struct heap_header *next; /**< @brief Next block in free list. */
+ MemoryHeap *heap; /**< @brief Block owner heap. */
+ } h_u; /**< @brief Overlapped fields. */
size_t h_size; /**< @brief Size of the memory block. */
};
diff --git a/os/kernel/include/vt.h b/os/kernel/include/vt.h index 20a64ec95..455545cc6 100644 --- a/os/kernel/include/vt.h +++ b/os/kernel/include/vt.h @@ -88,7 +88,7 @@ extern VTList vtlist; --vtlist.vt_next->vt_time; \
while (!(vtp = vtlist.vt_next)->vt_time) { \
vtfunc_t fn = vtp->vt_func; \
- vtp->vt_func = NULL; \
+ vtp->vt_func = (vtfunc_t)NULL; \
vtp->vt_next->vt_prev = (void *)&vtlist; \
(&vtlist)->vt_next = vtp->vt_next; \
fn(vtp->vt_par); \
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;
diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index e372a6e5c..6aab8f891 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -354,13 +354,17 @@ void chThdExit(msg_t msg) { */ msg_t chThdWait(Thread *tp) { msg_t msg; +#if CH_USE_DYNAMIC + tmode_t mode; +#endif chDbgCheck(tp != NULL, "chThdWait"); chSysLock(); chDbgAssert(tp != currp, "chThdWait(), #1", "waiting self"); - chDbgAssert(tp->p_waiting == NULL, "chThdWait(), #2", "some other thread waiting"); + chDbgAssert(tp->p_waiting == NULL, "chThdWait(), #2", + "some other thread waiting"); if (tp->p_state != THD_STATE_FINAL) { tp->p_waiting = currp; @@ -373,7 +377,7 @@ msg_t chThdWait(Thread *tp) { #else /* CH_USE_DYNAMIC */ /* Returning memory.*/ - tmode_t mode = tp->p_flags & THD_MEM_MODE_MASK; + mode = tp->p_flags & THD_MEM_MODE_MASK; chSysUnlock(); switch (mode) { diff --git a/os/kernel/src/chvt.c b/os/kernel/src/chvt.c index 60d0a789b..5acde49aa 100644 --- a/os/kernel/src/chvt.c +++ b/os/kernel/src/chvt.c @@ -93,7 +93,7 @@ void chVTResetI(VirtualTimer *vtp) { vtp->vt_next->vt_time += vtp->vt_time;
vtp->vt_prev->vt_next = vtp->vt_next;
vtp->vt_next->vt_prev = vtp->vt_prev;
- vtp->vt_func = NULL;
+ vtp->vt_func = (vtfunc_t)NULL;
}
/**
|