diff --git a/src/fast_mblock.c b/src/fast_mblock.c index 488a08484136d8e81e29431627c67fe97d2494bf..b1e33dcc56e808f6ce925a634a37773df452c4f8 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 496c9c77cfc0c1a5b26ba93ce689a3df08f32f5f..635b6695aeb10a85ab5773e6d60535a4f83f9939 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 }