From 2b111d95688415591c9db01448b66307303a45fb Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Thu, 12 Oct 2023 21:58:58 +0800 Subject: [PATCH] use free_queue_set_release_callback --- storage/storage_dio.c | 7 +++++-- storage/storage_service.c | 27 ++++++++++++++++----------- storage/storage_service.h | 22 ---------------------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/storage/storage_dio.c b/storage/storage_dio.c index 252a1d8..64b6bd4 100644 --- a/storage/storage_dio.c +++ b/storage/storage_dio.c @@ -762,8 +762,11 @@ static void *dio_thread_entrance(void* arg) { while ((pTask=blocked_queue_pop(&(pContext->queue))) != NULL) { - ((StorageClientInfo *)pTask->arg)->deal_func(pTask); - storage_release_task(pTask); + if (!FC_ATOMIC_GET(pTask->canceled)) + { + ((StorageClientInfo *)pTask->arg)->deal_func(pTask); + } + sf_release_task(pTask); } } diff --git a/storage/storage_service.c b/storage/storage_service.c index 59fedf8..d1a882d 100644 --- a/storage/storage_service.c +++ b/storage/storage_service.c @@ -1525,16 +1525,6 @@ static void storage_set_metadata_done_callback( \ sf_nio_notify(pTask, SF_NIO_STAGE_SEND); } -void task_finish_clean_up(struct fast_task_info *pTask) -{ - if (__sync_sub_and_fetch(&pTask->reffer_count, 0) == 1) - { - storage_clear_task(pTask); - } - ++g_stat_change_count; - sf_task_finish_clean_up(pTask); -} - int storage_set_body_length(struct fast_task_info *pTask) { StorageClientInfo *pClientInfo; @@ -1638,6 +1628,19 @@ static void *alloc_thread_extra_data_func(const int thread_index) } } +static void storage_clear_task(struct fast_task_info *pTask) +{ + StorageClientInfo *pClientInfo; + + pClientInfo = (StorageClientInfo *)pTask->arg; + if (pClientInfo->clean_func != NULL) + { + pClientInfo->clean_func(pTask); + } + memset(pTask->arg, 0, sizeof(StorageClientInfo)); + ++g_stat_change_count; +} + int storage_service_init() { int result; @@ -1652,10 +1655,12 @@ int storage_service_init() SF_G_EPOLL_EDGE_TRIGGER = true; result = sf_service_init("storage", alloc_thread_extra_data_func, NULL, sock_accept_done_callback, storage_set_body_length, - sock_send_done_callback, storage_deal_task, task_finish_clean_up, + sock_send_done_callback, storage_deal_task, sf_task_finish_clean_up, NULL, 1000, sizeof(TrackerHeader), sizeof(StorageClientInfo)); sf_enable_thread_notify(false); sf_set_remove_from_ready_list(false); + free_queue_set_release_callback(&g_sf_context. + free_queue, storage_clear_task); return result; } diff --git a/storage/storage_service.h b/storage/storage_service.h index b2cccff..30f05c3 100644 --- a/storage/storage_service.h +++ b/storage/storage_service.h @@ -40,28 +40,6 @@ int storage_get_storage_path_index(int *store_path_index); void storage_get_store_path(const char *filename, const int filename_len, int *sub_path_high, int *sub_path_low); -static inline void storage_clear_task(struct fast_task_info *pTask) -{ - StorageClientInfo *pClientInfo; - - pClientInfo = (StorageClientInfo *)pTask->arg; - if (pClientInfo->clean_func != NULL) - { - pClientInfo->clean_func(pTask); - pClientInfo->clean_func = NULL; - } - memset(pTask->arg, 0, sizeof(StorageClientInfo)); -} - -static inline void storage_release_task(struct fast_task_info *pTask) -{ - if (FC_ATOMIC_GET(pTask->reffer_count) == 1) - { - storage_clear_task(pTask); - } - sf_release_task(pTask); -} - #ifdef __cplusplus } #endif