diff --git a/src/sf_nio.c b/src/sf_nio.c index 85f3599..b5fc9b6 100644 --- a/src/sf_nio.c +++ b/src/sf_nio.c @@ -324,11 +324,18 @@ int sf_nio_notify(struct fast_task_info *task, const int stage) if (!__sync_bool_compare_and_swap(&task->nio_stages.notify, SF_NIO_STAGE_NONE, stage)) { - logWarning("file: "__FILE__", line: %d, " - "current stage: %d != %d, skip set stage to %d", - __LINE__, __sync_fetch_and_sub(&task->nio_stages.notify, 0), - SF_NIO_STAGE_NONE, stage); - return EAGAIN; + if (__sync_fetch_and_add(&task->nio_stages.notify, 0) == stage) { + logDebug("file: "__FILE__", line: %d, " + "current stage: %d equals to the target, skip set", + __LINE__, stage); + return 0; + } else { + logWarning("file: "__FILE__", line: %d, " + "current stage: %d != %d, skip set stage to %d", + __LINE__, __sync_fetch_and_add(&task->nio_stages.notify, 0), + SF_NIO_STAGE_NONE, stage); + return EAGAIN; + } } PTHREAD_MUTEX_LOCK(&task->thread_data->waiting_queue.lock);