From 1ac8c8f3c25e4e52a3f22ca81e3279848111a50e Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Wed, 28 Oct 2020 11:59:37 +0800 Subject: [PATCH] fast_task_info add fields: reffer_count and continue_callback --- HISTORY | 2 +- src/fast_task_queue.h | 4 +++- src/ioevent_loop.h | 10 +++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/HISTORY b/HISTORY index e8a0df1..585348b 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.44 2020-10-21 +Version 1.44 2020-10-28 * add test file src/tests/test_pthread_lock.c * add uniq_skiplist.[hc] * add function split_string_ex diff --git a/src/fast_task_queue.h b/src/fast_task_queue.h index 37a02f1..5e2d4c3 100644 --- a/src/fast_task_queue.h +++ b/src/fast_task_queue.h @@ -87,7 +87,9 @@ struct fast_task_info uint8_t current; volatile uint8_t notify; } nio_stages; //stages for network IO - bool canceled; //if task canceled + int (*continue_callback)(struct fast_task_info *task); //for continue stage + volatile int8_t reffer_count; + volatile int8_t canceled; //if task canceled int connect_timeout; //for client side int network_timeout; int64_t req_count; //request count diff --git a/src/ioevent_loop.h b/src/ioevent_loop.h index 40a5946..8a41970 100644 --- a/src/ioevent_loop.h +++ b/src/ioevent_loop.h @@ -32,20 +32,16 @@ int ioevent_remove(IOEventPoller *ioevent, void *data); int ioevent_set(struct fast_task_info *pTask, struct nio_thread_data *pThread, int sock, short event, IOEventCallback callback, const int timeout); +//only called by the nio thread static inline void ioevent_add_to_deleted_list(struct fast_task_info *task) { - if (task->thread_data == NULL) + if (!__sync_bool_compare_and_swap(&task->canceled, 0, 1)) { - return; - } - - if (task->canceled) { - logError("file: "__FILE__", line: %d, " + logWarning("file: "__FILE__", line: %d, " "task %p already canceled", __LINE__, task); return; } - task->canceled = true; task->next = task->thread_data->deleted_list; task->thread_data->deleted_list = task; }