set thread name as necessary
parent
03b6d7b20a
commit
eea7adde7c
|
|
@ -480,7 +480,7 @@ static int do_init()
|
|||
}
|
||||
memset(receipt_thread_contexts, 0, bytes);
|
||||
|
||||
return sf_service_init_ex2(&g_sf_context,
|
||||
return sf_service_init_ex2(&g_sf_context, "idemp-receipt",
|
||||
receipt_alloc_thread_extra_data, receipt_thread_loop_callback,
|
||||
NULL, sf_proto_set_body_length, receipt_deal_task,
|
||||
receipt_task_finish_cleanup, receipt_recv_timeout_callback,
|
||||
|
|
|
|||
|
|
@ -535,6 +535,16 @@ static void *binlog_writer_func(void *arg)
|
|||
SFBinlogWriterBuffer *wb_head;
|
||||
|
||||
thread = (SFBinlogWriterThread *)arg;
|
||||
|
||||
#ifdef OS_LINUX
|
||||
{
|
||||
char thread_name[64];
|
||||
snprintf(thread_name, sizeof(thread_name),
|
||||
"writer-%s", thread->name);
|
||||
prctl(PR_SET_NAME, thread_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
thread->running = true;
|
||||
while (SF_G_CONTINUE_FLAG) {
|
||||
wb_head = (SFBinlogWriterBuffer *)fc_queue_pop_all(&thread->queue);
|
||||
|
|
@ -641,7 +651,7 @@ int sf_binlog_writer_init_by_version(SFBinlogWriterInfo *writer,
|
|||
}
|
||||
|
||||
int sf_binlog_writer_init_thread_ex(SFBinlogWriterThread *thread,
|
||||
SFBinlogWriterInfo *writer, const short order_mode,
|
||||
const char *name, SFBinlogWriterInfo *writer, const short order_mode,
|
||||
const short order_by, const int max_record_size,
|
||||
const int writer_count, const bool use_fixed_buffer_size)
|
||||
{
|
||||
|
|
@ -650,6 +660,7 @@ int sf_binlog_writer_init_thread_ex(SFBinlogWriterThread *thread,
|
|||
pthread_t tid;
|
||||
int result;
|
||||
|
||||
snprintf(thread->name, sizeof(thread->name), "%s", name);
|
||||
thread->order_mode = order_mode;
|
||||
thread->order_by = order_by;
|
||||
thread->use_fixed_buffer_size = use_fixed_buffer_size;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ typedef struct sf_binlog_writer_buffer_ring {
|
|||
typedef struct binlog_writer_thread {
|
||||
struct fast_mblock_man mblock;
|
||||
struct fc_queue queue;
|
||||
char name[64];
|
||||
bool running;
|
||||
bool use_fixed_buffer_size;
|
||||
short order_mode;
|
||||
|
|
@ -127,13 +128,13 @@ int sf_binlog_writer_init_by_version(SFBinlogWriterInfo *writer,
|
|||
const int buffer_size, const int ring_size);
|
||||
|
||||
int sf_binlog_writer_init_thread_ex(SFBinlogWriterThread *thread,
|
||||
SFBinlogWriterInfo *writer, const short order_mode,
|
||||
const char *name, SFBinlogWriterInfo *writer, const short order_mode,
|
||||
const short order_by, const int max_record_size,
|
||||
const int writer_count, const bool use_fixed_buffer_size);
|
||||
|
||||
#define sf_binlog_writer_init_thread(thread, \
|
||||
#define sf_binlog_writer_init_thread(thread, name, \
|
||||
writer, order_by, max_record_size) \
|
||||
sf_binlog_writer_init_thread_ex(thread, writer, \
|
||||
sf_binlog_writer_init_thread_ex(thread, name, writer, \
|
||||
SF_BINLOG_THREAD_ORDER_MODE_FIXED, \
|
||||
order_by, max_record_size, 1, true)
|
||||
|
||||
|
|
@ -148,8 +149,9 @@ static inline int sf_binlog_writer_init(SFBinlogWriterContext *context,
|
|||
return result;
|
||||
}
|
||||
|
||||
return sf_binlog_writer_init_thread(&context->thread, &context->writer,
|
||||
SF_BINLOG_THREAD_TYPE_ORDER_BY_NONE, max_record_size);
|
||||
return sf_binlog_writer_init_thread(&context->thread, subdir_name,
|
||||
&context->writer, SF_BINLOG_THREAD_TYPE_ORDER_BY_NONE,
|
||||
max_record_size);
|
||||
}
|
||||
|
||||
int sf_binlog_writer_change_order_by(SFBinlogWriterInfo *writer,
|
||||
|
|
|
|||
|
|
@ -817,6 +817,10 @@ static void *connection_manager_thread_func(void *arg)
|
|||
SFConnectionManager *cm;
|
||||
struct common_blocked_node *head;
|
||||
|
||||
#ifdef OS_LINUX
|
||||
prctl(PR_SET_NAME, "cm-alive-detect");
|
||||
#endif
|
||||
|
||||
cm = (SFConnectionManager *)arg;
|
||||
logInfo("file: "__FILE__", line: %d, "
|
||||
"[%s] connection manager thread start",
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ SFGlobalVariables g_sf_global_vars = {
|
|||
};
|
||||
|
||||
SFContext g_sf_context = {
|
||||
NULL, 0, -1, -1, 0, 0, 1, DEFAULT_WORK_THREADS,
|
||||
{'\0'}, NULL, 0, -1, -1, 0, 0, 1, DEFAULT_WORK_THREADS,
|
||||
{'\0'}, {'\0'}, 0, true, true, NULL, NULL, NULL,
|
||||
sf_task_finish_clean_up, NULL
|
||||
};
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ static int sf_init_free_queues(const int task_arg_size,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int sf_service_init_ex2(SFContext *sf_context,
|
||||
int sf_service_init_ex2(SFContext *sf_context, const char *name,
|
||||
sf_alloc_thread_extra_data_callback
|
||||
alloc_thread_extra_data_callback,
|
||||
ThreadLoopCallback thread_loop_callback,
|
||||
|
|
@ -135,6 +135,7 @@ int sf_service_init_ex2(SFContext *sf_context,
|
|||
pthread_t tid;
|
||||
pthread_attr_t thread_attr;
|
||||
|
||||
snprintf(sf_context->name, sizeof(sf_context->name), "%s", name);
|
||||
sf_context->realloc_task_buffer = g_sf_global_vars.
|
||||
min_buff_size < g_sf_global_vars.max_buff_size;
|
||||
sf_context->accept_done_func = accept_done_callback;
|
||||
|
|
@ -234,7 +235,7 @@ int sf_service_init_ex2(SFContext *sf_context,
|
|||
thread_ctx->sf_context = sf_context;
|
||||
thread_ctx->thread_data = thread_data;
|
||||
if ((result=pthread_create(&tid, &thread_attr,
|
||||
worker_thread_entrance, thread_ctx)) != 0)
|
||||
worker_thread_entrance, thread_ctx)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"create thread failed, startup threads: %d, "
|
||||
|
|
@ -284,6 +285,17 @@ static void *worker_thread_entrance(void *arg)
|
|||
int thread_count;
|
||||
|
||||
thread_ctx = (struct worker_thread_context *)arg;
|
||||
|
||||
#ifdef OS_LINUX
|
||||
{
|
||||
char thread_name[32];
|
||||
snprintf(thread_name, sizeof(thread_name), "%s-net[%d]",
|
||||
thread_ctx->sf_context->name, (int)(thread_ctx->
|
||||
thread_data - thread_ctx->sf_context->thread_data));
|
||||
prctl(PR_SET_NAME, thread_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
thread_count = __sync_add_and_fetch(&thread_ctx->
|
||||
sf_context->thread_count, 1);
|
||||
|
||||
|
|
@ -375,6 +387,16 @@ static void *accept_thread_entrance(void *arg)
|
|||
struct fast_task_info *task;
|
||||
|
||||
accept_context = (struct accept_thread_context *)arg;
|
||||
|
||||
#ifdef OS_LINUX
|
||||
{
|
||||
char thread_name[32];
|
||||
snprintf(thread_name, sizeof(thread_name), "%s-listen",
|
||||
accept_context->sf_context->name);
|
||||
prctl(PR_SET_NAME, thread_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
while (g_sf_global_vars.continue_flag) {
|
||||
sockaddr_len = sizeof(inaddr);
|
||||
incomesock = accept(accept_context->server_sock,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ typedef void (*sf_sig_quit_handler)(int sig);
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int sf_service_init_ex2(SFContext *sf_context,
|
||||
int sf_service_init_ex2(SFContext *sf_context, const char *name,
|
||||
sf_alloc_thread_extra_data_callback
|
||||
alloc_thread_extra_data_callback,
|
||||
ThreadLoopCallback thread_loop_callback,
|
||||
|
|
@ -44,20 +44,20 @@ int sf_service_init_ex2(SFContext *sf_context,
|
|||
const int proto_header_size, const int task_arg_size,
|
||||
TaskInitCallback init_callback);
|
||||
|
||||
#define sf_service_init_ex(sf_context, alloc_thread_extra_data_callback, \
|
||||
#define sf_service_init_ex(sf_context, name, alloc_thread_extra_data_callback,\
|
||||
thread_loop_callback, accept_done_callback, set_body_length_func, \
|
||||
deal_func, task_cleanup_func, timeout_callback, net_timeout_ms, \
|
||||
proto_header_size, task_arg_size) \
|
||||
sf_service_init_ex2(sf_context, alloc_thread_extra_data_callback, \
|
||||
thread_loop_callback, accept_done_callback, set_body_length_func, \
|
||||
deal_func, task_cleanup_func, timeout_callback, net_timeout_ms, \
|
||||
sf_service_init_ex2(sf_context, name, alloc_thread_extra_data_callback, \
|
||||
thread_loop_callback, accept_done_callback, set_body_length_func, \
|
||||
deal_func, task_cleanup_func, timeout_callback, net_timeout_ms, \
|
||||
proto_header_size, task_arg_size, NULL)
|
||||
|
||||
#define sf_service_init(alloc_thread_extra_data_callback, \
|
||||
#define sf_service_init(name, alloc_thread_extra_data_callback, \
|
||||
thread_loop_callback, accept_done_callback, set_body_length_func, \
|
||||
deal_func, task_cleanup_func, timeout_callback, net_timeout_ms, \
|
||||
proto_header_size, task_arg_size) \
|
||||
sf_service_init_ex2(&g_sf_context, alloc_thread_extra_data_callback, \
|
||||
sf_service_init_ex2(&g_sf_context, name, alloc_thread_extra_data_callback, \
|
||||
thread_loop_callback, accept_done_callback, set_body_length_func, \
|
||||
deal_func, task_cleanup_func, timeout_callback, net_timeout_ms, \
|
||||
proto_header_size, task_arg_size, NULL)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ typedef int (*sf_deal_task_func)(struct fast_task_info *task, const int stage);
|
|||
typedef int (*sf_recv_timeout_callback)(struct fast_task_info *task);
|
||||
|
||||
typedef struct sf_context {
|
||||
char name[64];
|
||||
struct nio_thread_data *thread_data;
|
||||
volatile int thread_count;
|
||||
int outer_sock;
|
||||
|
|
|
|||
Loading…
Reference in New Issue