mblock add total_count

pull/1/head
yuqing 2014-06-27 10:10:18 +08:00
parent c8ecbb8c31
commit 16bda0a1ab
2 changed files with 7 additions and 2 deletions

View File

@ -44,6 +44,7 @@ int fast_mblock_init(struct fast_mblock_man *mblock, const int element_size, \
mblock->malloc_chain_head = NULL; mblock->malloc_chain_head = NULL;
mblock->free_chain_head = NULL; mblock->free_chain_head = NULL;
mblock->total_count = 0;
return 0; return 0;
} }
@ -90,6 +91,7 @@ static int fast_mblock_prealloc(struct fast_mblock_man *mblock)
pMallocNode->next = mblock->malloc_chain_head; pMallocNode->next = mblock->malloc_chain_head;
mblock->malloc_chain_head = pMallocNode; mblock->malloc_chain_head = pMallocNode;
mblock->total_count += mblock->alloc_elements_once;
return 0; return 0;
} }
@ -189,7 +191,7 @@ int fast_mblock_free(struct fast_mblock_man *mblock, \
return 0; 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; struct fast_mblock_node *pNode;
int count; int count;

View File

@ -37,6 +37,7 @@ struct fast_mblock_man
struct fast_mblock_malloc *malloc_chain_head; //malloc chain to be freed struct fast_mblock_malloc *malloc_chain_head; //malloc chain to be freed
int element_size; //element size int element_size; //element size
int alloc_elements_once; //alloc elements once 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 pthread_mutex_t lock; //the lock for read / write free node chain
}; };
@ -90,7 +91,9 @@ parameters:
mblock: the mblock pointer mblock: the mblock pointer
return the free node count of the mblock, return -1 if fail 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 #ifdef __cplusplus
} }