add function fc_queue_free_chain
parent
7614f789c8
commit
81950ac246
|
|
@ -864,6 +864,7 @@ void fast_mblock_free_objects(struct fast_mblock_man *mblock,
|
|||
void **obj;
|
||||
void **end;
|
||||
struct fast_mblock_node *previous;
|
||||
struct fast_mblock_node *current;
|
||||
struct fast_mblock_chain chain;
|
||||
|
||||
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]);
|
||||
end = objs + count;
|
||||
for (obj=objs+1; obj<end; obj++) {
|
||||
previous->next = *obj;
|
||||
previous = *obj;
|
||||
current = fast_mblock_to_node_ptr(*obj);
|
||||
previous->next = current;
|
||||
previous = current;
|
||||
}
|
||||
|
||||
previous->next = NULL;
|
||||
chain.tail = fast_mblock_to_node_ptr(previous);
|
||||
chain.tail = previous;
|
||||
fast_mblock_batch_free(mblock, &chain);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -263,23 +263,6 @@ return 0 for success, return none zero if fail
|
|||
int fast_mblock_batch_free(struct fast_mblock_man *mblock,
|
||||
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)
|
||||
parameters:
|
||||
|
|
|
|||
|
|
@ -205,3 +205,30 @@ void *fc_queue_timedpeek(struct fc_queue *queue,
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#define _FC_QUEUE_H
|
||||
|
||||
#include "common_define.h"
|
||||
#include "fast_mblock.h"
|
||||
|
||||
struct fc_queue_info
|
||||
{
|
||||
|
|
@ -172,6 +173,9 @@ void *fc_queue_timedpeek(struct fc_queue *queue,
|
|||
#define fc_queue_timedpeek_us(queue, timeout_us) \
|
||||
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
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -121,6 +121,12 @@ static inline void *sorted_queue_timedpeek(struct sorted_queue *sq,
|
|||
#define sorted_queue_timedpeek_us(sq, timeout_us) \
|
||||
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
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue