From 16bda0a1abcfdbfdc3436d1f669e0f20b4a03873 Mon Sep 17 00:00:00 2001 From: yuqing Date: Fri, 27 Jun 2014 10:10:18 +0800 Subject: [PATCH] mblock add total_count --- src/fast_mblock.c | 4 +++- src/fast_mblock.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/fast_mblock.c b/src/fast_mblock.c index 488a084..b1e33dc 100644 --- a/src/fast_mblock.c +++ b/src/fast_mblock.c @@ -44,6 +44,7 @@ int fast_mblock_init(struct fast_mblock_man *mblock, const int element_size, \ mblock->malloc_chain_head = NULL; mblock->free_chain_head = NULL; + mblock->total_count = 0; return 0; } @@ -90,6 +91,7 @@ static int fast_mblock_prealloc(struct fast_mblock_man *mblock) pMallocNode->next = mblock->malloc_chain_head; mblock->malloc_chain_head = pMallocNode; + mblock->total_count += mblock->alloc_elements_once; return 0; } @@ -189,7 +191,7 @@ int fast_mblock_free(struct fast_mblock_man *mblock, \ return 0; } -int fast_mblock_count(struct fast_mblock_man *mblock) +int fast_mblock_free_count(struct fast_mblock_man *mblock) { struct fast_mblock_node *pNode; int count; diff --git a/src/fast_mblock.h b/src/fast_mblock.h index 496c9c7..635b669 100644 --- a/src/fast_mblock.h +++ b/src/fast_mblock.h @@ -37,6 +37,7 @@ struct fast_mblock_man struct fast_mblock_malloc *malloc_chain_head; //malloc chain to be freed int element_size; //element size int alloc_elements_once; //alloc elements once + int total_count; //total element count pthread_mutex_t lock; //the lock for read / write free node chain }; @@ -90,7 +91,9 @@ parameters: mblock: the mblock pointer return the free node count of the mblock, return -1 if fail */ -int fast_mblock_count(struct fast_mblock_man *mblock); +int fast_mblock_free_count(struct fast_mblock_man *mblock); + +#define fast_mblock_total_count(mblock) (mblock)->total_count #ifdef __cplusplus } -- GitLab