add functions: sf_set_deal_task_func_ex etc.

connection_manager
YuQing 2021-01-18 11:25:32 +08:00
parent 077c29e2b6
commit 223f15fb79
3 changed files with 34 additions and 6 deletions

View File

@ -40,6 +40,15 @@ void sf_set_parameters_ex(SFContext *sf_context, const int header_size,
set_body_length_func, deal_func, \ set_body_length_func, deal_func, \
cleanup_func, timeout_callback) 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, static inline void sf_set_remove_from_ready_list_ex(SFContext *sf_context,
const bool enabled) const bool enabled)
{ {

View File

@ -131,7 +131,7 @@ int sf_service_init_ex2(SFContext *sf_context,
struct worker_thread_context *thread_contexts; struct worker_thread_context *thread_contexts;
struct worker_thread_context *thread_ctx; struct worker_thread_context *thread_ctx;
struct nio_thread_data *thread_data; struct nio_thread_data *thread_data;
struct nio_thread_data *pDataEnd; struct nio_thread_data *data_end;
pthread_t tid; pthread_t tid;
pthread_attr_t thread_attr; pthread_attr_t thread_attr;
@ -167,9 +167,9 @@ int sf_service_init_ex2(SFContext *sf_context,
} }
sf_context->thread_count = 0; 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; for (thread_data=sf_context->thread_data,thread_ctx=thread_contexts;
thread_data<pDataEnd; thread_data++,thread_ctx++) thread_data<data_end; thread_data++,thread_ctx++)
{ {
thread_data->thread_loop_callback = thread_loop_callback; thread_data->thread_loop_callback = thread_loop_callback;
if (alloc_thread_extra_data_callback != NULL) { 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) 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(); free_queue_destroy();
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_data<pDataEnd; for (thread_data=sf_context->thread_data; thread_data<data_end;
thread_data++) thread_data++)
{ {
fast_timer_destroy(&thread_data->timer); fast_timer_destroy(&thread_data->timer);
@ -265,6 +265,19 @@ int sf_service_destroy_ex(SFContext *sf_context)
return 0; 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_data<data_end;
thread_data++)
{
thread_data->thread_loop_callback = thread_loop_callback;
}
}
static void *worker_thread_entrance(void *arg) static void *worker_thread_entrance(void *arg)
{ {
struct worker_thread_context *thread_ctx; struct worker_thread_context *thread_ctx;

View File

@ -66,6 +66,12 @@ int sf_service_destroy_ex(SFContext *sf_context);
#define sf_service_destroy() sf_service_destroy_ex(&g_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_setup_signal_handler();
int sf_startup_schedule(pthread_t *schedule_tid); int sf_startup_schedule(pthread_t *schedule_tid);