diff --git a/HISTORY b/HISTORY index e915ad3..144f5d2 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.54 2021-09-13 +Version 1.54 2021-09-22 * fast_allocator.[hc]: correct reclaim_interval logic * shared_func.[hc]: add functions getFileContentEx1 and getFileContent1 * fc_queue.[hc]: add function fc_queue_timedpeek diff --git a/src/fast_mblock.h b/src/fast_mblock.h index fac9720..d3f220a 100644 --- a/src/fast_mblock.h +++ b/src/fast_mblock.h @@ -24,7 +24,6 @@ #include #include "common_define.h" #include "fc_memory.h" -#include "chain.h" #include "logger.h" #define FAST_MBLOCK_NAME_SIZE 32 @@ -304,6 +303,14 @@ static inline int fast_mblock_free_object(struct fast_mblock_man *mblock, return fast_mblock_free(mblock, fast_mblock_to_node_ptr(object)); } +/** +free objects (put objects to the mblock) +parameters: + mblock: the mblock pointer + objs: the object array to free + count: the count of the object array +return none +*/ void fast_mblock_free_objects(struct fast_mblock_man *mblock, void **objs, const int count); diff --git a/src/fc_queue.c b/src/fc_queue.c index 00c1eac..a5a307d 100644 --- a/src/fc_queue.c +++ b/src/fc_queue.c @@ -206,6 +206,26 @@ void *fc_queue_timedpeek(struct fc_queue *queue, return data; } +int fc_queue_alloc_chain(struct fc_queue *queue, struct fast_mblock_man + *mblock, const int count, struct fc_queue_info *chain) +{ + struct fast_mblock_node *node; + + if ((node=fast_mblock_batch_alloc(mblock, count)) == NULL) { + chain->head = chain->tail = NULL; + return ENOMEM; + } + + chain->head = chain->tail = node->data; + while ((node=node->next) != NULL) { + FC_QUEUE_NEXT_PTR(queue, chain->tail) = node->data; + chain->tail = node->data; + } + FC_QUEUE_NEXT_PTR(queue, chain->tail) = NULL; + + return 0; +} + int fc_queue_free_chain(struct fc_queue *queue, struct fast_mblock_man *mblock, struct fc_queue_info *qinfo) { diff --git a/src/fc_queue.h b/src/fc_queue.h index b0bdee4..ee588ec 100644 --- a/src/fc_queue.h +++ b/src/fc_queue.h @@ -173,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_alloc_chain(struct fc_queue *queue, struct fast_mblock_man + *mblock, const int count, struct fc_queue_info *chain); + int fc_queue_free_chain(struct fc_queue *queue, struct fast_mblock_man *mblock, struct fc_queue_info *qinfo); diff --git a/src/sorted_queue.c b/src/sorted_queue.c index d29ff64..cf72d69 100644 --- a/src/sorted_queue.c +++ b/src/sorted_queue.c @@ -75,7 +75,9 @@ void *sorted_queue_pop_ex(struct sorted_queue *sq, PTHREAD_MUTEX_LOCK(&sq->queue.lc_pair.lock); do { - if (sq->queue.head == NULL) { + if (sq->queue.head == NULL || sq->compare_func( + sq->queue.head, less_equal) > 0) + { if (!blocked) { data = NULL; break;