struct fast_mblock_node *fast_mblock_alloc(struct fast_mblock_man *mblock) { struct fast_mblock_node *pNode; int result; if (mblock->need_lock && (result=pthread_mutex_lock(&(mblock->lock))) != 0) { /*logError("file: "__FILE__", line: %d, " \ "call pthread_mutex_lock fail, " \ "errno: %d, error info: %s", \ __LINE__, result, STRERROR(result));*/ return NULL; } if (mblock->free_chain_head != NULL) { pNode = mblock->free_chain_head; mblock->free_chain_head = pNode->next; mblock->info.element_used_count++; fast_mblock_ref_counter_inc(mblock, pNode); } else { if (mblock->delay_free_chain.head != NULL && mblock->delay_free_chain.head->recycle_timestamp <= get_current_time()) { pNode = mblock->delay_free_chain.head; mblock->delay_free_chain.head = pNode->next; if (mblock->delay_free_chain.tail == pNode) { mblock->delay_free_chain.tail = NULL; } } else if ((result=fast_mblock_prealloc(mblock)) == 0) { pNode = mblock->free_chain_head; mblock->free_chain_head = pNode->next; mblock->info.element_used_count++; fast_mblock_ref_counter_inc(mblock, pNode); } else { pNode = NULL; } } if (mblock->need_lock && (result=pthread_mutex_unlock(&(mblock->lock))) != 0) { /*logError("file: "__FILE__", line: %d, " \ "call pthread_mutex_unlock fail, " \ "errno: %d, error info: %s", \ __LINE__, result, STRERROR(result));*/ } return pNode; }
struct fast_mblock_node *fast_mblock_alloc(struct fast_mblock_man *mblock) { struct fast_mblock_node *pNode; int result; if ((result=pthread_mutex_lock(&(mblock->lock))) != 0) { logError("file: "__FILE__", line: %d, " \ "call pthread_mutex_lock fail, " \ "errno: %d, error info: %s", \ __LINE__, result, STRERROR(result)); return NULL; } if (mblock->free_chain_head != NULL) { pNode = mblock->free_chain_head; mblock->free_chain_head = pNode->next; } else { if ((result=fast_mblock_prealloc(mblock)) == 0) { pNode = mblock->free_chain_head; mblock->free_chain_head = pNode->next; } else { pNode = NULL; } } if ((result=pthread_mutex_unlock(&(mblock->lock))) != 0) { logError("file: "__FILE__", line: %d, " \ "call pthread_mutex_unlock fail, " \ "errno: %d, error info: %s", \ __LINE__, result, STRERROR(result)); } return pNode; }