From 569e0994c67427e689fbac95215bd1569dcd816d Mon Sep 17 00:00:00 2001 From: Stathis Kamperis Date: Mon, 15 Oct 2007 10:18:00 +0300 Subject: [PATCH] Put the stat functions in a separate .c files --- malloc/mpool.c | 72 ------------------------------------------------------- malloc/mpool.h | 14 +++++------ malloc/mstat.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ malloc/mstat.h | 11 +++++++++ malloc/test.c | 1 + 5 files changed, 93 insertions(+), 80 deletions(-) create mode 100644 malloc/mstat.c create mode 100644 malloc/mstat.h diff --git a/malloc/mpool.c b/malloc/mpool.c index ebc339a..297af88 100644 --- a/malloc/mpool.c +++ b/malloc/mpool.c @@ -405,75 +405,3 @@ void mpool_printblks(const mpool_t *mpool) } } -void mpool_stat_get_nodes(const mpool_t *mpool, size_t *avail, size_t *used) -{ - const blkhead_t *phead; - const blknode_t *pnode; - unsigned int i; - - *avail = 0; - *used = 0; - for (i = 0; i < mpool->nblocks; i++) { - phead = &mpool->blktable[i]; - LIST_FOREACH(pnode, phead, next_chunk) { - /*if (pnode->flags & MP_NODE_AVAIL)*/ - if (MPOOL_IS_AVAIL(pnode)) - (*avail)++; - else - (*used)++; - } - } -} - -void mpool_stat_get_bytes(const mpool_t *mpool, size_t *avail, size_t *used) -{ - const blkhead_t *phead; - const blknode_t *pnode; - unsigned int i; - - *avail = 0; - *used = 0; - for (i = 0; i < mpool->nblocks; i++) { - phead = &mpool->blktable[i]; - LIST_FOREACH(pnode, phead, next_chunk) { - /*if (pnode->flags & MP_NODE_AVAIL)*/ - if (MPOOL_IS_AVAIL(pnode)) - *avail += 1 << pnode->logsize; - else - *used += 1 << pnode->logsize; - } - } -} - -size_t mpool_stat_get_blocks(const mpool_t *mpool) -{ - return mpool->nblocks; -} - -size_t mpool_stat_get_block_length(const mpool_t *mpool, size_t pos) -{ - const blknode_t *pnode; - size_t length; - - if (pos >= mpool->nblocks) - return 0; /* FIXME: Better error handling */ - - length = 0; - LIST_FOREACH(pnode, &mpool->blktable[pos], next_chunk) - length++; - - return length; -} - -#ifdef MP_STATS -size_t mpool_stat_get_splits(const mpool_t *mpool) -{ - return mpool->nsplits; -} - -size_t mpool_stat_get_merges(const mpool_t *mpool) -{ - return mpool->nmerges; -} -#endif - diff --git a/malloc/mpool.h b/malloc/mpool.h index 5ccd1cb..c61decd 100644 --- a/malloc/mpool.h +++ b/malloc/mpool.h @@ -1,3 +1,7 @@ +#ifndef MPOOL_H_ +#define MPOOL_H_ + +#include #include /*#define MP_DEBUG*/ @@ -58,11 +62,5 @@ void mpool_free(mpool_t *mpool, void *ptr); void mpool_destroy(mpool_t *mpool); void mpool_printblks(const mpool_t *mpool); -void mpool_stat_get_nodes(const mpool_t *mpool, size_t *avail, size_t *used); -void mpool_stat_get_bytes(const mpool_t *mpool, size_t *avail, size_t *used); -size_t mpool_stat_get_blocks(const mpool_t *mpool); -size_t mpool_stat_get_block_length(const mpool_t *mpool, size_t pos); -#ifdef MP_STATS -size_t mpool_stat_get_splits(const mpool_t *mpool); -size_t mpool_stat_get_merges(const mpool_t *mpool); -#endif + +#endif /* MPOOL_H_ */ diff --git a/malloc/mstat.c b/malloc/mstat.c new file mode 100644 index 0000000..7b7bb0b --- /dev/null +++ b/malloc/mstat.c @@ -0,0 +1,75 @@ +#include "mpool.h" +#include "mstat.h" + +void mpool_stat_get_nodes(const mpool_t *mpool, size_t *avail, size_t *used) +{ + const blkhead_t *phead; + const blknode_t *pnode; + unsigned int i; + + *avail = 0; + *used = 0; + for (i = 0; i < mpool->nblocks; i++) { + phead = &mpool->blktable[i]; + LIST_FOREACH(pnode, phead, next_chunk) { + /*if (pnode->flags & MP_NODE_AVAIL)*/ + if (MPOOL_IS_AVAIL(pnode)) + (*avail)++; + else + (*used)++; + } + } +} + +void mpool_stat_get_bytes(const mpool_t *mpool, size_t *avail, size_t *used) +{ + const blkhead_t *phead; + const blknode_t *pnode; + unsigned int i; + + *avail = 0; + *used = 0; + for (i = 0; i < mpool->nblocks; i++) { + phead = &mpool->blktable[i]; + LIST_FOREACH(pnode, phead, next_chunk) { + /*if (pnode->flags & MP_NODE_AVAIL)*/ + if (MPOOL_IS_AVAIL(pnode)) + *avail += 1 << pnode->logsize; + else + *used += 1 << pnode->logsize; + } + } +} + +size_t mpool_stat_get_blocks(const mpool_t *mpool) +{ + return mpool->nblocks; +} + +size_t mpool_stat_get_block_length(const mpool_t *mpool, size_t pos) +{ + const blknode_t *pnode; + size_t length; + + if (pos >= mpool->nblocks) + return 0; /* FIXME: Better error handling */ + + length = 0; + LIST_FOREACH(pnode, &mpool->blktable[pos], next_chunk) + length++; + + return length; +} + +#ifdef MP_STATS +size_t mpool_stat_get_splits(const mpool_t *mpool) +{ + return mpool->nsplits; +} + +size_t mpool_stat_get_merges(const mpool_t *mpool) +{ + return mpool->nmerges; +} +#endif + diff --git a/malloc/mstat.h b/malloc/mstat.h new file mode 100644 index 0000000..b270aeb --- /dev/null +++ b/malloc/mstat.h @@ -0,0 +1,11 @@ +#include "mpool.h" + +void mpool_stat_get_nodes(const mpool_t *mpool, size_t *avail, size_t *used); +void mpool_stat_get_bytes(const mpool_t *mpool, size_t *avail, size_t *used); +size_t mpool_stat_get_blocks(const mpool_t *mpool); +size_t mpool_stat_get_block_length(const mpool_t *mpool, size_t pos); +#ifdef MP_STATS +size_t mpool_stat_get_splits(const mpool_t *mpool); +size_t mpool_stat_get_merges(const mpool_t *mpool); +#endif + diff --git a/malloc/test.c b/malloc/test.c index 14ef4b7..37bb2f2 100644 --- a/malloc/test.c +++ b/malloc/test.c @@ -5,6 +5,7 @@ #include #include "mpool.h" +#include "mstat.h" #define MAX_EPOCHS 20000 /* Maximum number of epochs of simulation */ #define MAX_LIFETIME 1000 /* Maximum lifetime of a reserved block */ -- 2.11.4.GIT