code simplification for last commit

fstore_storage_engine
YuQing 2023-02-23 10:51:46 +08:00
parent 92fbcab0f4
commit 8bedbb6f27
1 changed files with 18 additions and 43 deletions

View File

@ -425,51 +425,26 @@ void sf_recv_notify_read(int sock, short event, void *arg)
__LINE__, sock, errno, STRERROR(errno)); __LINE__, sock, errno, STRERROR(errno));
} }
if (SF_G_EPOLL_EDGE_TRIGGER) { PTHREAD_MUTEX_LOCK(&thread_data->waiting_queue.lock);
while (1) { current = thread_data->waiting_queue.head;
PTHREAD_MUTEX_LOCK(&thread_data->waiting_queue.lock); thread_data->waiting_queue.head = NULL;
if (thread_data->waiting_queue.head != NULL) { thread_data->waiting_queue.tail = NULL;
task = thread_data->waiting_queue.head; PTHREAD_MUTEX_UNLOCK(&thread_data->waiting_queue.lock);
thread_data->waiting_queue.head = task->notify_next;
if (thread_data->waiting_queue.head == NULL) {
thread_data->waiting_queue.tail = NULL;
}
} else {
task = NULL;
}
PTHREAD_MUTEX_UNLOCK(&thread_data->waiting_queue.lock);
if (task != NULL) { while (current != NULL) {
stage = FC_ATOMIC_GET(task->nio_stages.notify); task = current;
__sync_bool_compare_and_swap(&task->nio_stages.notify, current = current->notify_next;
stage, SF_NIO_STAGE_NONE);
deal_notified_task(task, stage);
} else {
break;
}
}
} else {
PTHREAD_MUTEX_LOCK(&thread_data->waiting_queue.lock);
current = thread_data->waiting_queue.head;
thread_data->waiting_queue.head = NULL;
thread_data->waiting_queue.tail = NULL;
PTHREAD_MUTEX_UNLOCK(&thread_data->waiting_queue.lock);
while (current != NULL) { stage = FC_ATOMIC_GET(task->nio_stages.notify);
task = current; if (stage == SF_NIO_STAGE_CONTINUE || SF_G_EPOLL_EDGE_TRIGGER) {
current = current->notify_next; /* MUST set to SF_NIO_STAGE_NONE first for re-entry */
__sync_bool_compare_and_swap(&task->nio_stages.notify,
stage = FC_ATOMIC_GET(task->nio_stages.notify); stage, SF_NIO_STAGE_NONE);
if (stage == SF_NIO_STAGE_CONTINUE) { deal_notified_task(task, stage);
/* MUST set to SF_NIO_STAGE_NONE first for re-entry */ } else {
__sync_bool_compare_and_swap(&task->nio_stages.notify, deal_notified_task(task, stage);
stage, SF_NIO_STAGE_NONE); __sync_bool_compare_and_swap(&task->nio_stages.notify,
deal_notified_task(task, stage); stage, SF_NIO_STAGE_NONE);
} else {
deal_notified_task(task, stage);
__sync_bool_compare_and_swap(&task->nio_stages.notify,
stage, SF_NIO_STAGE_NONE);
}
} }
} }
} }