lc_pair in struct fc_queue change to lcp

fstore_storage_engine
YuQing 2023-03-27 16:18:32 +08:00
parent 595a8c5664
commit f1691b7480
5 changed files with 46 additions and 45 deletions

View File

@ -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 * 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 Version 1.65 2023-01-09
* locked_list.h: add functions locked_list_move and locked_list_move_tail * locked_list.h: add functions locked_list_move and locked_list_move_tail

View File

@ -22,7 +22,7 @@ int fc_queue_init(struct fc_queue *queue, const int next_ptr_offset)
{ {
int result; 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; 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) 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) 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; FC_QUEUE_NEXT_PTR(queue, data) = NULL;
if (queue->tail == NULL) { if (queue->tail == NULL) {
queue->head = data; queue->head = data;
@ -51,14 +51,14 @@ void fc_queue_push_ex(struct fc_queue *queue, void *data, bool *notify)
} }
queue->tail = data; 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 *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked)
{ {
void *data; void *data;
PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_LOCK(&queue->lcp.lock);
do { do {
data = queue->head; data = queue->head;
if (data == NULL) { if (data == NULL) {
@ -66,7 +66,7 @@ void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked)
break; break;
} }
pthread_cond_wait(&queue->lc_pair.cond, &queue->lc_pair.lock); pthread_cond_wait(&queue->lcp.cond, &queue->lcp.lock);
data = queue->head; data = queue->head;
} }
@ -78,7 +78,7 @@ void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked)
} }
} while (0); } while (0);
PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock);
return data; return data;
} }
@ -86,7 +86,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked)
{ {
void *data; void *data;
PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_LOCK(&queue->lcp.lock);
do { do {
data = queue->head; data = queue->head;
if (data == NULL) { if (data == NULL) {
@ -94,7 +94,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked)
break; break;
} }
pthread_cond_wait(&queue->lc_pair.cond, &queue->lc_pair.lock); pthread_cond_wait(&queue->lcp.cond, &queue->lcp.lock);
data = queue->head; data = queue->head;
} }
@ -103,7 +103,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked)
} }
} while (0); } while (0);
PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock);
return data; return data;
} }
@ -115,7 +115,7 @@ void fc_queue_push_queue_to_head_ex(struct fc_queue *queue,
return; return;
} }
PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_LOCK(&queue->lcp.lock);
FC_QUEUE_NEXT_PTR(queue, qinfo->tail) = queue->head; FC_QUEUE_NEXT_PTR(queue, qinfo->tail) = queue->head;
queue->head = qinfo->head; queue->head = qinfo->head;
if (queue->tail == NULL) { if (queue->tail == NULL) {
@ -124,7 +124,7 @@ void fc_queue_push_queue_to_head_ex(struct fc_queue *queue,
} else { } else {
*notify = false; *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, 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; return;
} }
PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_LOCK(&queue->lcp.lock);
if (queue->head == NULL) { if (queue->head == NULL) {
queue->head = qinfo->head; queue->head = qinfo->head;
*notify = true; *notify = true;
@ -144,16 +144,16 @@ void fc_queue_push_queue_to_tail_ex(struct fc_queue *queue,
*notify = false; *notify = false;
} }
queue->tail = qinfo->tail; 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, void fc_queue_pop_to_queue_ex(struct fc_queue *queue,
struct fc_queue_info *qinfo, const bool blocked) 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 (queue->head == NULL) {
if (blocked) { 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 { } else {
qinfo->head = qinfo->tail = NULL; 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, void *fc_queue_timedpop(struct fc_queue *queue,
@ -172,10 +172,10 @@ void *fc_queue_timedpop(struct fc_queue *queue,
{ {
void *data; void *data;
PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_LOCK(&queue->lcp.lock);
data = queue->head; data = queue->head;
if (data == NULL) { if (data == NULL) {
fc_cond_timedwait(&queue->lc_pair, timeout, time_unit); fc_cond_timedwait(&queue->lcp, timeout, time_unit);
data = queue->head; data = queue->head;
} }
@ -185,7 +185,7 @@ void *fc_queue_timedpop(struct fc_queue *queue,
queue->tail = NULL; queue->tail = NULL;
} }
} }
PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock);
return data; return data;
} }
@ -195,13 +195,13 @@ void *fc_queue_timedpeek(struct fc_queue *queue,
{ {
void *data; void *data;
PTHREAD_MUTEX_LOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_LOCK(&queue->lcp.lock);
data = queue->head; data = queue->head;
if (data == NULL) { if (data == NULL) {
fc_cond_timedwait(&queue->lc_pair, timeout, time_unit); fc_cond_timedwait(&queue->lcp, timeout, time_unit);
data = queue->head; data = queue->head;
} }
PTHREAD_MUTEX_UNLOCK(&queue->lc_pair.lock); PTHREAD_MUTEX_UNLOCK(&queue->lcp.lock);
return data; return data;
} }

View File

@ -31,7 +31,7 @@ struct fc_queue
{ {
void *head; void *head;
void *tail; void *tail;
pthread_lock_cond_pair_t lc_pair; pthread_lock_cond_pair_t lcp;
int next_ptr_offset; 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) 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( static inline void fc_queue_terminate_all(
@ -57,7 +57,7 @@ static inline void fc_queue_terminate_all(
{ {
int i; int i;
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
pthread_cond_signal(&(queue->lc_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, &notify); fc_queue_push_ex(queue, data, &notify);
if (notify) { 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, &notify); fc_queue_push_queue_to_head_ex(queue, qinfo, &notify);
if (notify) { 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, &notify); fc_queue_push_queue_to_tail_ex(queue, qinfo, &notify);
if (notify) { 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; bool empty;
pthread_mutex_lock(&queue->lc_pair.lock); pthread_mutex_lock(&queue->lcp.lock);
empty = (queue->head == NULL); empty = (queue->head == NULL);
pthread_mutex_unlock(&queue->lc_pair.lock); pthread_mutex_unlock(&queue->lcp.lock);
return empty; return empty;
} }
@ -160,14 +160,14 @@ static inline int fc_queue_count(struct fc_queue *queue)
void *data; void *data;
count = 0; count = 0;
pthread_mutex_lock(&queue->lc_pair.lock); pthread_mutex_lock(&queue->lcp.lock);
data = queue->head; data = queue->head;
while (data != NULL) while (data != NULL)
{ {
++count; ++count;
data = FC_QUEUE_NEXT_PTR(queue, data); data = FC_QUEUE_NEXT_PTR(queue, data);
} }
pthread_mutex_unlock(&queue->lc_pair.lock); pthread_mutex_unlock(&queue->lcp.lock);
return count; return count;
} }

View File

@ -35,7 +35,7 @@ void sorted_queue_push_ex(struct sorted_queue *sq, void *data, bool *notify)
void *previous; void *previous;
void *current; void *current;
PTHREAD_MUTEX_LOCK(&sq->queue.lc_pair.lock); PTHREAD_MUTEX_LOCK(&sq->queue.lcp.lock);
if (sq->queue.tail == NULL) { if (sq->queue.tail == NULL) {
FC_QUEUE_NEXT_PTR(&sq->queue, data) = NULL; FC_QUEUE_NEXT_PTR(&sq->queue, data) = NULL;
sq->queue.head = sq->queue.tail = data; 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, void *sorted_queue_pop_ex(struct sorted_queue *sq,
@ -73,7 +73,7 @@ void *sorted_queue_pop_ex(struct sorted_queue *sq,
{ {
void *data; void *data;
PTHREAD_MUTEX_LOCK(&sq->queue.lc_pair.lock); PTHREAD_MUTEX_LOCK(&sq->queue.lcp.lock);
do { do {
if (sq->queue.head == NULL || sq->compare_func( if (sq->queue.head == NULL || sq->compare_func(
sq->queue.head, less_equal) > 0) sq->queue.head, less_equal) > 0)
@ -83,8 +83,8 @@ void *sorted_queue_pop_ex(struct sorted_queue *sq,
break; break;
} }
pthread_cond_wait(&sq->queue.lc_pair.cond, pthread_cond_wait(&sq->queue.lcp.cond,
&sq->queue.lc_pair.lock); &sq->queue.lcp.lock);
} }
if (sq->queue.head == NULL) { if (sq->queue.head == NULL) {
@ -102,7 +102,7 @@ void *sorted_queue_pop_ex(struct sorted_queue *sq,
} }
} while (0); } while (0);
PTHREAD_MUTEX_UNLOCK(&sq->queue.lc_pair.lock); PTHREAD_MUTEX_UNLOCK(&sq->queue.lcp.lock);
return data; 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, void *less_equal, struct fc_queue_info *qinfo,
const bool blocked) const bool blocked)
{ {
PTHREAD_MUTEX_LOCK(&sq->queue.lc_pair.lock); PTHREAD_MUTEX_LOCK(&sq->queue.lcp.lock);
do { do {
if (sq->queue.head == NULL) { if (sq->queue.head == NULL) {
if (!blocked) { if (!blocked) {
@ -118,8 +118,8 @@ void sorted_queue_pop_to_queue_ex(struct sorted_queue *sq,
break; break;
} }
pthread_cond_wait(&sq->queue.lc_pair.cond, pthread_cond_wait(&sq->queue.lcp.cond,
&sq->queue.lc_pair.lock); &sq->queue.lcp.lock);
} }
if (sq->queue.head == NULL) { if (sq->queue.head == NULL) {
@ -148,5 +148,5 @@ void sorted_queue_pop_to_queue_ex(struct sorted_queue *sq,
} }
} while (0); } while (0);
PTHREAD_MUTEX_UNLOCK(&sq->queue.lc_pair.lock); PTHREAD_MUTEX_UNLOCK(&sq->queue.lcp.lock);
} }

View File

@ -55,7 +55,7 @@ static inline void sorted_queue_push(struct sorted_queue *sq, void *data)
sorted_queue_push_ex(sq, data, &notify); sorted_queue_push_ex(sq, data, &notify);
if (notify) { if (notify) {
pthread_cond_signal(&(sq->queue.lc_pair.cond)); pthread_cond_signal(&(sq->queue.lcp.cond));
} }
} }