From f1691b7480f8d78325e9ef761e38dee217d96392 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Mon, 27 Mar 2023 16:18:32 +0800 Subject: [PATCH] lc_pair in struct fc_queue change to lcp --- HISTORY | 3 ++- src/fc_queue.c | 46 +++++++++++++++++++++++----------------------- src/fc_queue.h | 20 ++++++++++---------- src/sorted_queue.c | 20 ++++++++++---------- src/sorted_queue.h | 2 +- 5 files changed, 46 insertions(+), 45 deletions(-) diff --git a/HISTORY b/HISTORY index 44463d2..4517a15 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -Version 1.66 2023-02-12 +Version 1.66 2023-03-27 * struct fast_task_info add field: notify_next for nio notify queue + * lc_pair in struct fc_queue change to lcp Version 1.65 2023-01-09 * locked_list.h: add functions locked_list_move and locked_list_move_tail diff --git a/src/fc_queue.c b/src/fc_queue.c index 74d7837..c8f30c4 100644 --- a/src/fc_queue.c +++ b/src/fc_queue.c @@ -22,7 +22,7 @@ int fc_queue_init(struct fc_queue *queue, const int next_ptr_offset) { int result; - if ((result=init_pthread_lock_cond_pair(&queue->lc_pair)) != 0) + if ((result=init_pthread_lock_cond_pair(&queue->lcp)) != 0) { return result; } @@ -35,12 +35,12 @@ int fc_queue_init(struct fc_queue *queue, const int next_ptr_offset) void fc_queue_destroy(struct fc_queue *queue) { - destroy_pthread_lock_cond_pair(&queue->lc_pair); + destroy_pthread_lock_cond_pair(&queue->lcp); } void fc_queue_push_ex(struct fc_queue *queue, void *data, bool *notify) { - PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_LOCK(&queue->lcp.lock); FC_QUEUE_NEXT_PTR(queue, data) = NULL; if (queue->tail == NULL) { queue->head = data; @@ -51,14 +51,14 @@ void fc_queue_push_ex(struct fc_queue *queue, void *data, bool *notify) } queue->tail = data; - PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock); } void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked) { void *data; - PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_LOCK(&queue->lcp.lock); do { data = queue->head; if (data == NULL) { @@ -66,7 +66,7 @@ void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked) break; } - pthread_cond_wait(&queue->lc_pair.cond, &queue->lc_pair.lock); + pthread_cond_wait(&queue->lcp.cond, &queue->lcp.lock); data = queue->head; } @@ -78,7 +78,7 @@ void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked) } } while (0); - PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock); return data; } @@ -86,7 +86,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked) { void *data; - PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_LOCK(&queue->lcp.lock); do { data = queue->head; if (data == NULL) { @@ -94,7 +94,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked) break; } - pthread_cond_wait(&queue->lc_pair.cond, &queue->lc_pair.lock); + pthread_cond_wait(&queue->lcp.cond, &queue->lcp.lock); data = queue->head; } @@ -103,7 +103,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked) } } while (0); - PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock); return data; } @@ -115,7 +115,7 @@ void fc_queue_push_queue_to_head_ex(struct fc_queue *queue, return; } - PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_LOCK(&queue->lcp.lock); FC_QUEUE_NEXT_PTR(queue, qinfo->tail) = queue->head; queue->head = qinfo->head; if (queue->tail == NULL) { @@ -124,7 +124,7 @@ void fc_queue_push_queue_to_head_ex(struct fc_queue *queue, } else { *notify = false; } - PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock); } void fc_queue_push_queue_to_tail_ex(struct fc_queue *queue, @@ -135,7 +135,7 @@ void fc_queue_push_queue_to_tail_ex(struct fc_queue *queue, return; } - PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_LOCK(&queue->lcp.lock); if (queue->head == NULL) { queue->head = qinfo->head; *notify = true; @@ -144,16 +144,16 @@ void fc_queue_push_queue_to_tail_ex(struct fc_queue *queue, *notify = false; } queue->tail = qinfo->tail; - PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock); } 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); + PTHREAD_MUTEX_LOCK(&queue->lcp.lock); if (queue->head == NULL) { if (blocked) { - pthread_cond_wait(&queue->lc_pair.cond, &queue->lc_pair.lock); + pthread_cond_wait(&queue->lcp.cond, &queue->lcp.lock); } } @@ -164,7 +164,7 @@ void fc_queue_pop_to_queue_ex(struct fc_queue *queue, } else { qinfo->head = qinfo->tail = NULL; } - PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock); } void *fc_queue_timedpop(struct fc_queue *queue, @@ -172,10 +172,10 @@ void *fc_queue_timedpop(struct fc_queue *queue, { void *data; - PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_LOCK(&queue->lcp.lock); data = queue->head; if (data == NULL) { - fc_cond_timedwait(&queue->lc_pair, timeout, time_unit); + fc_cond_timedwait(&queue->lcp, timeout, time_unit); data = queue->head; } @@ -185,7 +185,7 @@ void *fc_queue_timedpop(struct fc_queue *queue, queue->tail = NULL; } } - PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock); return data; } @@ -195,13 +195,13 @@ void *fc_queue_timedpeek(struct fc_queue *queue, { void *data; - PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_LOCK(&queue->lcp.lock); data = queue->head; if (data == NULL) { - fc_cond_timedwait(&queue->lc_pair, timeout, time_unit); + fc_cond_timedwait(&queue->lcp, timeout, time_unit); data = queue->head; } - PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock); return data; } diff --git a/src/fc_queue.h b/src/fc_queue.h index 42f2e25..1533435 100644 --- a/src/fc_queue.h +++ b/src/fc_queue.h @@ -31,7 +31,7 @@ struct fc_queue { void *head; void *tail; - pthread_lock_cond_pair_t lc_pair; + pthread_lock_cond_pair_t lcp; int next_ptr_offset; }; @@ -49,7 +49,7 @@ void fc_queue_destroy(struct fc_queue *queue); static inline void fc_queue_terminate(struct fc_queue *queue) { - pthread_cond_signal(&queue->lc_pair.cond); + pthread_cond_signal(&queue->lcp.cond); } static inline void fc_queue_terminate_all( @@ -57,7 +57,7 @@ static inline void fc_queue_terminate_all( { int i; for (i=0; ilc_pair.cond)); + pthread_cond_signal(&(queue->lcp.cond)); } } @@ -75,7 +75,7 @@ static inline void fc_queue_push(struct fc_queue *queue, void *data) fc_queue_push_ex(queue, data, ¬ify); if (notify) { - pthread_cond_signal(&(queue->lc_pair.cond)); + pthread_cond_signal(&(queue->lcp.cond)); } } @@ -95,7 +95,7 @@ static inline void fc_queue_push_queue_to_head(struct fc_queue *queue, fc_queue_push_queue_to_head_ex(queue, qinfo, ¬ify); if (notify) { - pthread_cond_signal(&(queue->lc_pair.cond)); + pthread_cond_signal(&(queue->lcp.cond)); } } @@ -116,7 +116,7 @@ static inline void fc_queue_push_queue_to_tail(struct fc_queue *queue, fc_queue_push_queue_to_tail_ex(queue, qinfo, ¬ify); if (notify) { - pthread_cond_signal(&(queue->lc_pair.cond)); + pthread_cond_signal(&(queue->lcp.cond)); } } @@ -148,9 +148,9 @@ static inline bool fc_queue_empty(struct fc_queue *queue) { bool empty; - pthread_mutex_lock(&queue->lc_pair.lock); + pthread_mutex_lock(&queue->lcp.lock); empty = (queue->head == NULL); - pthread_mutex_unlock(&queue->lc_pair.lock); + pthread_mutex_unlock(&queue->lcp.lock); return empty; } @@ -160,14 +160,14 @@ static inline int fc_queue_count(struct fc_queue *queue) void *data; count = 0; - pthread_mutex_lock(&queue->lc_pair.lock); + pthread_mutex_lock(&queue->lcp.lock); data = queue->head; while (data != NULL) { ++count; data = FC_QUEUE_NEXT_PTR(queue, data); } - pthread_mutex_unlock(&queue->lc_pair.lock); + pthread_mutex_unlock(&queue->lcp.lock); return count; } diff --git a/src/sorted_queue.c b/src/sorted_queue.c index cf72d69..7183f15 100644 --- a/src/sorted_queue.c +++ b/src/sorted_queue.c @@ -35,7 +35,7 @@ void sorted_queue_push_ex(struct sorted_queue *sq, void *data, bool *notify) void *previous; void *current; - PTHREAD_MUTEX_LOCK(&sq->queue.lc_pair.lock); + PTHREAD_MUTEX_LOCK(&sq->queue.lcp.lock); if (sq->queue.tail == NULL) { FC_QUEUE_NEXT_PTR(&sq->queue, data) = NULL; sq->queue.head = sq->queue.tail = data; @@ -65,7 +65,7 @@ void sorted_queue_push_ex(struct sorted_queue *sq, void *data, bool *notify) } } - PTHREAD_MUTEX_UNLOCK(&sq->queue.lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&sq->queue.lcp.lock); } void *sorted_queue_pop_ex(struct sorted_queue *sq, @@ -73,7 +73,7 @@ void *sorted_queue_pop_ex(struct sorted_queue *sq, { void *data; - PTHREAD_MUTEX_LOCK(&sq->queue.lc_pair.lock); + PTHREAD_MUTEX_LOCK(&sq->queue.lcp.lock); do { if (sq->queue.head == NULL || sq->compare_func( sq->queue.head, less_equal) > 0) @@ -83,8 +83,8 @@ void *sorted_queue_pop_ex(struct sorted_queue *sq, break; } - pthread_cond_wait(&sq->queue.lc_pair.cond, - &sq->queue.lc_pair.lock); + pthread_cond_wait(&sq->queue.lcp.cond, + &sq->queue.lcp.lock); } if (sq->queue.head == NULL) { @@ -102,7 +102,7 @@ void *sorted_queue_pop_ex(struct sorted_queue *sq, } } while (0); - PTHREAD_MUTEX_UNLOCK(&sq->queue.lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&sq->queue.lcp.lock); return data; } @@ -110,7 +110,7 @@ void sorted_queue_pop_to_queue_ex(struct sorted_queue *sq, void *less_equal, struct fc_queue_info *qinfo, const bool blocked) { - PTHREAD_MUTEX_LOCK(&sq->queue.lc_pair.lock); + PTHREAD_MUTEX_LOCK(&sq->queue.lcp.lock); do { if (sq->queue.head == NULL) { if (!blocked) { @@ -118,8 +118,8 @@ void sorted_queue_pop_to_queue_ex(struct sorted_queue *sq, break; } - pthread_cond_wait(&sq->queue.lc_pair.cond, - &sq->queue.lc_pair.lock); + pthread_cond_wait(&sq->queue.lcp.cond, + &sq->queue.lcp.lock); } if (sq->queue.head == NULL) { @@ -148,5 +148,5 @@ void sorted_queue_pop_to_queue_ex(struct sorted_queue *sq, } } while (0); - PTHREAD_MUTEX_UNLOCK(&sq->queue.lc_pair.lock); + PTHREAD_MUTEX_UNLOCK(&sq->queue.lcp.lock); } diff --git a/src/sorted_queue.h b/src/sorted_queue.h index 5ad7fd2..83c0683 100644 --- a/src/sorted_queue.h +++ b/src/sorted_queue.h @@ -55,7 +55,7 @@ static inline void sorted_queue_push(struct sorted_queue *sq, void *data) sorted_queue_push_ex(sq, data, ¬ify); if (notify) { - pthread_cond_signal(&(sq->queue.lc_pair.cond)); + pthread_cond_signal(&(sq->queue.lcp.cond)); } }