code simplification for epoll edge trigger

fstore_storage_engine
YuQing 2023-02-12 20:04:01 +08:00
parent 294ad5e636
commit 13990e3747
1 changed files with 5 additions and 70 deletions

View File

@ -95,8 +95,6 @@ static inline void release_iovec_buffer(struct fast_task_info *task)
void sf_task_finish_clean_up(struct fast_task_info *task) void sf_task_finish_clean_up(struct fast_task_info *task)
{ {
//int next_stage;
/* /*
assert(task->event.fd >= 0); assert(task->event.fd >= 0);
if (task->event.fd < 0) { if (task->event.fd < 0) {
@ -112,18 +110,6 @@ void sf_task_finish_clean_up(struct fast_task_info *task)
task->finish_callback = NULL; task->finish_callback = NULL;
} }
/*
if (SF_G_EPOLL_EDGE_TRIGGER && (next_stage=FC_ATOMIC_GET(task->
nio_stages.next)) != SF_NIO_STAGE_NONE)
{
logWarning("file: "__FILE__", line: %d, "
"task: %p, nio_stages.next: %d != 0",
__LINE__, task, FC_ATOMIC_GET(task->nio_stages.next));
__sync_bool_compare_and_swap(&task->nio_stages.next,
next_stage, SF_NIO_STAGE_NONE);
}
*/
release_iovec_buffer(task); release_iovec_buffer(task);
sf_task_detach_thread(task); sf_task_detach_thread(task);
@ -158,7 +144,7 @@ static inline int set_write_event(struct fast_task_info *task)
return 0; return 0;
} }
static int setup_read_event(struct fast_task_info *task) int sf_set_read_event(struct fast_task_info *task)
{ {
int result; int result;
@ -184,33 +170,6 @@ static int setup_read_event(struct fast_task_info *task)
return 0; return 0;
} }
int sf_set_read_event(struct fast_task_info *task)
{
int result;
if ((result=setup_read_event(task)) != 0) {
return result;
}
return 0;
if (SF_G_EPOLL_EDGE_TRIGGER) {
if (FC_ATOMIC_GET(task->nio_stages.notify) == SF_NIO_STAGE_SEND) {
if (__sync_bool_compare_and_swap(&task->nio_stages.next,
SF_NIO_STAGE_NONE, SF_NIO_STAGE_RECV))
{
return 0;
} else {
return EAGAIN;
}
} else {
return sf_nio_notify(task, SF_NIO_STAGE_RECV);
return 0;
}
} else {
return 0;
}
}
static inline int sf_ioevent_add(struct fast_task_info *task, static inline int sf_ioevent_add(struct fast_task_info *task,
IOEventCallback callback, const int timeout) IOEventCallback callback, const int timeout)
{ {
@ -318,7 +277,7 @@ static int sf_nio_deal_task(struct fast_task_info *task, const int stage)
result = sf_connect_server(task); result = sf_connect_server(task);
break; break;
case SF_NIO_STAGE_RECV: case SF_NIO_STAGE_RECV:
if ((result=setup_read_event(task)) == 0) { if ((result=sf_set_read_event(task)) == 0) {
if (sf_client_sock_read(task->event.fd, if (sf_client_sock_read(task->event.fd,
IOEVENT_READ, task) < 0) IOEVENT_READ, task) < 0)
{ {
@ -397,20 +356,7 @@ int sf_nio_notify(struct fast_task_info *task, const int stage)
__LINE__, stage); __LINE__, stage);
return 0; return 0;
} else if (old_stage == SF_NIO_STAGE_NONE) { } else if (old_stage != SF_NIO_STAGE_NONE) {
continue;
/*
} else if (SF_G_EPOLL_EDGE_TRIGGER && (
(old_stage == SF_NIO_STAGE_RECV &&
stage == SF_NIO_STAGE_SEND) ||
(old_stage == SF_NIO_STAGE_SEND &&
stage == SF_NIO_STAGE_RECV)))
{
__sync_bool_compare_and_swap(&task->nio_stages.
next, SF_NIO_STAGE_NONE, stage);
return 0;
*/
} else {
logWarning("file: "__FILE__", line: %d, " logWarning("file: "__FILE__", line: %d, "
"current stage: %d != %d, skip set stage to %d", "current stage: %d != %d, skip set stage to %d",
__LINE__, old_stage, SF_NIO_STAGE_NONE, stage); __LINE__, old_stage, SF_NIO_STAGE_NONE, stage);
@ -451,8 +397,6 @@ void sf_recv_notify_read(int sock, short event, void *arg)
{ {
int64_t n; int64_t n;
int stage; int stage;
int next;
int result;
struct nio_thread_data *thread_data; struct nio_thread_data *thread_data;
struct fast_task_info *task; struct fast_task_info *task;
struct fast_task_info *current; struct fast_task_info *current;
@ -479,21 +423,12 @@ void sf_recv_notify_read(int sock, short event, void *arg)
/* MUST set to SF_NIO_STAGE_NONE first for re-entry */ /* MUST set to SF_NIO_STAGE_NONE first for re-entry */
__sync_bool_compare_and_swap(&task->nio_stages.notify, __sync_bool_compare_and_swap(&task->nio_stages.notify,
stage, SF_NIO_STAGE_NONE); stage, SF_NIO_STAGE_NONE);
result = sf_nio_deal_task(task, stage); sf_nio_deal_task(task, stage);
} else { } else {
result = sf_nio_deal_task(task, stage); sf_nio_deal_task(task, stage);
__sync_bool_compare_and_swap(&task->nio_stages.notify, __sync_bool_compare_and_swap(&task->nio_stages.notify,
stage, SF_NIO_STAGE_NONE); stage, SF_NIO_STAGE_NONE);
} }
if (SF_G_EPOLL_EDGE_TRIGGER && result >= 0) {
next = FC_ATOMIC_GET(task->nio_stages.next);
if (next != SF_NIO_STAGE_NONE) {
//sf_nio_notify(task, next);
__sync_bool_compare_and_swap(&task->nio_stages.next,
next, SF_NIO_STAGE_NONE);
}
}
} else { } else {
if (stage != SF_NIO_STAGE_NONE) { if (stage != SF_NIO_STAGE_NONE) {
if (stage == SF_NIO_STAGE_CONTINUE) { if (stage == SF_NIO_STAGE_CONTINUE) {