From 223f15fb79a6004b4690cef5e4ddd47cafe8100b Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Mon, 18 Jan 2021 11:25:32 +0800 Subject: [PATCH] add functions: sf_set_deal_task_func_ex etc. --- src/sf_nio.h | 9 +++++++++ src/sf_service.c | 25 +++++++++++++++++++------ src/sf_service.h | 6 ++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/sf_nio.h b/src/sf_nio.h index f52431a..1dbf6b3 100644 --- a/src/sf_nio.h +++ b/src/sf_nio.h @@ -40,6 +40,15 @@ void sf_set_parameters_ex(SFContext *sf_context, const int header_size, set_body_length_func, deal_func, \ cleanup_func, timeout_callback) +static inline void sf_set_deal_task_func_ex(SFContext *sf_context, + sf_deal_task_func deal_func) +{ + sf_context->deal_task = deal_func; +} + +#define sf_set_deal_task_func(deal_func) \ + sf_set_deal_task_func_ex(&g_sf_context, deal_func) + static inline void sf_set_remove_from_ready_list_ex(SFContext *sf_context, const bool enabled) { diff --git a/src/sf_service.c b/src/sf_service.c index 24fc598..b80d3b5 100644 --- a/src/sf_service.c +++ b/src/sf_service.c @@ -131,7 +131,7 @@ int sf_service_init_ex2(SFContext *sf_context, struct worker_thread_context *thread_contexts; struct worker_thread_context *thread_ctx; struct nio_thread_data *thread_data; - struct nio_thread_data *pDataEnd; + struct nio_thread_data *data_end; pthread_t tid; pthread_attr_t thread_attr; @@ -167,9 +167,9 @@ int sf_service_init_ex2(SFContext *sf_context, } sf_context->thread_count = 0; - pDataEnd = sf_context->thread_data + sf_context->work_threads; + data_end = sf_context->thread_data + sf_context->work_threads; for (thread_data=sf_context->thread_data,thread_ctx=thread_contexts; - thread_datathread_loop_callback = thread_loop_callback; if (alloc_thread_extra_data_callback != NULL) { @@ -251,11 +251,11 @@ int sf_service_init_ex2(SFContext *sf_context, int sf_service_destroy_ex(SFContext *sf_context) { - struct nio_thread_data *pDataEnd, *thread_data; + struct nio_thread_data *data_end, *thread_data; free_queue_destroy(); - pDataEnd = sf_context->thread_data + sf_context->work_threads; - for (thread_data=sf_context->thread_data; thread_datathread_data + sf_context->work_threads; + for (thread_data=sf_context->thread_data; thread_datatimer); @@ -265,6 +265,19 @@ int sf_service_destroy_ex(SFContext *sf_context) return 0; } +void sf_service_set_thread_loop_callback_ex(SFContext *sf_context, + ThreadLoopCallback thread_loop_callback) +{ + struct nio_thread_data *data_end, *thread_data; + + data_end = sf_context->thread_data + sf_context->work_threads; + for (thread_data=sf_context->thread_data; thread_datathread_loop_callback = thread_loop_callback; + } +} + static void *worker_thread_entrance(void *arg) { struct worker_thread_context *thread_ctx; diff --git a/src/sf_service.h b/src/sf_service.h index 4648ba9..4eab6fd 100644 --- a/src/sf_service.h +++ b/src/sf_service.h @@ -66,6 +66,12 @@ int sf_service_destroy_ex(SFContext *sf_context); #define sf_service_destroy() sf_service_destroy_ex(&g_sf_context) +void sf_service_set_thread_loop_callback_ex(SFContext *sf_context, + ThreadLoopCallback thread_loop_callback); + +#define sf_service_set_thread_loop_callback(thread_loop_callback) \ + sf_service_set_thread_loop_callback_ex(&g_sf_context, thread_loop_callback) + int sf_setup_signal_handler(); int sf_startup_schedule(pthread_t *schedule_tid);