add function fc_queue_free_chain

pull/37/merge
YuQing 2021-09-11 18:40:26 +08:00
parent 7614f789c8
commit 81950ac246
5 changed files with 42 additions and 20 deletions

View File

@ -864,6 +864,7 @@ void fast_mblock_free_objects(struct fast_mblock_man *mblock,
void **obj; void **obj;
void **end; void **end;
struct fast_mblock_node *previous; struct fast_mblock_node *previous;
struct fast_mblock_node *current;
struct fast_mblock_chain chain; struct fast_mblock_chain chain;
if (count == 0) { if (count == 0) {
@ -873,12 +874,13 @@ void fast_mblock_free_objects(struct fast_mblock_man *mblock,
chain.head = previous = fast_mblock_to_node_ptr(objs[0]); chain.head = previous = fast_mblock_to_node_ptr(objs[0]);
end = objs + count; end = objs + count;
for (obj=objs+1; obj<end; obj++) { for (obj=objs+1; obj<end; obj++) {
previous->next = *obj; current = fast_mblock_to_node_ptr(*obj);
previous = *obj; previous->next = current;
previous = current;
} }
previous->next = NULL; previous->next = NULL;
chain.tail = fast_mblock_to_node_ptr(previous); chain.tail = previous;
fast_mblock_batch_free(mblock, &chain); fast_mblock_batch_free(mblock, &chain);
} }

View File

@ -263,23 +263,6 @@ return 0 for success, return none zero if fail
int fast_mblock_batch_free(struct fast_mblock_man *mblock, int fast_mblock_batch_free(struct fast_mblock_man *mblock,
struct fast_mblock_chain *chain); struct fast_mblock_chain *chain);
/**
batch free objects
parameters:
mblock: the mblock pointer
head: the head object
tail: the tail object
return 0 for success, return none zero if fail
*/
static inline int fast_mblock_batch_free_objs(struct fast_mblock_man
*mblock, void *head, void *tail)
{
struct fast_mblock_chain chain;
chain.head = fast_mblock_to_node_ptr(head);
chain.tail = fast_mblock_to_node_ptr(tail);
return fast_mblock_batch_free(mblock, &chain);
}
/** /**
delay free a node (put a node to the mblock) delay free a node (put a node to the mblock)
parameters: parameters:

View File

@ -205,3 +205,30 @@ void *fc_queue_timedpeek(struct fc_queue *queue,
return data; return data;
} }
int fc_queue_free_chain(struct fc_queue *queue, struct fast_mblock_man
*mblock, struct fc_queue_info *qinfo)
{
struct fast_mblock_node *previous;
struct fast_mblock_node *current;
struct fast_mblock_chain chain;
void *data;
if (qinfo->head == NULL) {
return 0;
}
chain.head = previous = fast_mblock_to_node_ptr(qinfo->head);
data = FC_QUEUE_NEXT_PTR(queue, qinfo->head);
while (data != NULL) {
current = fast_mblock_to_node_ptr(data);
previous->next = current;
previous = current;
data = FC_QUEUE_NEXT_PTR(queue, data);
}
previous->next = NULL;
chain.tail = previous;
return fast_mblock_batch_free(mblock, &chain);
}

View File

@ -19,6 +19,7 @@
#define _FC_QUEUE_H #define _FC_QUEUE_H
#include "common_define.h" #include "common_define.h"
#include "fast_mblock.h"
struct fc_queue_info struct fc_queue_info
{ {
@ -172,6 +173,9 @@ void *fc_queue_timedpeek(struct fc_queue *queue,
#define fc_queue_timedpeek_us(queue, timeout_us) \ #define fc_queue_timedpeek_us(queue, timeout_us) \
fc_queue_timedpeek(queue, timeout_us, FC_TIME_UNIT_USECOND) fc_queue_timedpeek(queue, timeout_us, FC_TIME_UNIT_USECOND)
int fc_queue_free_chain(struct fc_queue *queue, struct fast_mblock_man
*mblock, struct fc_queue_info *qinfo);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -121,6 +121,12 @@ static inline void *sorted_queue_timedpeek(struct sorted_queue *sq,
#define sorted_queue_timedpeek_us(sq, timeout_us) \ #define sorted_queue_timedpeek_us(sq, timeout_us) \
sorted_queue_timedpeek(sq, timeout_us, FC_TIME_UNIT_USECOND) sorted_queue_timedpeek(sq, timeout_us, FC_TIME_UNIT_USECOND)
static inline int sorted_queue_free_chain(struct sorted_queue *sq,
struct fast_mblock_man *mblock, struct fc_queue_info *qinfo)
{
return fc_queue_free_chain(&sq->queue, mblock, qinfo);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif