function fast_mblock_batch_alloc changed
parent
af68bf5d6a
commit
0381982ac2
4
HISTORY
4
HISTORY
|
|
@ -1,4 +1,8 @@
|
||||||
|
|
||||||
|
Version 1.55 2022-01-09
|
||||||
|
* fastcommon php extension adapt to php 8
|
||||||
|
* function fast_mblock_batch_alloc changed
|
||||||
|
|
||||||
Version 1.54 2021-12-23
|
Version 1.54 2021-12-23
|
||||||
* fast_allocator.[hc]: correct reclaim_interval logic
|
* fast_allocator.[hc]: correct reclaim_interval logic
|
||||||
* shared_func.[hc]: add functions getFileContentEx1 and getFileContent1
|
* shared_func.[hc]: add functions getFileContentEx1 and getFileContent1
|
||||||
|
|
|
||||||
|
|
@ -838,10 +838,9 @@ static inline void batch_free(struct fast_mblock_man *mblock,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fast_mblock_node *fast_mblock_batch_alloc(
|
int fast_mblock_batch_alloc(struct fast_mblock_man *mblock,
|
||||||
struct fast_mblock_man *mblock, const int count)
|
const int count, struct fast_mblock_chain *chain)
|
||||||
{
|
{
|
||||||
struct fast_mblock_chain chain;
|
|
||||||
struct fast_mblock_node *pNode;
|
struct fast_mblock_node *pNode;
|
||||||
int i;
|
int i;
|
||||||
int result;
|
int result;
|
||||||
|
|
@ -853,28 +852,31 @@ struct fast_mblock_node *fast_mblock_batch_alloc(
|
||||||
"call pthread_mutex_lock fail, "
|
"call pthread_mutex_lock fail, "
|
||||||
"errno: %d, error info: %s",
|
"errno: %d, error info: %s",
|
||||||
__LINE__, result, STRERROR(result));
|
__LINE__, result, STRERROR(result));
|
||||||
return NULL;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((chain.head=alloc_node(mblock)) != NULL)
|
if ((chain->head=alloc_node(mblock)) != NULL) {
|
||||||
{
|
chain->tail = chain->head;
|
||||||
chain.tail = chain.head;
|
for (i=1; i<count; i++) {
|
||||||
for (i=1; i<count; i++)
|
if ((pNode=alloc_node(mblock)) == NULL) {
|
||||||
{
|
|
||||||
if ((pNode=alloc_node(mblock)) == NULL)
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
chain.tail->next = pNode;
|
chain->tail->next = pNode;
|
||||||
chain.tail = pNode;
|
chain->tail = pNode;
|
||||||
}
|
}
|
||||||
chain.tail->next = NULL;
|
chain->tail->next = NULL;
|
||||||
|
|
||||||
if (i != count) { //fail
|
if (i == count) {
|
||||||
batch_free(mblock, &chain);
|
result = 0;
|
||||||
chain.head = NULL;
|
} else { //fail
|
||||||
|
batch_free(mblock, chain);
|
||||||
|
chain->head = chain->tail = NULL;
|
||||||
|
result = ENOMEM;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
chain->head = chain->tail = NULL;
|
||||||
|
result = ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mblock->need_lock && (result=pthread_mutex_unlock(
|
if (mblock->need_lock && (result=pthread_mutex_unlock(
|
||||||
|
|
@ -886,7 +888,7 @@ struct fast_mblock_node *fast_mblock_batch_alloc(
|
||||||
__LINE__, result, STRERROR(result));
|
__LINE__, result, STRERROR(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
return chain.head;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fast_mblock_batch_free(struct fast_mblock_man *mblock,
|
int fast_mblock_batch_free(struct fast_mblock_man *mblock,
|
||||||
|
|
|
||||||
|
|
@ -255,6 +255,17 @@ return 0 for success, return none zero if fail
|
||||||
int fast_mblock_free(struct fast_mblock_man *mblock,
|
int fast_mblock_free(struct fast_mblock_man *mblock,
|
||||||
struct fast_mblock_node *pNode);
|
struct fast_mblock_node *pNode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
batch alloc nodes from the mblock
|
||||||
|
parameters:
|
||||||
|
mblock: the mblock pointer
|
||||||
|
count: alloc count
|
||||||
|
chain: return the mblock node chain
|
||||||
|
return 0 for success, return none zero if fail
|
||||||
|
*/
|
||||||
|
int fast_mblock_batch_alloc(struct fast_mblock_man *mblock,
|
||||||
|
const int count, struct fast_mblock_chain *chain);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
batch alloc nodes from the mblock
|
batch alloc nodes from the mblock
|
||||||
parameters:
|
parameters:
|
||||||
|
|
@ -262,8 +273,16 @@ parameters:
|
||||||
count: alloc count
|
count: alloc count
|
||||||
return the alloced node head, return NULL if fail
|
return the alloced node head, return NULL if fail
|
||||||
*/
|
*/
|
||||||
struct fast_mblock_node *fast_mblock_batch_alloc(
|
static inline struct fast_mblock_node *fast_mblock_batch_alloc1(
|
||||||
struct fast_mblock_man *mblock, const int count);
|
struct fast_mblock_man *mblock, const int count)
|
||||||
|
{
|
||||||
|
struct fast_mblock_chain chain;
|
||||||
|
if (fast_mblock_batch_alloc(mblock, count, &chain) == 0) {
|
||||||
|
return chain.head;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
batch free nodes
|
batch free nodes
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ int fc_queue_alloc_chain(struct fc_queue *queue, struct fast_mblock_man
|
||||||
{
|
{
|
||||||
struct fast_mblock_node *node;
|
struct fast_mblock_node *node;
|
||||||
|
|
||||||
if ((node=fast_mblock_batch_alloc(mblock, count)) == NULL) {
|
if ((node=fast_mblock_batch_alloc1(mblock, count)) == NULL) {
|
||||||
chain->head = chain->tail = NULL;
|
chain->head = chain->tail = NULL;
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue