diff --git a/HISTORY b/HISTORY index 0df82e3..0832899 100644 --- a/HISTORY +++ b/HISTORY @@ -1,11 +1,12 @@ -Version 1.49 2021-03-28 +Version 1.49 2021-04-07 * add macros: FC_ABS and FC_NEGATIVE * uniq_skiplist.c: add uniq_skiplist_pair struct and init function * add functions: fc_mkdirs and str_replace * add FilenameString type and macro * add functions: fc_string_case_compare, fc_string_case_equal etc. - * add functions: fc_check_filename_ex + * add function: fc_check_filename_ex + * add functions: fc_queue_push_queue_to_tail etc. Version 1.48 2021-02-01 * fast_buffer.[hc]: add function fast_buffer_append_binary diff --git a/src/fc_queue.c b/src/fc_queue.c index 5e27bf7..8c4c892 100644 --- a/src/fc_queue.c +++ b/src/fc_queue.c @@ -135,6 +135,26 @@ void fc_queue_push_queue_to_head_ex(struct fc_queue *queue, PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); } +void fc_queue_push_queue_to_tail_ex(struct fc_queue *queue, + struct fc_queue_info *qinfo, bool *notify) +{ + if (qinfo->head == NULL) { + *notify = false; + return; + } + + PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + if (queue->head == NULL) { + queue->head = qinfo->head; + *notify = true; + } else { + FC_QUEUE_NEXT_PTR(queue, queue->tail) = qinfo->head; + *notify = false; + } + queue->tail = qinfo->tail; + PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); +} + void fc_queue_pop_to_queue(struct fc_queue *queue, struct fc_queue_info *qinfo) { diff --git a/src/fc_queue.h b/src/fc_queue.h index e5ce71e..3be5e7e 100644 --- a/src/fc_queue.h +++ b/src/fc_queue.h @@ -93,6 +93,34 @@ static inline void fc_queue_push_queue_to_head(struct fc_queue *queue, } } +static inline void fc_queue_push_queue_to_head_silence( + struct fc_queue *queue, struct fc_queue_info *qinfo) +{ + bool notify; + fc_queue_push_queue_to_head_ex(queue, qinfo, ¬ify); +} + +void fc_queue_push_queue_to_tail_ex(struct fc_queue *queue, + struct fc_queue_info *qinfo, bool *notify); + +static inline void fc_queue_push_queue_to_tail(struct fc_queue *queue, + struct fc_queue_info *qinfo) +{ + bool notify; + + fc_queue_push_queue_to_tail_ex(queue, qinfo, ¬ify); + if (notify) { + pthread_cond_signal(&(queue->lc_pair.cond)); + } +} + +static inline void fc_queue_push_queue_to_tail_silence( + struct fc_queue *queue, struct fc_queue_info *qinfo) +{ + bool notify; + fc_queue_push_queue_to_tail_ex(queue, qinfo, ¬ify); +} + void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked); #define fc_queue_pop(queue) fc_queue_pop_ex(queue, true) #define fc_queue_try_pop(queue) fc_queue_pop_ex(queue, false)