diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/lib/iomgr/ev_poll_posix.cc | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/executor.cc | 8 | ||||
-rw-r--r-- | src/core/lib/iomgr/timer_manager.cc | 2 | ||||
-rw-r--r-- | src/core/lib/profiling/basic_timers.cc | 3 | ||||
-rw-r--r-- | src/core/lib/support/thd_posix.cc | 18 | ||||
-rw-r--r-- | src/core/lib/support/thd_windows.cc | 3 | ||||
-rw-r--r-- | src/ruby/ext/grpc/rb_grpc_imports.generated.h | 2 |
7 files changed, 28 insertions, 10 deletions
diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 8659559f78..e32e1ba42a 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -1382,7 +1382,7 @@ static poll_args* get_poller_locked(struct pollfd* fds, nfds_t count) { gpr_thd_options opt = gpr_thd_options_default(); gpr_ref(&g_cvfds.pollcount); gpr_thd_options_set_detached(&opt); - GPR_ASSERT(gpr_thd_new(&t_id, &run_poll, pargs, &opt)); + GPR_ASSERT(gpr_thd_new(&t_id, "grpc_poller", &run_poll, pargs, &opt)); return pargs; } diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index d8a195f010..fabdbdf934 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -104,8 +104,8 @@ void grpc_executor_set_threading(grpc_exec_ctx* exec_ctx, bool threading) { gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&g_thread_state[0].id, executor_thread, &g_thread_state[0], - &opt); + gpr_thd_new(&g_thread_state[0].id, "grpc_executor", executor_thread, + &g_thread_state[0], &opt); } else { if (cur_threads == 0) return; for (size_t i = 0; i < g_max_threads; i++) { @@ -263,8 +263,8 @@ static void executor_push(grpc_exec_ctx* exec_ctx, grpc_closure* closure, gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&g_thread_state[cur_thread_count].id, executor_thread, - &g_thread_state[cur_thread_count], &opt); + gpr_thd_new(&g_thread_state[cur_thread_count].id, "gpr_executor", + executor_thread, &g_thread_state[cur_thread_count], &opt); } gpr_spinlock_unlock(&g_adding_thread_lock); } diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index dac74aea24..87ed0e05dc 100644 --- a/src/core/lib/iomgr/timer_manager.cc +++ b/src/core/lib/iomgr/timer_manager.cc @@ -93,7 +93,7 @@ static void start_timer_thread_and_unlock(void) { // to leak through g_completed_threads and be freed in gc_completed_threads() // before "&ct->t" is written to, causing a use-after-free. gpr_mu_lock(&g_mu); - gpr_thd_new(&ct->t, timer_thread, ct, &opt); + gpr_thd_new(&ct->t, "grpc_global_timer", timer_thread, ct, &opt); gpr_mu_unlock(&g_mu); } diff --git a/src/core/lib/profiling/basic_timers.cc b/src/core/lib/profiling/basic_timers.cc index 3ec6280e6b..87dd4ab120 100644 --- a/src/core/lib/profiling/basic_timers.cc +++ b/src/core/lib/profiling/basic_timers.cc @@ -203,7 +203,8 @@ void gpr_timers_set_log_filename(const char* filename) { static void init_output() { gpr_thd_options options = gpr_thd_options_default(); gpr_thd_options_set_joinable(&options); - GPR_ASSERT(gpr_thd_new(&g_writing_thread, writing_thread, NULL, &options)); + GPR_ASSERT(gpr_thd_new(&g_writing_thread, "timer_output_thread", + writing_thread, NULL, &options)); atexit(finish_writing); } diff --git a/src/core/lib/support/thd_posix.cc b/src/core/lib/support/thd_posix.cc index c2a4f4198f..f0ed48dbfc 100644 --- a/src/core/lib/support/thd_posix.cc +++ b/src/core/lib/support/thd_posix.cc @@ -41,6 +41,7 @@ static int g_awaiting_threads; struct thd_arg { void (*body)(void* arg); /* body of a thread */ void* arg; /* argument to a thread */ + const char* name; /* name of thread. Can be nullptr. */ }; static void inc_thd_count(); @@ -50,12 +51,26 @@ static void dec_thd_count(); static void* thread_body(void* v) { struct thd_arg a = *(struct thd_arg*)v; free(v); + if (a.name != nullptr) { +#if GPR_APPLE_PTHREAD_NAME + /* Apple supports 64 characters, and will truncate if it's longer. */ + pthread_setname_np(a.name); +#elif GPR_LINUX_PTHREAD_NAME + /* Linux supports 16 characters max, and will error if it's longer. */ + char buf[16]; + size_t buf_len = GPR_ARRAY_SIZE(buf) - 1; + strncpy(buf, a.name, buf_len); + buf[buf_len] = '\0'; + pthread_setname_np(pthread_self(), buf); +#endif // GPR_APPLE_PTHREAD_NAME + } (*a.body)(a.arg); dec_thd_count(); return nullptr; } -int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, +int gpr_thd_new(gpr_thd_id* t, const char* thd_name, + void (*thd_body)(void* arg), void* arg, const gpr_thd_options* options) { int thread_started; pthread_attr_t attr; @@ -66,6 +81,7 @@ int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, GPR_ASSERT(a != nullptr); a->body = thd_body; a->arg = arg; + a->name = thd_name; inc_thd_count(); GPR_ASSERT(pthread_attr_init(&attr) == 0); diff --git a/src/core/lib/support/thd_windows.cc b/src/core/lib/support/thd_windows.cc index 0875c2f03e..f920770f32 100644 --- a/src/core/lib/support/thd_windows.cc +++ b/src/core/lib/support/thd_windows.cc @@ -65,7 +65,8 @@ static DWORD WINAPI thread_body(void* v) { return 0; } -int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, +int gpr_thd_new(gpr_thd_id* t, const char* thd_name, + void (*thd_body)(void* arg), void* arg, const gpr_thd_options* options) { HANDLE handle; struct thd_info* info = (struct thd_info*)gpr_malloc(sizeof(*info)); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 62223fda5b..fae77843f0 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -768,7 +768,7 @@ extern gpr_stats_inc_type gpr_stats_inc_import; typedef intptr_t(*gpr_stats_read_type)(const gpr_stats_counter* c); extern gpr_stats_read_type gpr_stats_read_import; #define gpr_stats_read gpr_stats_read_import -typedef int(*gpr_thd_new_type)(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, const gpr_thd_options* options); +typedef int(*gpr_thd_new_type)(gpr_thd_id* t, const char* thd_name, void (*thd_body)(void* arg), void* arg, const gpr_thd_options* options); extern gpr_thd_new_type gpr_thd_new_import; #define gpr_thd_new gpr_thd_new_import typedef gpr_thd_options(*gpr_thd_options_default_type)(void); |