diff --git a/HISTORY b/HISTORY index b699faa..643a404 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ Version 1.52 2021-06-01 * process_stop more gracefully (kill -9 on timeout) + * add function fc_queue_pop_to_queue_ex Version 1.51 2021-05-27 * fast_mblock.[hc]: support batch alloc and batch free diff --git a/src/fc_queue.c b/src/fc_queue.c index 8c4c892..784f6ab 100644 --- a/src/fc_queue.c +++ b/src/fc_queue.c @@ -155,10 +155,16 @@ void fc_queue_push_queue_to_tail_ex(struct fc_queue *queue, PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); } -void fc_queue_pop_to_queue(struct fc_queue *queue, - struct fc_queue_info *qinfo) +void fc_queue_pop_to_queue_ex(struct fc_queue *queue, + struct fc_queue_info *qinfo, const bool blocked) { PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + if (queue->head == NULL) { + if (blocked) { + pthread_cond_wait(&queue->lc_pair.cond, &queue->lc_pair.lock); + } + } + if (queue->head != NULL) { qinfo->head = queue->head; qinfo->tail = queue->tail; diff --git a/src/fc_queue.h b/src/fc_queue.h index 3be5e7e..0df3675 100644 --- a/src/fc_queue.h +++ b/src/fc_queue.h @@ -129,8 +129,14 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked); #define fc_queue_pop_all(queue) fc_queue_pop_all_ex(queue, true) #define fc_queue_try_pop_all(queue) fc_queue_pop_all_ex(queue, false) -void fc_queue_pop_to_queue(struct fc_queue *queue, - struct fc_queue_info *qinfo); +void fc_queue_pop_to_queue_ex(struct fc_queue *queue, + struct fc_queue_info *qinfo, const bool blocked); + +#define fc_queue_pop_to_queue(queue, qinfo) \ + fc_queue_pop_to_queue_ex(queue, qinfo, true) + +#define fc_queue_try_pop_to_queue(queue, qinfo) \ + fc_queue_pop_to_queue_ex(queue, qinfo, false) static inline bool fc_queue_empty(struct fc_queue *queue) { diff --git a/src/sched_thread.c b/src/sched_thread.c index cfd291e..60f2e30 100644 --- a/src/sched_thread.c +++ b/src/sched_thread.c @@ -840,7 +840,7 @@ static void sched_deal_task_queue(ScheduleContext *pContext) FastDelayTask *task; struct fc_queue_info qinfo; - fc_queue_pop_to_queue(&pContext->delay_queue, &qinfo); + fc_queue_try_pop_to_queue(&pContext->delay_queue, &qinfo); task = qinfo.head; while (task != NULL) {