From af5c54de9cdf3a8ac27aa428571d98a93f32cc1f Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Wed, 29 Nov 2017 16:25:10 -0800 Subject: [PATCH 01/10] Add thread naming support on platforms that support it. As a client of grpc I want to be aware of which threads are being created by grpc, and giving them recognizable names makes it significantly easier to diagnose what is going on in my programs. This provides thread names for macOS and Linux. Adding support for other platforms should be easy for platform specialists. --- include/grpc/impl/codegen/port_platform.h | 3 +++ include/grpc/support/thd.h | 5 ++++- src/core/lib/iomgr/ev_poll_posix.cc | 2 +- src/core/lib/iomgr/executor.cc | 8 ++++---- src/core/lib/iomgr/timer_manager.cc | 2 +- src/core/lib/support/thd_posix.cc | 19 +++++++++++++++++-- src/core/lib/support/thd_windows.cc | 3 ++- test/core/bad_client/bad_client.cc | 2 +- test/core/end2end/bad_server_response_test.cc | 2 +- .../end2end/fixtures/http_proxy_fixture.cc | 3 ++- test/core/end2end/fixtures/proxy.cc | 3 ++- test/core/end2end/tests/connectivity.cc | 3 ++- test/core/handshake/client_ssl.cc | 3 ++- test/core/handshake/server_ssl_common.cc | 3 ++- test/core/iomgr/combiner_test.cc | 3 ++- test/core/iomgr/resolve_address_posix_test.cc | 2 +- test/core/iomgr/wakeup_fd_cv_test.cc | 10 +++++----- test/core/support/arena_test.cc | 3 ++- test/core/support/cpu_test.cc | 2 +- test/core/support/mpscq_test.cc | 9 ++++++--- test/core/support/spinlock_test.cc | 3 ++- test/core/support/sync_test.cc | 4 ++-- test/core/support/thd_test.cc | 5 +++-- test/core/support/tls_test.cc | 2 +- .../completion_queue_threading_test.cc | 5 +++-- .../surface/concurrent_connectivity_test.cc | 16 ++++++++++------ .../surface/sequential_connectivity_test.cc | 3 ++- 27 files changed, 84 insertions(+), 44 deletions(-) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 1906886d5e2..0c87aef27d7 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -166,6 +166,7 @@ #define GPR_POSIX_SYNC 1 #define GPR_POSIX_TIME 1 #define GPR_GETPID_IN_UNISTD_H 1 +#define GPR_LINUX_PTHREAD_NAME 1 #ifdef _LP64 #define GPR_ARCH_64 1 #else /* _LP64 */ @@ -195,6 +196,7 @@ #else /* __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_7 */ #define GPR_CPU_POSIX 1 #define GPR_GCC_TLS 1 +#define GPR_APPLE_PTHREAD_NAME 1 #endif #else /* __MAC_OS_X_VERSION_MIN_REQUIRED */ #define GPR_CPU_POSIX 1 @@ -236,6 +238,7 @@ #define GPR_POSIX_TIME 1 #define GPR_GETPID_IN_UNISTD_H 1 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 +#define GPR_BSD_PTHREAD_NAME 1 #ifdef _LP64 #define GPR_ARCH_64 1 #else /* _LP64 */ diff --git a/include/grpc/support/thd.h b/include/grpc/support/thd.h index 225d9d6c755..e9444e88c9e 100644 --- a/include/grpc/support/thd.h +++ b/include/grpc/support/thd.h @@ -42,9 +42,12 @@ typedef struct { /** Create a new thread running (*thd_body)(arg) and place its thread identifier in *t, and return true. If there are insufficient resources, return false. + thd_name is the name of the thread for identification purposes on platforms + that support thread naming. If options==NULL, default options are used. The thread is immediately runnable, and exits when (*thd_body)() returns. */ -GPRAPI int gpr_thd_new(gpr_thd_id* t, void (*thd_body)(void* arg), void* arg, +GPRAPI int gpr_thd_new(gpr_thd_id* t, const char* thd_name, + void (*thd_body)(void* arg), void* arg, const gpr_thd_options* options); /** Return a gpr_thd_options struct with all fields set to defaults. */ diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 8659559f78a..7f701b2fb78 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, "gpr_poller", &run_poll, pargs, &opt)); return pargs; } diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index d8a195f0108..5c32ca3b360 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, "gpr_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 dac74aea24e..0e68637fa41 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, "gpr_timer", timer_thread, ct, &opt); gpr_mu_unlock(&g_mu); } diff --git a/src/core/lib/support/thd_posix.cc b/src/core/lib/support/thd_posix.cc index 02e3846be19..ae31a179908 100644 --- a/src/core/lib/support/thd_posix.cc +++ b/src/core/lib/support/thd_posix.cc @@ -33,17 +33,31 @@ struct thd_arg { void (*body)(void* arg); /* body of a thread */ void* arg; /* argument to a thread */ + const char* name; /* name of thread */ }; /* Body of every thread started via gpr_thd_new. */ static void* thread_body(void* v) { struct thd_arg a = *(struct thd_arg*)v; free(v); + if (a.name != NULL) { +#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]; + strncpy(buf, a.name, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; + pthread_setname_np(pthread_self(), buf); +#endif // GPR_APPLE_PTHREAD_NAME + } (*a.body)(a.arg); 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; @@ -54,7 +68,8 @@ 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; + GPR_ASSERT(pthread_attr_init(&attr) == 0); if (gpr_thd_options_is_detached(options)) { GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == diff --git a/src/core/lib/support/thd_windows.cc b/src/core/lib/support/thd_windows.cc index 5bda7f440c4..b54d0b6c627 100644 --- a/src/core/lib/support/thd_windows.cc +++ b/src/core/lib/support/thd_windows.cc @@ -63,7 +63,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/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index c19b7bdf40a..99e61b0c5f2 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -128,7 +128,7 @@ void grpc_run_bad_client_test( GPR_ASSERT(grpc_server_has_open_connections(a.server)); /* Start validator */ - gpr_thd_new(&id, thd_func, &a, nullptr); + gpr_thd_new(&id, "gpr_bad_client", thd_func, &a, nullptr); grpc_slice_buffer_init(&outgoing); grpc_slice_buffer_add(&outgoing, slice); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index b0c6ae926ec..566fd129154 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -262,7 +262,7 @@ static void poll_server_until_read_done(test_tcp_server* server, poll_args* pa = (poll_args*)gpr_malloc(sizeof(*pa)); pa->server = server; pa->signal_when_done = signal_when_done; - gpr_thd_new(&id, actually_poll_server, pa, nullptr); + gpr_thd_new(&id, "gpr_poll_server", actually_poll_server, pa, nullptr); } static void run_test(const char* response_payload, diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index ac0c953a79f..25d8983503a 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -529,7 +529,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( // Start proxy thread. gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt)); + GPR_ASSERT(gpr_thd_new(&proxy->thd, "gpr_http_proxy", thread_main, proxy, + &opt)); return proxy; } diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index 2fab62b721b..6bbb1f4d1dd 100644 --- a/test/core/end2end/fixtures/proxy.cc +++ b/test/core/end2end/fixtures/proxy.cc @@ -98,7 +98,8 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, grpc_call_details_init(&proxy->new_call_details); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt)); + GPR_ASSERT(gpr_thd_new(&proxy->thd, "gpr_end2end_proxy", thread_main, proxy, + &opt)); request_call(proxy); diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc index 2ea4ca81f58..6477dcdd69d 100644 --- a/test/core/end2end/tests/connectivity.cc +++ b/test/core/end2end/tests/connectivity.cc @@ -68,7 +68,8 @@ static void test_connectivity(grpc_end2end_test_config config) { ce.cq = f.cq; gpr_event_init(&ce.started); gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT(gpr_thd_new(&thdid, child_thread, &ce, &thdopt)); + GPR_ASSERT(gpr_thd_new(&thdid, "gpr_connectivity", child_thread, &ce, + &thdopt)); gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC)); diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index 2b149a73b33..21147ef445e 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -231,7 +231,8 @@ static bool client_ssl_test(char* server_alpn_preferred) { gpr_thd_id thdid; gpr_thd_options_set_joinable(&thdopt); server_args args = {server_socket, server_alpn_preferred}; - GPR_ASSERT(gpr_thd_new(&thdid, server_thread, &args, &thdopt)); + GPR_ASSERT(gpr_thd_new(&thdid, "gpr_client_ssl_test", server_thread, &args, + &thdopt)); // Load key pair and establish client SSL credentials. grpc_ssl_pem_key_cert_pair pem_key_cert_pair; diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index 599b2814e0c..9b06d31ab27 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -137,7 +137,8 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, gpr_thd_options thdopt = gpr_thd_options_default(); gpr_thd_id thdid; gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT(gpr_thd_new(&thdid, server_thread, &port, &thdopt)); + GPR_ASSERT(gpr_thd_new(&thdid, "gpr_ssl_test", server_thread, &port, + &thdopt)); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 146a6bd5530..8c97d8a6ef5 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -112,7 +112,8 @@ static void test_execute_many(void) { ta[i].ctr = 0; ta[i].lock = lock; gpr_event_init(&ta[i].done); - GPR_ASSERT(gpr_thd_new(&thds[i], execute_many_loop, &ta[i], &options)); + GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_execute_many", execute_many_loop, + &ta[i], &options)); } for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { GPR_ASSERT(gpr_event_wait(&ta[i].done, diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index 1a5eb9ace14..ea70dab89ef 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -104,7 +104,7 @@ static void actually_poll(void* argsp) { static void poll_pollset_until_request_done(args_struct* args) { gpr_atm_rel_store(&args->done_atm, 0); gpr_thd_id id; - gpr_thd_new(&id, actually_poll, args, nullptr); + gpr_thd_new(&id, "gpr_poll_pollset", actually_poll, args, nullptr); } static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc index dc1d77a0abc..9d761712e75 100644 --- a/test/core/iomgr/wakeup_fd_cv_test.cc +++ b/test/core/iomgr/wakeup_fd_cv_test.cc @@ -138,7 +138,7 @@ void test_poll_cv_trigger(void) { opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&t_id, &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); // Wakeup wakeup_fd not listening for events GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd1) == GRPC_ERROR_NONE); @@ -154,7 +154,7 @@ void test_poll_cv_trigger(void) { // Pollin on socket fd pargs.timeout = -1; pargs.result = -2; - gpr_thd_new(&t_id, &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); trigger_socket_event(); gpr_thd_join(t_id); GPR_ASSERT(pargs.result == 1); @@ -168,7 +168,7 @@ void test_poll_cv_trigger(void) { // Pollin on wakeup fd reset_socket_event(); pargs.result = -2; - gpr_thd_new(&t_id, &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE); gpr_thd_join(t_id); @@ -182,7 +182,7 @@ void test_poll_cv_trigger(void) { // Pollin on wakeupfd before poll() pargs.result = -2; - gpr_thd_new(&t_id, &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); gpr_thd_join(t_id); GPR_ASSERT(pargs.result == 1); @@ -199,7 +199,7 @@ void test_poll_cv_trigger(void) { reset_socket_event(); GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd1) == GRPC_ERROR_NONE); GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd2) == GRPC_ERROR_NONE); - gpr_thd_new(&t_id, &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); gpr_thd_join(t_id); GPR_ASSERT(pargs.result == 0); diff --git a/test/core/support/arena_test.cc b/test/core/support/arena_test.cc index 244d860639f..4e11652318d 100644 --- a/test/core/support/arena_test.cc +++ b/test/core/support/arena_test.cc @@ -100,7 +100,8 @@ static void concurrent_test(void) { for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) { gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&thds[i], concurrent_test_body, &args, &opt); + gpr_thd_new(&thds[i], "gpr_concurrent_test", concurrent_test_body, &args, + &opt); } gpr_event_set(&args.ev_start, (void*)1); diff --git a/test/core/support/cpu_test.cc b/test/core/support/cpu_test.cc index 1783ec3c60a..db94b8f1c43 100644 --- a/test/core/support/cpu_test.cc +++ b/test/core/support/cpu_test.cc @@ -110,7 +110,7 @@ static void cpu_test(void) { gpr_cv_init(&ct.done_cv); ct.is_done = 0; for (i = 0; i < ct.ncores * 3; i++) { - GPR_ASSERT(gpr_thd_new(&thd, &worker_thread, &ct, nullptr)); + GPR_ASSERT(gpr_thd_new(&thd, "gpr_cpu_test", &worker_thread, &ct, nullptr)); } gpr_mu_lock(&ct.mu); while (!ct.is_done) { diff --git a/test/core/support/mpscq_test.cc b/test/core/support/mpscq_test.cc index 50ff8174f69..026b045b0fd 100644 --- a/test/core/support/mpscq_test.cc +++ b/test/core/support/mpscq_test.cc @@ -85,7 +85,8 @@ static void test_mt(void) { ta[i].ctr = 0; ta[i].q = &q; ta[i].start = &start; - GPR_ASSERT(gpr_thd_new(&thds[i], test_thread, &ta[i], &options)); + GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_test_md", test_thread, &ta[i], + &options)); } size_t num_done = 0; size_t spins = 0; @@ -156,7 +157,8 @@ static void test_mt_multipop(void) { ta[i].ctr = 0; ta[i].q = &q; ta[i].start = &start; - GPR_ASSERT(gpr_thd_new(&thds[i], test_thread, &ta[i], &options)); + GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_multipop_test", test_thread, &ta[i], + &options)); } pull_args pa; pa.ta = ta; @@ -169,7 +171,8 @@ static void test_mt_multipop(void) { for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) { gpr_thd_options options = gpr_thd_options_default(); gpr_thd_options_set_joinable(&options); - GPR_ASSERT(gpr_thd_new(&pull_thds[i], pull_thread, &pa, &options)); + GPR_ASSERT(gpr_thd_new(&pull_thds[i], "gpr_multipop_pull", pull_thread, &pa, + &options)); } gpr_event_set(&start, (void*)1); for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) { diff --git a/test/core/support/spinlock_test.cc b/test/core/support/spinlock_test.cc index 3639802cd7e..1658c5c5f1a 100644 --- a/test/core/support/spinlock_test.cc +++ b/test/core/support/spinlock_test.cc @@ -67,7 +67,8 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) { for (i = 0; i != m->thread_count; i++) { gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&m->threads[i], body, m, &opt)); + GPR_ASSERT(gpr_thd_new(&m->threads[i], "gpr_create_threads", body, m, + &opt)); } } diff --git a/test/core/support/sync_test.cc b/test/core/support/sync_test.cc index 86e78ce0b51..de53742dd80 100644 --- a/test/core/support/sync_test.cc +++ b/test/core/support/sync_test.cc @@ -189,7 +189,7 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) { gpr_thd_id id; int i; for (i = 0; i != m->threads; i++) { - GPR_ASSERT(gpr_thd_new(&id, body, m, nullptr)); + GPR_ASSERT(gpr_thd_new(&id, "gpr_create_threads", body, m, nullptr)); } } @@ -244,7 +244,7 @@ static void test(const char* name, void (*body)(void* m), m = test_new(10, iterations, incr_step); if (extra != nullptr) { gpr_thd_id id; - GPR_ASSERT(gpr_thd_new(&id, extra, m, nullptr)); + GPR_ASSERT(gpr_thd_new(&id, name, extra, m, nullptr)); m->done++; /* one more thread to wait for */ } test_create_threads(m, body); diff --git a/test/core/support/thd_test.cc b/test/core/support/thd_test.cc index 34befd80d18..50702c4ae7e 100644 --- a/test/core/support/thd_test.cc +++ b/test/core/support/thd_test.cc @@ -74,7 +74,7 @@ static void test(void) { t.n = NUM_THREADS; t.is_done = 0; for (i = 0; i < NUM_THREADS; i++) { - GPR_ASSERT(gpr_thd_new(&thd, &thd_body, &t, nullptr)); + GPR_ASSERT(gpr_thd_new(&thd, "gpr_thread_test", &thd_body, &t, nullptr)); } gpr_mu_lock(&t.mu); while (!t.is_done) { @@ -84,7 +84,8 @@ static void test(void) { GPR_ASSERT(t.n == 0); gpr_thd_options_set_joinable(&options); for (i = 0; i < NUM_THREADS; i++) { - GPR_ASSERT(gpr_thd_new(&thds[i], &thd_body_joinable, nullptr, &options)); + GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_thread_test_joinable", + &thd_body_joinable, nullptr, &options)); } for (i = 0; i < NUM_THREADS; i++) { gpr_thd_join(thds[i]); diff --git a/test/core/support/tls_test.cc b/test/core/support/tls_test.cc index 0f64d2ee7c8..2a560a4df37 100644 --- a/test/core/support/tls_test.cc +++ b/test/core/support/tls_test.cc @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) { gpr_thd_options_set_joinable(&opt); for (i = 0; i < NUM_THREADS; i++) { - gpr_thd_new(&threads[i], thd_body, nullptr, &opt); + gpr_thd_new(&threads[i], "gpr_tls_test", thd_body, nullptr, &opt); } for (i = 0; i < NUM_THREADS; i++) { gpr_thd_join(threads[i]); diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index af54e00c4a2..17e185d236e 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -96,7 +96,8 @@ static void test_too_many_plucks(void) { } thread_states[i].cc = cc; thread_states[i].tag = tags[i]; - gpr_thd_new(thread_ids + i, pluck_one, thread_states + i, &thread_options); + gpr_thd_new(thread_ids + i, "gpr_test_pluck", pluck_one, thread_states + i, + &thread_options); } /* wait until all other threads are plucking */ @@ -233,7 +234,7 @@ static void test_threading(size_t producers, size_t consumers) { options[i].events_triggered = 0; options[i].cc = cc; options[i].id = optid++; - GPR_ASSERT(gpr_thd_new(&id, + GPR_ASSERT(gpr_thd_new(&id, i < producers ? "gpr_producer" : "gpr_consumer", i < producers ? producer_thread : consumer_thread, options + i, nullptr)); gpr_event_wait(&options[i].on_started, ten_seconds_time()); diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 8fa15ab3313..50bea0aee13 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -180,7 +180,8 @@ int run_concurrent_connectivity_test() { /* First round, no server */ gpr_log(GPR_DEBUG, "Wave 1"); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], create_loop_destroy, localhost, &options); + gpr_thd_new(&threads[i], "gpr_wave_1", create_loop_destroy, localhost, + &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { gpr_thd_join(threads[i]); @@ -196,10 +197,11 @@ int run_concurrent_connectivity_test() { args.cq = grpc_completion_queue_create_for_next(nullptr); grpc_server_register_completion_queue(args.server, args.cq, nullptr); grpc_server_start(args.server); - gpr_thd_new(&server, server_thread, &args, &options); + gpr_thd_new(&server, "gpr_wave_2_server", server_thread, &args, &options); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], create_loop_destroy, args.addr, &options); + gpr_thd_new(&threads[i], "gpr_wave_2", create_loop_destroy, args.addr, + &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { gpr_thd_join(threads[i]); @@ -216,11 +218,12 @@ int run_concurrent_connectivity_test() { args.pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args.pollset, &args.mu); gpr_event_init(&args.ready); - gpr_thd_new(&server, bad_server_thread, &args, &options); + gpr_thd_new(&server, "gpr_wave_3_server", bad_server_thread, &args, &options); gpr_event_wait(&args.ready, gpr_inf_future(GPR_CLOCK_MONOTONIC)); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], create_loop_destroy, args.addr, &options); + gpr_thd_new(&threads[i], "gpr_wave_3", create_loop_destroy, args.addr, + &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { gpr_thd_join(threads[i]); @@ -278,7 +281,8 @@ int run_concurrent_watches_with_short_timeouts_test() { gpr_thd_options_set_joinable(&options); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], watches_with_short_timeouts, localhost, &options); + gpr_thd_new(&threads[i], "gpr_watches_with_short_timeouts", + watches_with_short_timeouts, localhost, &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { gpr_thd_join(threads[i]); diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index 015db92cb03..82225f7a892 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -70,7 +70,8 @@ static void run_test(const test_fixture* fixture) { gpr_thd_id server_thread; gpr_thd_options thdopt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&thdopt); - gpr_thd_new(&server_thread, server_thread_func, &sta, &thdopt); + gpr_thd_new(&server_thread, "gpr_server_thread", server_thread_func, &sta, + &thdopt); grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* channels[NUM_CONNECTIONS]; From 8a631a2b052330b169fd52d7fb7efea2c149d3a5 Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Wed, 29 Nov 2017 16:31:14 -0800 Subject: [PATCH 02/10] Remove unused BSD thread name macro --- include/grpc/impl/codegen/port_platform.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 0c87aef27d7..b22988a438c 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -238,7 +238,6 @@ #define GPR_POSIX_TIME 1 #define GPR_GETPID_IN_UNISTD_H 1 #define GPR_SUPPORT_CHANNELS_FROM_FD 1 -#define GPR_BSD_PTHREAD_NAME 1 #ifdef _LP64 #define GPR_ARCH_64 1 #else /* _LP64 */ From da341bcb8969264800f63eac718e5b483aba9896 Mon Sep 17 00:00:00 2001 From: Dave MacLachlan Date: Thu, 30 Nov 2017 12:48:22 -0800 Subject: [PATCH 03/10] Fix up review comments --- src/core/lib/iomgr/ev_poll_posix.cc | 2 +- src/core/lib/iomgr/executor.cc | 2 +- src/core/lib/iomgr/timer_manager.cc | 2 +- src/core/lib/support/thd_posix.cc | 11 ++++++----- test/core/bad_client/bad_client.cc | 2 +- test/core/end2end/bad_server_response_test.cc | 2 +- test/core/end2end/fixtures/http_proxy_fixture.cc | 2 +- test/core/end2end/fixtures/proxy.cc | 2 +- test/core/end2end/tests/connectivity.cc | 2 +- test/core/handshake/client_ssl.cc | 2 +- test/core/handshake/server_ssl_common.cc | 2 +- test/core/iomgr/combiner_test.cc | 2 +- test/core/iomgr/resolve_address_posix_test.cc | 2 +- test/core/iomgr/wakeup_fd_cv_test.cc | 10 +++++----- test/core/support/arena_test.cc | 2 +- test/core/support/cpu_test.cc | 3 ++- test/core/support/mpscq_test.cc | 8 ++++---- test/core/support/spinlock_test.cc | 2 +- test/core/support/sync_test.cc | 2 +- test/core/support/thd_test.cc | 4 ++-- test/core/support/tls_test.cc | 2 +- test/core/surface/completion_queue_threading_test.cc | 5 +++-- test/core/surface/concurrent_connectivity_test.cc | 12 ++++++------ test/core/surface/sequential_connectivity_test.cc | 3 +-- 24 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index 7f701b2fb78..e32e1ba42a9 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, "gpr_poller", &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 5c32ca3b360..fabdbdf934f 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -104,7 +104,7 @@ 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, "gpr_executor", executor_thread, + gpr_thd_new(&g_thread_state[0].id, "grpc_executor", executor_thread, &g_thread_state[0], &opt); } else { if (cur_threads == 0) return; diff --git a/src/core/lib/iomgr/timer_manager.cc b/src/core/lib/iomgr/timer_manager.cc index 0e68637fa41..87ed0e05dcd 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, "gpr_timer", 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/support/thd_posix.cc b/src/core/lib/support/thd_posix.cc index ae31a179908..fb308801740 100644 --- a/src/core/lib/support/thd_posix.cc +++ b/src/core/lib/support/thd_posix.cc @@ -33,22 +33,23 @@ struct thd_arg { void (*body)(void* arg); /* body of a thread */ void* arg; /* argument to a thread */ - const char* name; /* name of thread */ + const char* name; /* name of thread. Can be nullptr. */ }; /* Body of every thread started via gpr_thd_new. */ static void* thread_body(void* v) { struct thd_arg a = *(struct thd_arg*)v; free(v); - if (a.name != NULL) { + 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]; - strncpy(buf, a.name, sizeof(buf) - 1); - buf[sizeof(buf) - 1] = '\0'; + 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 } @@ -69,7 +70,7 @@ int gpr_thd_new(gpr_thd_id* t, const char* thd_name, a->body = thd_body; a->arg = arg; a->name = thd_name; - + GPR_ASSERT(pthread_attr_init(&attr) == 0); if (gpr_thd_options_is_detached(options)) { GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc index 99e61b0c5f2..443886751ce 100644 --- a/test/core/bad_client/bad_client.cc +++ b/test/core/bad_client/bad_client.cc @@ -128,7 +128,7 @@ void grpc_run_bad_client_test( GPR_ASSERT(grpc_server_has_open_connections(a.server)); /* Start validator */ - gpr_thd_new(&id, "gpr_bad_client", thd_func, &a, nullptr); + gpr_thd_new(&id, "grpc_bad_client", thd_func, &a, nullptr); grpc_slice_buffer_init(&outgoing); grpc_slice_buffer_add(&outgoing, slice); diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc index 566fd129154..0fdb637eadd 100644 --- a/test/core/end2end/bad_server_response_test.cc +++ b/test/core/end2end/bad_server_response_test.cc @@ -262,7 +262,7 @@ static void poll_server_until_read_done(test_tcp_server* server, poll_args* pa = (poll_args*)gpr_malloc(sizeof(*pa)); pa->server = server; pa->signal_when_done = signal_when_done; - gpr_thd_new(&id, "gpr_poll_server", actually_poll_server, pa, nullptr); + gpr_thd_new(&id, "grpc_poll_server", actually_poll_server, pa, nullptr); } static void run_test(const char* response_payload, diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 25d8983503a..1c33e578ec5 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -529,7 +529,7 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( // Start proxy thread. gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&proxy->thd, "gpr_http_proxy", thread_main, proxy, + GPR_ASSERT(gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy, &opt)); return proxy; } diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index 6bbb1f4d1dd..00fc9fecbee 100644 --- a/test/core/end2end/fixtures/proxy.cc +++ b/test/core/end2end/fixtures/proxy.cc @@ -98,7 +98,7 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, grpc_call_details_init(&proxy->new_call_details); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&proxy->thd, "gpr_end2end_proxy", thread_main, proxy, + GPR_ASSERT(gpr_thd_new(&proxy->thd, "grpc_end2end_proxy", thread_main, proxy, &opt)); request_call(proxy); diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc index 6477dcdd69d..7fab55cb3a5 100644 --- a/test/core/end2end/tests/connectivity.cc +++ b/test/core/end2end/tests/connectivity.cc @@ -68,7 +68,7 @@ static void test_connectivity(grpc_end2end_test_config config) { ce.cq = f.cq; gpr_event_init(&ce.started); gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT(gpr_thd_new(&thdid, "gpr_connectivity", child_thread, &ce, + GPR_ASSERT(gpr_thd_new(&thdid, "grpc_connectivity", child_thread, &ce, &thdopt)); gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC)); diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc index 21147ef445e..2302e3da2f9 100644 --- a/test/core/handshake/client_ssl.cc +++ b/test/core/handshake/client_ssl.cc @@ -231,7 +231,7 @@ static bool client_ssl_test(char* server_alpn_preferred) { gpr_thd_id thdid; gpr_thd_options_set_joinable(&thdopt); server_args args = {server_socket, server_alpn_preferred}; - GPR_ASSERT(gpr_thd_new(&thdid, "gpr_client_ssl_test", server_thread, &args, + GPR_ASSERT(gpr_thd_new(&thdid, "grpc_client_ssl_test", server_thread, &args, &thdopt)); // Load key pair and establish client SSL credentials. diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index 9b06d31ab27..001d4e24cac 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -137,7 +137,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, gpr_thd_options thdopt = gpr_thd_options_default(); gpr_thd_id thdid; gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT(gpr_thd_new(&thdid, "gpr_ssl_test", server_thread, &port, + GPR_ASSERT(gpr_thd_new(&thdid, "grpc_ssl_test", server_thread, &port, &thdopt)); SSL_load_error_strings(); diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc index 8c97d8a6ef5..33d892fa06a 100644 --- a/test/core/iomgr/combiner_test.cc +++ b/test/core/iomgr/combiner_test.cc @@ -112,7 +112,7 @@ static void test_execute_many(void) { ta[i].ctr = 0; ta[i].lock = lock; gpr_event_init(&ta[i].done); - GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_execute_many", execute_many_loop, + GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_execute_many", execute_many_loop, &ta[i], &options)); } for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc index ea70dab89ef..836de423bd8 100644 --- a/test/core/iomgr/resolve_address_posix_test.cc +++ b/test/core/iomgr/resolve_address_posix_test.cc @@ -104,7 +104,7 @@ static void actually_poll(void* argsp) { static void poll_pollset_until_request_done(args_struct* args) { gpr_atm_rel_store(&args->done_atm, 0); gpr_thd_id id; - gpr_thd_new(&id, "gpr_poll_pollset", actually_poll, args, nullptr); + gpr_thd_new(&id, "grpc_poll_pollset", actually_poll, args, nullptr); } static void must_succeed(grpc_exec_ctx* exec_ctx, void* argsp, diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc index 9d761712e75..d4e05bd7ef8 100644 --- a/test/core/iomgr/wakeup_fd_cv_test.cc +++ b/test/core/iomgr/wakeup_fd_cv_test.cc @@ -138,7 +138,7 @@ void test_poll_cv_trigger(void) { opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt); // Wakeup wakeup_fd not listening for events GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd1) == GRPC_ERROR_NONE); @@ -154,7 +154,7 @@ void test_poll_cv_trigger(void) { // Pollin on socket fd pargs.timeout = -1; pargs.result = -2; - gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt); trigger_socket_event(); gpr_thd_join(t_id); GPR_ASSERT(pargs.result == 1); @@ -168,7 +168,7 @@ void test_poll_cv_trigger(void) { // Pollin on wakeup fd reset_socket_event(); pargs.result = -2; - gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt); GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE); gpr_thd_join(t_id); @@ -182,7 +182,7 @@ void test_poll_cv_trigger(void) { // Pollin on wakeupfd before poll() pargs.result = -2; - gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt); gpr_thd_join(t_id); GPR_ASSERT(pargs.result == 1); @@ -199,7 +199,7 @@ void test_poll_cv_trigger(void) { reset_socket_event(); GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd1) == GRPC_ERROR_NONE); GPR_ASSERT(grpc_wakeup_fd_consume_wakeup(&cvfd2) == GRPC_ERROR_NONE); - gpr_thd_new(&t_id, "gpr_background_poll", &background_poll, &pargs, &opt); + gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs, &opt); gpr_thd_join(t_id); GPR_ASSERT(pargs.result == 0); diff --git a/test/core/support/arena_test.cc b/test/core/support/arena_test.cc index 4e11652318d..ada0f438542 100644 --- a/test/core/support/arena_test.cc +++ b/test/core/support/arena_test.cc @@ -100,7 +100,7 @@ static void concurrent_test(void) { for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) { gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&thds[i], "gpr_concurrent_test", concurrent_test_body, &args, + gpr_thd_new(&thds[i], "grpc_concurrent_test", concurrent_test_body, &args, &opt); } diff --git a/test/core/support/cpu_test.cc b/test/core/support/cpu_test.cc index db94b8f1c43..53ce0f948c1 100644 --- a/test/core/support/cpu_test.cc +++ b/test/core/support/cpu_test.cc @@ -110,7 +110,8 @@ static void cpu_test(void) { gpr_cv_init(&ct.done_cv); ct.is_done = 0; for (i = 0; i < ct.ncores * 3; i++) { - GPR_ASSERT(gpr_thd_new(&thd, "gpr_cpu_test", &worker_thread, &ct, nullptr)); + GPR_ASSERT(gpr_thd_new(&thd, "grpc_cpu_test", &worker_thread, &ct, + nullptr)); } gpr_mu_lock(&ct.mu); while (!ct.is_done) { diff --git a/test/core/support/mpscq_test.cc b/test/core/support/mpscq_test.cc index 026b045b0fd..6a9ac4ca2ce 100644 --- a/test/core/support/mpscq_test.cc +++ b/test/core/support/mpscq_test.cc @@ -85,7 +85,7 @@ static void test_mt(void) { ta[i].ctr = 0; ta[i].q = &q; ta[i].start = &start; - GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_test_md", test_thread, &ta[i], + GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_mt_test", test_thread, &ta[i], &options)); } size_t num_done = 0; @@ -157,7 +157,7 @@ static void test_mt_multipop(void) { ta[i].ctr = 0; ta[i].q = &q; ta[i].start = &start; - GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_multipop_test", test_thread, &ta[i], + GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_multipop_test", test_thread, &ta[i], &options)); } pull_args pa; @@ -171,8 +171,8 @@ static void test_mt_multipop(void) { for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) { gpr_thd_options options = gpr_thd_options_default(); gpr_thd_options_set_joinable(&options); - GPR_ASSERT(gpr_thd_new(&pull_thds[i], "gpr_multipop_pull", pull_thread, &pa, - &options)); + GPR_ASSERT(gpr_thd_new(&pull_thds[i], "grpc_multipop_pull", pull_thread, + &pa, &options)); } gpr_event_set(&start, (void*)1); for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) { diff --git a/test/core/support/spinlock_test.cc b/test/core/support/spinlock_test.cc index 1658c5c5f1a..4828ce0c23f 100644 --- a/test/core/support/spinlock_test.cc +++ b/test/core/support/spinlock_test.cc @@ -67,7 +67,7 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) { for (i = 0; i != m->thread_count; i++) { gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&m->threads[i], "gpr_create_threads", body, m, + GPR_ASSERT(gpr_thd_new(&m->threads[i], "grpc_create_threads", body, m, &opt)); } } diff --git a/test/core/support/sync_test.cc b/test/core/support/sync_test.cc index de53742dd80..3f534de8203 100644 --- a/test/core/support/sync_test.cc +++ b/test/core/support/sync_test.cc @@ -189,7 +189,7 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) { gpr_thd_id id; int i; for (i = 0; i != m->threads; i++) { - GPR_ASSERT(gpr_thd_new(&id, "gpr_create_threads", body, m, nullptr)); + GPR_ASSERT(gpr_thd_new(&id, "grpc_create_threads", body, m, nullptr)); } } diff --git a/test/core/support/thd_test.cc b/test/core/support/thd_test.cc index 50702c4ae7e..b755bf18f37 100644 --- a/test/core/support/thd_test.cc +++ b/test/core/support/thd_test.cc @@ -74,7 +74,7 @@ static void test(void) { t.n = NUM_THREADS; t.is_done = 0; for (i = 0; i < NUM_THREADS; i++) { - GPR_ASSERT(gpr_thd_new(&thd, "gpr_thread_test", &thd_body, &t, nullptr)); + GPR_ASSERT(gpr_thd_new(&thd, "grpc_thread_test", &thd_body, &t, nullptr)); } gpr_mu_lock(&t.mu); while (!t.is_done) { @@ -84,7 +84,7 @@ static void test(void) { GPR_ASSERT(t.n == 0); gpr_thd_options_set_joinable(&options); for (i = 0; i < NUM_THREADS; i++) { - GPR_ASSERT(gpr_thd_new(&thds[i], "gpr_thread_test_joinable", + GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_joinable_thread_test", &thd_body_joinable, nullptr, &options)); } for (i = 0; i < NUM_THREADS; i++) { diff --git a/test/core/support/tls_test.cc b/test/core/support/tls_test.cc index 2a560a4df37..743b10f0907 100644 --- a/test/core/support/tls_test.cc +++ b/test/core/support/tls_test.cc @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) { gpr_thd_options_set_joinable(&opt); for (i = 0; i < NUM_THREADS; i++) { - gpr_thd_new(&threads[i], "gpr_tls_test", thd_body, nullptr, &opt); + gpr_thd_new(&threads[i], "grpc_tls_test", thd_body, nullptr, &opt); } for (i = 0; i < NUM_THREADS; i++) { gpr_thd_join(threads[i]); diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 17e185d236e..42c8aee767b 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -96,7 +96,7 @@ static void test_too_many_plucks(void) { } thread_states[i].cc = cc; thread_states[i].tag = tags[i]; - gpr_thd_new(thread_ids + i, "gpr_test_pluck", pluck_one, thread_states + i, + gpr_thd_new(thread_ids + i, "grpc_pluck_test", pluck_one, thread_states + i, &thread_options); } @@ -234,7 +234,8 @@ static void test_threading(size_t producers, size_t consumers) { options[i].events_triggered = 0; options[i].cc = cc; options[i].id = optid++; - GPR_ASSERT(gpr_thd_new(&id, i < producers ? "gpr_producer" : "gpr_consumer", + GPR_ASSERT(gpr_thd_new(&id, + i < producers ? "grpc_producer" : "grpc_consumer", i < producers ? producer_thread : consumer_thread, options + i, nullptr)); gpr_event_wait(&options[i].on_started, ten_seconds_time()); diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 50bea0aee13..e750d09495a 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -180,7 +180,7 @@ int run_concurrent_connectivity_test() { /* First round, no server */ gpr_log(GPR_DEBUG, "Wave 1"); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "gpr_wave_1", create_loop_destroy, localhost, + gpr_thd_new(&threads[i], "grpc_wave_1", create_loop_destroy, localhost, &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { @@ -197,10 +197,10 @@ int run_concurrent_connectivity_test() { args.cq = grpc_completion_queue_create_for_next(nullptr); grpc_server_register_completion_queue(args.server, args.cq, nullptr); grpc_server_start(args.server); - gpr_thd_new(&server, "gpr_wave_2_server", server_thread, &args, &options); + gpr_thd_new(&server, "grpc_wave_2_server", server_thread, &args, &options); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "gpr_wave_2", create_loop_destroy, args.addr, + gpr_thd_new(&threads[i], "grpc_wave_2", create_loop_destroy, args.addr, &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { @@ -218,11 +218,11 @@ int run_concurrent_connectivity_test() { args.pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args.pollset, &args.mu); gpr_event_init(&args.ready); - gpr_thd_new(&server, "gpr_wave_3_server", bad_server_thread, &args, &options); + gpr_thd_new(&server, "grpc_wave_3_server", bad_server_thread, &args, &options); gpr_event_wait(&args.ready, gpr_inf_future(GPR_CLOCK_MONOTONIC)); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "gpr_wave_3", create_loop_destroy, args.addr, + gpr_thd_new(&threads[i], "grpc_wave_3", create_loop_destroy, args.addr, &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { @@ -281,7 +281,7 @@ int run_concurrent_watches_with_short_timeouts_test() { gpr_thd_options_set_joinable(&options); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "gpr_watches_with_short_timeouts", + gpr_thd_new(&threads[i], "grpc_short_watches", watches_with_short_timeouts, localhost, &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index 82225f7a892..11d0aa705d9 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -70,8 +70,7 @@ static void run_test(const test_fixture* fixture) { gpr_thd_id server_thread; gpr_thd_options thdopt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&thdopt); - gpr_thd_new(&server_thread, "gpr_server_thread", server_thread_func, &sta, - &thdopt); + gpr_thd_new(&server_thread, "grpc_server", server_thread_func, &sta, &thdopt); grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* channels[NUM_CONNECTIONS]; From a3a4f39121ba2f367be704a89c80f611fdd1584f Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Mon, 4 Dec 2017 13:02:12 -0800 Subject: [PATCH 04/10] Update ev_epollsig_linux_test.cc --- test/core/iomgr/ev_epollsig_linux_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc index ac8b2f43d16..94f387164a8 100644 --- a/test/core/iomgr/ev_epollsig_linux_test.cc +++ b/test/core/iomgr/ev_epollsig_linux_test.cc @@ -269,7 +269,7 @@ static void test_threading(void) { for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) { gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - gpr_thd_new(&thds[i], test_threading_loop, &shared, &opt); + gpr_thd_new(&thds[i], "test_thread", test_threading_loop, &shared, &opt); } grpc_wakeup_fd fd; GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&fd))); From 33dd7f07ff9ea9a6027f8aa3340c496df7d7d603 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Mon, 4 Dec 2017 15:26:43 -0800 Subject: [PATCH 05/10] Add thread name --- test/core/network_benchmarks/low_level_ping_pong.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc index 2ae9a45d7c6..96b0745f529 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.cc +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -583,7 +583,7 @@ static int run_benchmark(const char* socket_type, thread_args* client_args, gpr_log(GPR_INFO, "Starting test %s %s %zu", client_args->strategy_name, socket_type, client_args->msg_size); - gpr_thd_new(&tid, server_thread_wrap, server_args, nullptr); + gpr_thd_new(&tid, "server_thread", server_thread_wrap, server_args, nullptr); client_thread(client_args); return 0; } From 19988c6c7ebfdbd239d87907519851957b34262f Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Mon, 4 Dec 2017 15:28:35 -0800 Subject: [PATCH 06/10] clang-format --- src/core/lib/support/thd_posix.cc | 2 +- test/core/end2end/fixtures/http_proxy_fixture.cc | 4 ++-- test/core/end2end/fixtures/proxy.cc | 4 ++-- test/core/end2end/tests/connectivity.cc | 4 ++-- test/core/handshake/server_ssl_common.cc | 4 ++-- test/core/support/cpu_test.cc | 4 ++-- test/core/support/mpscq_test.cc | 4 ++-- test/core/support/spinlock_test.cc | 4 ++-- test/core/surface/completion_queue_threading_test.cc | 2 +- test/core/surface/concurrent_connectivity_test.cc | 7 ++++--- 10 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/core/lib/support/thd_posix.cc b/src/core/lib/support/thd_posix.cc index 339c40fe4c6..f0ed48dbfc2 100644 --- a/src/core/lib/support/thd_posix.cc +++ b/src/core/lib/support/thd_posix.cc @@ -62,7 +62,7 @@ static void* thread_body(void* v) { strncpy(buf, a.name, buf_len); buf[buf_len] = '\0'; pthread_setname_np(pthread_self(), buf); -#endif // GPR_APPLE_PTHREAD_NAME +#endif // GPR_APPLE_PTHREAD_NAME } (*a.body)(a.arg); dec_thd_count(); diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 1c33e578ec5..3f7806942be 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -529,8 +529,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( // Start proxy thread. gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy, - &opt)); + GPR_ASSERT( + gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy, &opt)); return proxy; } diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc index 00fc9fecbee..b1698c804ce 100644 --- a/test/core/end2end/fixtures/proxy.cc +++ b/test/core/end2end/fixtures/proxy.cc @@ -98,8 +98,8 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def, grpc_call_details_init(&proxy->new_call_details); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&proxy->thd, "grpc_end2end_proxy", thread_main, proxy, - &opt)); + GPR_ASSERT( + gpr_thd_new(&proxy->thd, "grpc_end2end_proxy", thread_main, proxy, &opt)); request_call(proxy); diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc index 7fab55cb3a5..da65080bc06 100644 --- a/test/core/end2end/tests/connectivity.cc +++ b/test/core/end2end/tests/connectivity.cc @@ -68,8 +68,8 @@ static void test_connectivity(grpc_end2end_test_config config) { ce.cq = f.cq; gpr_event_init(&ce.started); gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT(gpr_thd_new(&thdid, "grpc_connectivity", child_thread, &ce, - &thdopt)); + GPR_ASSERT( + gpr_thd_new(&thdid, "grpc_connectivity", child_thread, &ce, &thdopt)); gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC)); diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc index 001d4e24cac..0bf453a204a 100644 --- a/test/core/handshake/server_ssl_common.cc +++ b/test/core/handshake/server_ssl_common.cc @@ -137,8 +137,8 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len, gpr_thd_options thdopt = gpr_thd_options_default(); gpr_thd_id thdid; gpr_thd_options_set_joinable(&thdopt); - GPR_ASSERT(gpr_thd_new(&thdid, "grpc_ssl_test", server_thread, &port, - &thdopt)); + GPR_ASSERT( + gpr_thd_new(&thdid, "grpc_ssl_test", server_thread, &port, &thdopt)); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); diff --git a/test/core/support/cpu_test.cc b/test/core/support/cpu_test.cc index 53ce0f948c1..6e04feedaa5 100644 --- a/test/core/support/cpu_test.cc +++ b/test/core/support/cpu_test.cc @@ -110,8 +110,8 @@ static void cpu_test(void) { gpr_cv_init(&ct.done_cv); ct.is_done = 0; for (i = 0; i < ct.ncores * 3; i++) { - GPR_ASSERT(gpr_thd_new(&thd, "grpc_cpu_test", &worker_thread, &ct, - nullptr)); + GPR_ASSERT( + gpr_thd_new(&thd, "grpc_cpu_test", &worker_thread, &ct, nullptr)); } gpr_mu_lock(&ct.mu); while (!ct.is_done) { diff --git a/test/core/support/mpscq_test.cc b/test/core/support/mpscq_test.cc index 6a9ac4ca2ce..1b83f7d5be9 100644 --- a/test/core/support/mpscq_test.cc +++ b/test/core/support/mpscq_test.cc @@ -85,8 +85,8 @@ static void test_mt(void) { ta[i].ctr = 0; ta[i].q = &q; ta[i].start = &start; - GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_mt_test", test_thread, &ta[i], - &options)); + GPR_ASSERT( + gpr_thd_new(&thds[i], "grpc_mt_test", test_thread, &ta[i], &options)); } size_t num_done = 0; size_t spins = 0; diff --git a/test/core/support/spinlock_test.cc b/test/core/support/spinlock_test.cc index 4828ce0c23f..58d5fcd42b9 100644 --- a/test/core/support/spinlock_test.cc +++ b/test/core/support/spinlock_test.cc @@ -67,8 +67,8 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) { for (i = 0; i != m->thread_count; i++) { gpr_thd_options opt = gpr_thd_options_default(); gpr_thd_options_set_joinable(&opt); - GPR_ASSERT(gpr_thd_new(&m->threads[i], "grpc_create_threads", body, m, - &opt)); + GPR_ASSERT( + gpr_thd_new(&m->threads[i], "grpc_create_threads", body, m, &opt)); } } diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc index 42c8aee767b..126d363f839 100644 --- a/test/core/surface/completion_queue_threading_test.cc +++ b/test/core/surface/completion_queue_threading_test.cc @@ -234,7 +234,7 @@ static void test_threading(size_t producers, size_t consumers) { options[i].events_triggered = 0; options[i].cc = cc; options[i].id = optid++; - GPR_ASSERT(gpr_thd_new(&id, + GPR_ASSERT(gpr_thd_new(&id, i < producers ? "grpc_producer" : "grpc_consumer", i < producers ? producer_thread : consumer_thread, options + i, nullptr)); diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index 386eb29cbce..2ff1ca3d799 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -220,7 +220,8 @@ int run_concurrent_connectivity_test() { args.pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(args.pollset, &args.mu); gpr_event_init(&args.ready); - gpr_thd_new(&server, "grpc_wave_3_server", bad_server_thread, &args, &options); + gpr_thd_new(&server, "grpc_wave_3_server", bad_server_thread, &args, + &options); gpr_event_wait(&args.ready, gpr_inf_future(GPR_CLOCK_MONOTONIC)); for (size_t i = 0; i < NUM_THREADS; ++i) { @@ -283,8 +284,8 @@ int run_concurrent_watches_with_short_timeouts_test() { gpr_thd_options_set_joinable(&options); for (size_t i = 0; i < NUM_THREADS; ++i) { - gpr_thd_new(&threads[i], "grpc_short_watches", - watches_with_short_timeouts, localhost, &options); + gpr_thd_new(&threads[i], "grpc_short_watches", watches_with_short_timeouts, + localhost, &options); } for (size_t i = 0; i < NUM_THREADS; ++i) { gpr_thd_join(threads[i]); From 770bf078d517dbaa49eb532bff47566011940375 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 5 Dec 2017 16:09:04 -0600 Subject: [PATCH 07/10] Regen projects and fix more uses of gpr_thd_new --- src/core/lib/profiling/basic_timers.cc | 3 ++- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 2 +- test/cpp/grpclb/grpclb_test.cc | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/lib/profiling/basic_timers.cc b/src/core/lib/profiling/basic_timers.cc index 3ec6280e6b0..8fcb712f6b3 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/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 62223fda5b7..fae77843f03 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); diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index ca846c72fde..67bf5a2bb00 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -703,14 +703,14 @@ static test_fixture setup_test_fixture(int lb_server_update_delay_ms) { tf.lb_backends[i].lb_token_prefix = ""; } setup_server("127.0.0.1", &tf.lb_backends[i]); - gpr_thd_new(&tf.lb_backends[i].tid, fork_backend_server, &tf.lb_backends[i], + gpr_thd_new(&tf.lb_backends[i].tid, "grpclb_backend", fork_backend_server, &tf.lb_backends[i], &options); } tf.lb_server.lb_token_prefix = LB_TOKEN_PREFIX; tf.lb_server.balancer_name = BALANCERS_NAME; setup_server("127.0.0.1", &tf.lb_server); - gpr_thd_new(&tf.lb_server.tid, fork_lb_server, &tf.lb_server, &options); + gpr_thd_new(&tf.lb_server.tid, "grpclb_server", fork_lb_server, &tf.lb_server, &options); setup_client(&tf.lb_server, tf.lb_backends, &tf.client); return tf; } From dba6f847d7db7dbe13fb65988e2c22a698ff7943 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 5 Dec 2017 17:16:35 -0600 Subject: [PATCH 08/10] Update basic_timers.cc --- src/core/lib/profiling/basic_timers.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/profiling/basic_timers.cc b/src/core/lib/profiling/basic_timers.cc index 8fcb712f6b3..87dd4ab120b 100644 --- a/src/core/lib/profiling/basic_timers.cc +++ b/src/core/lib/profiling/basic_timers.cc @@ -204,7 +204,7 @@ 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, "timer_output_thread", - writing_thread, NULL, &options)); + writing_thread, NULL, &options)); atexit(finish_writing); } From 43b8f8a11e8d14f5ad8a7523b770a06a0a554c18 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 5 Dec 2017 17:17:40 -0600 Subject: [PATCH 09/10] Update grpclb_test.cc --- test/cpp/grpclb/grpclb_test.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 67bf5a2bb00..a469fbb7e3b 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -703,14 +703,15 @@ static test_fixture setup_test_fixture(int lb_server_update_delay_ms) { tf.lb_backends[i].lb_token_prefix = ""; } setup_server("127.0.0.1", &tf.lb_backends[i]); - gpr_thd_new(&tf.lb_backends[i].tid, "grpclb_backend", fork_backend_server, &tf.lb_backends[i], - &options); + gpr_thd_new(&tf.lb_backends[i].tid, "grpclb_backend", fork_backend_server, + &tf.lb_backends[i], &options); } tf.lb_server.lb_token_prefix = LB_TOKEN_PREFIX; tf.lb_server.balancer_name = BALANCERS_NAME; setup_server("127.0.0.1", &tf.lb_server); - gpr_thd_new(&tf.lb_server.tid, "grpclb_server", fork_lb_server, &tf.lb_server, &options); + gpr_thd_new(&tf.lb_server.tid, "grpclb_server", fork_lb_server, &tf.lb_server, + &options); setup_client(&tf.lb_server, tf.lb_backends, &tf.client); return tf; } From 30ccc944d659a9314f717c9fff582d917420656a Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 5 Dec 2017 18:30:52 -0600 Subject: [PATCH 10/10] Update port_platform.h --- include/grpc/impl/codegen/port_platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index b22988a438c..5a0ed851111 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -166,7 +166,6 @@ #define GPR_POSIX_SYNC 1 #define GPR_POSIX_TIME 1 #define GPR_GETPID_IN_UNISTD_H 1 -#define GPR_LINUX_PTHREAD_NAME 1 #ifdef _LP64 #define GPR_ARCH_64 1 #else /* _LP64 */ @@ -174,6 +173,7 @@ #endif /* _LP64 */ #ifdef __GLIBC__ #define GPR_POSIX_CRASH_HANDLER 1 +#define GPR_LINUX_PTHREAD_NAME 1 #else /* musl libc */ #define GPR_MUSL_LIBC_COMPAT 1 #endif