aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/iomgr/ev_poll_posix.cc2
-rw-r--r--src/core/lib/iomgr/executor.cc8
-rw-r--r--src/core/lib/iomgr/timer_manager.cc2
-rw-r--r--src/core/lib/profiling/basic_timers.cc3
-rw-r--r--src/core/lib/support/thd_posix.cc18
-rw-r--r--src/core/lib/support/thd_windows.cc3
6 files changed, 27 insertions, 9 deletions
diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc
index 1246b382d5..006e3ddd2f 100644
--- a/src/core/lib/iomgr/ev_poll_posix.cc
+++ b/src/core/lib/iomgr/ev_poll_posix.cc
@@ -1359,7 +1359,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 d9b0c1daf0..b45223ce16 100644
--- a/src/core/lib/iomgr/executor.cc
+++ b/src/core/lib/iomgr/executor.cc
@@ -104,8 +104,8 @@ void grpc_executor_set_threading(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++) {
@@ -261,8 +261,8 @@ static void executor_push(grpc_closure* closure, grpc_error* error,
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 e11e9156c3..8ca6a3c23e 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));