aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2018-02-16 22:59:03 -0800
committerGravatar Vijay Pai <vpai@google.com>2018-02-19 22:39:58 -0800
commitda69355f30ca6863cc07c0aebffc5a14900de265 (patch)
tree83c866fcf54b2c058d452312109175cbb2107865 /test/core
parent5e1298f0a826777b0e5b844328b81216e9c37476 (diff)
C++ize gpr_thread as grpc_core::Thread, make it 2-phase init (construct/Start)
Diffstat (limited to 'test/core')
-rw-r--r--test/core/bad_client/bad_client.cc9
-rw-r--r--test/core/end2end/bad_server_response_test.cc21
-rw-r--r--test/core/end2end/fixtures/h2_census.cc1
-rw-r--r--test/core/end2end/fixtures/h2_compress.cc1
-rw-r--r--test/core/end2end/fixtures/h2_full+pipe.cc1
-rw-r--r--test/core/end2end/fixtures/h2_full+trace.cc1
-rw-r--r--test/core/end2end/fixtures/h2_full+workarounds.cc1
-rw-r--r--test/core/end2end/fixtures/h2_full.cc1
-rw-r--r--test/core/end2end/fixtures/h2_http_proxy.cc1
-rw-r--r--test/core/end2end/fixtures/h2_load_reporting.cc1
-rw-r--r--test/core/end2end/fixtures/h2_proxy.cc1
-rw-r--r--test/core/end2end/fixtures/h2_sockpair+trace.cc1
-rw-r--r--test/core/end2end/fixtures/h2_sockpair.cc1
-rw-r--r--test/core/end2end/fixtures/h2_sockpair_1byte.cc1
-rw-r--r--test/core/end2end/fixtures/h2_uds.cc1
-rw-r--r--test/core/end2end/fixtures/http_proxy_fixture.cc11
-rw-r--r--test/core/end2end/fixtures/inproc.cc1
-rw-r--r--test/core/end2end/fixtures/proxy.cc12
-rw-r--r--test/core/end2end/tests/bad_ping.cc1
-rw-r--r--test/core/end2end/tests/connectivity.cc8
-rw-r--r--test/core/end2end/tests/ping.cc1
-rw-r--r--test/core/gpr/arena_test.cc18
-rw-r--r--test/core/gpr/cpu_test.cc21
-rw-r--r--test/core/gpr/mpscq_test.cc33
-rw-r--r--test/core/gpr/spinlock_test.cc21
-rw-r--r--test/core/gpr/sync_test.cc66
-rw-r--r--test/core/gpr/time_test.cc1
-rw-r--r--test/core/gpr/tls_test.cc23
-rw-r--r--test/core/gprpp/manual_constructor_test.cc1
-rw-r--r--test/core/gprpp/thd_test.cc (renamed from test/core/gpr/thd_test.cc)36
-rw-r--r--test/core/handshake/client_ssl.cc10
-rw-r--r--test/core/handshake/readahead_handshaker_server_ssl.cc1
-rw-r--r--test/core/handshake/server_ssl.cc1
-rw-r--r--test/core/handshake/server_ssl_common.cc10
-rw-r--r--test/core/handshake/server_ssl_common.h1
-rw-r--r--test/core/iomgr/combiner_test.cc13
-rw-r--r--test/core/iomgr/error_test.cc1
-rw-r--r--test/core/iomgr/ev_epollsig_linux_test.cc2
-rw-r--r--test/core/iomgr/resolve_address_posix_test.cc12
-rw-r--r--test/core/iomgr/wakeup_fd_cv_test.cc39
-rw-r--r--test/core/network_benchmarks/low_level_ping_pong.cc2
-rw-r--r--test/core/statistics/rpc_stats_test.cc1
-rw-r--r--test/core/surface/byte_buffer_reader_test.cc2
-rw-r--r--test/core/surface/completion_queue_threading_test.cc36
-rw-r--r--test/core/surface/concurrent_connectivity_test.cc72
-rw-r--r--test/core/surface/num_external_connectivity_watchers_test.cc2
-rw-r--r--test/core/surface/sequential_connectivity_test.cc8
-rw-r--r--test/core/tsi/transport_security_test_lib.cc1
48 files changed, 286 insertions, 225 deletions
diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc
index 9abc1c40d9..c03ebcf409 100644
--- a/test/core/bad_client/bad_client.cc
+++ b/test/core/bad_client/bad_client.cc
@@ -29,7 +29,7 @@
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/gpr/murmur_hash.h"
#include "src/core/lib/gpr/string.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/completion_queue.h"
@@ -220,11 +220,12 @@ void grpc_run_bad_client_test(
/* Check a ground truth */
GPR_ASSERT(grpc_server_has_open_connections(a.server));
- gpr_thd_id server_validator_id;
gpr_event_init(&a.done_thd);
a.validator = server_validator;
/* Start validator */
- gpr_thd_new(&server_validator_id, "grpc_bad_client", thd_func, &a);
+
+ grpc_core::Thread server_validator_thd("grpc_bad_client", thd_func, &a);
+ server_validator_thd.Start();
for (int i = 0; i < num_args; i++) {
grpc_run_client_side_validator(&args[i], i == (num_args - 1) ? flags : 0,
&sfd, client_cq);
@@ -234,7 +235,7 @@ void grpc_run_bad_client_test(
/* Shutdown. */
shutdown_client(&sfd.client);
- gpr_thd_join(server_validator_id);
+ server_validator_thd.Join();
shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
grpc_server_shutdown_and_notify(a.server, shutdown_cq, nullptr);
diff --git a/test/core/end2end/bad_server_response_test.cc b/test/core/end2end/bad_server_response_test.cc
index e7b2cafa35..0dbde3d788 100644
--- a/test/core/end2end/bad_server_response_test.cc
+++ b/test/core/end2end/bad_server_response_test.cc
@@ -31,7 +31,8 @@
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/memory.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h"
@@ -253,17 +254,18 @@ static void actually_poll_server(void* arg) {
gpr_free(pa);
}
-static gpr_thd_id poll_server_until_read_done(test_tcp_server* server,
-
- gpr_event* signal_when_done) {
+static grpc_core::Thread*
+ poll_server_until_read_done(test_tcp_server* server,
+ gpr_event* signal_when_done) {
gpr_atm_rel_store(&state.done_atm, 0);
state.write_done = 0;
- gpr_thd_id id;
poll_args* pa = static_cast<poll_args*>(gpr_malloc(sizeof(*pa)));
pa->server = server;
pa->signal_when_done = signal_when_done;
- gpr_thd_new(&id, "grpc_poll_server", actually_poll_server, pa);
- return id;
+ auto* th = grpc_core::New<grpc_core::Thread>("grpc_poll_server",
+ actually_poll_server, pa);
+ th->Start();
+ return th;
}
static void run_test(const char* response_payload,
@@ -283,10 +285,11 @@ static void run_test(const char* response_payload,
state.response_payload_length = response_payload_length;
/* poll server until sending out the response */
- gpr_thd_id id = poll_server_until_read_done(&test_server, &ev);
+ grpc_core::UniquePtr<grpc_core::Thread>
+ thdptr(poll_server_until_read_done(&test_server, &ev));
start_rpc(server_port, expected_status, expected_detail);
gpr_event_wait(&ev, gpr_inf_future(GPR_CLOCK_REALTIME));
- gpr_thd_join(id);
+ thdptr->Join();
/* clean up */
grpc_endpoint_shutdown(state.tcp,
diff --git a/test/core/end2end/fixtures/h2_census.cc b/test/core/end2end/fixtures/h2_census.cc
index 27b897ce5a..b3b4171a72 100644
--- a/test/core/end2end/fixtures/h2_census.cc
+++ b/test/core/end2end/fixtures/h2_census.cc
@@ -30,7 +30,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc
index b4ec78d710..565c96cf93 100644
--- a/test/core/end2end/fixtures/h2_compress.cc
+++ b/test/core/end2end/fixtures/h2_compress.cc
@@ -30,7 +30,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/fixtures/h2_full+pipe.cc b/test/core/end2end/fixtures/h2_full+pipe.cc
index e97d078d9c..ed173c1afb 100644
--- a/test/core/end2end/fixtures/h2_full+pipe.cc
+++ b/test/core/end2end/fixtures/h2_full+pipe.cc
@@ -34,7 +34,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
diff --git a/test/core/end2end/fixtures/h2_full+trace.cc b/test/core/end2end/fixtures/h2_full+trace.cc
index 12aa69bb17..afb86ea899 100644
--- a/test/core/end2end/fixtures/h2_full+trace.cc
+++ b/test/core/end2end/fixtures/h2_full+trace.cc
@@ -35,7 +35,6 @@
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/fixtures/h2_full+workarounds.cc b/test/core/end2end/fixtures/h2_full+workarounds.cc
index c6b358dcc5..bd9ddff5b5 100644
--- a/test/core/end2end/fixtures/h2_full+workarounds.cc
+++ b/test/core/end2end/fixtures/h2_full+workarounds.cc
@@ -31,7 +31,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/fixtures/h2_full.cc b/test/core/end2end/fixtures/h2_full.cc
index 32e3e55128..ca61ec8eff 100644
--- a/test/core/end2end/fixtures/h2_full.cc
+++ b/test/core/end2end/fixtures/h2_full.cc
@@ -29,7 +29,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/fixtures/h2_http_proxy.cc b/test/core/end2end/fixtures/h2_http_proxy.cc
index b990d7a763..90d0627860 100644
--- a/test/core/end2end/fixtures/h2_http_proxy.cc
+++ b/test/core/end2end/fixtures/h2_http_proxy.cc
@@ -31,7 +31,6 @@
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/end2end/fixtures/http_proxy_fixture.h"
diff --git a/test/core/end2end/fixtures/h2_load_reporting.cc b/test/core/end2end/fixtures/h2_load_reporting.cc
index 6adc0c154e..ec9eedbd34 100644
--- a/test/core/end2end/fixtures/h2_load_reporting.cc
+++ b/test/core/end2end/fixtures/h2_load_reporting.cc
@@ -31,7 +31,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/fixtures/h2_proxy.cc b/test/core/end2end/fixtures/h2_proxy.cc
index 93dde4f4a2..28884f13b5 100644
--- a/test/core/end2end/fixtures/h2_proxy.cc
+++ b/test/core/end2end/fixtures/h2_proxy.cc
@@ -29,7 +29,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/end2end/fixtures/proxy.h"
diff --git a/test/core/end2end/fixtures/h2_sockpair+trace.cc b/test/core/end2end/fixtures/h2_sockpair+trace.cc
index 5dd5c2ad67..d539ddae8f 100644
--- a/test/core/end2end/fixtures/h2_sockpair+trace.cc
+++ b/test/core/end2end/fixtures/h2_sockpair+trace.cc
@@ -36,7 +36,6 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/env.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/surface/channel.h"
diff --git a/test/core/end2end/fixtures/h2_sockpair.cc b/test/core/end2end/fixtures/h2_sockpair.cc
index 52a7b95c3a..75f64024cd 100644
--- a/test/core/end2end/fixtures/h2_sockpair.cc
+++ b/test/core/end2end/fixtures/h2_sockpair.cc
@@ -30,7 +30,6 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/surface/channel.h"
diff --git a/test/core/end2end/fixtures/h2_sockpair_1byte.cc b/test/core/end2end/fixtures/h2_sockpair_1byte.cc
index 0d3cb34724..929631917d 100644
--- a/test/core/end2end/fixtures/h2_sockpair_1byte.cc
+++ b/test/core/end2end/fixtures/h2_sockpair_1byte.cc
@@ -30,7 +30,6 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/endpoint_pair.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/surface/channel.h"
diff --git a/test/core/end2end/fixtures/h2_uds.cc b/test/core/end2end/fixtures/h2_uds.cc
index a97b14f1d6..1b081f9ea3 100644
--- a/test/core/end2end/fixtures/h2_uds.cc
+++ b/test/core/end2end/fixtures/h2_uds.cc
@@ -33,7 +33,6 @@
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc
index 8546ef541f..d95ce66423 100644
--- a/test/core/end2end/fixtures/http_proxy_fixture.cc
+++ b/test/core/end2end/fixtures/http_proxy_fixture.cc
@@ -20,6 +20,7 @@
#include "src/core/lib/iomgr/sockaddr.h"
+#include <new>
#include <string.h>
#include <grpc/grpc.h>
@@ -33,7 +34,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/http/parser.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/combiner.h"
@@ -53,7 +54,7 @@
struct grpc_end2end_http_proxy {
char* proxy_name;
- gpr_thd_id thd;
+ grpc_core::Thread thd;
grpc_tcp_server* server;
grpc_channel_args* channel_args;
gpr_mu* mu;
@@ -550,7 +551,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(
grpc_tcp_server_start(proxy->server, &proxy->pollset, 1, on_accept, proxy);
// Start proxy thread.
- GPR_ASSERT(gpr_thd_new(&proxy->thd, "grpc_http_proxy", thread_main, proxy));
+ new (&proxy->thd) grpc_core::Thread("grpc_http_proxy", thread_main, proxy);
+ proxy->thd.Start();
return proxy;
}
@@ -563,7 +565,8 @@ static void destroy_pollset(void* arg, grpc_error* error) {
void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) {
gpr_unref(&proxy->users); // Signal proxy thread to shutdown.
grpc_core::ExecCtx exec_ctx;
- gpr_thd_join(proxy->thd);
+ proxy->thd.Join();
+ proxy->thd.~Thread();
grpc_tcp_server_shutdown_listeners(proxy->server);
grpc_tcp_server_unref(proxy->server);
gpr_free(proxy->proxy_name);
diff --git a/test/core/end2end/fixtures/inproc.cc b/test/core/end2end/fixtures/inproc.cc
index 4ddcc78495..d47de42540 100644
--- a/test/core/end2end/fixtures/inproc.cc
+++ b/test/core/end2end/fixtures/inproc.cc
@@ -29,7 +29,6 @@
#include "src/core/ext/transport/inproc/inproc_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
diff --git a/test/core/end2end/fixtures/proxy.cc b/test/core/end2end/fixtures/proxy.cc
index db49534899..fe54261b5e 100644
--- a/test/core/end2end/fixtures/proxy.cc
+++ b/test/core/end2end/fixtures/proxy.cc
@@ -18,6 +18,7 @@
#include "test/core/end2end/fixtures/proxy.h"
+#include <new>
#include <string.h>
#include <grpc/support/alloc.h>
@@ -25,12 +26,12 @@
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/util/port.h"
struct grpc_end2end_proxy {
- gpr_thd_id thd;
+ grpc_core::Thread thd;
char* proxy_port;
char* server_port;
grpc_completion_queue* cq;
@@ -97,8 +98,8 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def,
grpc_server_start(proxy->server);
grpc_call_details_init(&proxy->new_call_details);
- GPR_ASSERT(
- gpr_thd_new(&proxy->thd, "grpc_end2end_proxy", thread_main, proxy));
+ new (&proxy->thd) grpc_core::Thread("grpc_end2end_proxy", thread_main, proxy);
+ proxy->thd.Start();
request_call(proxy);
@@ -121,7 +122,8 @@ static void shutdown_complete(void* arg, int success) {
void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy) {
grpc_server_shutdown_and_notify(proxy->server, proxy->cq,
new_closure(shutdown_complete, proxy));
- gpr_thd_join(proxy->thd);
+ proxy->thd.Join();
+ proxy->thd.~Thread();
gpr_free(proxy->proxy_port);
gpr_free(proxy->server_port);
grpc_server_destroy(proxy->server);
diff --git a/test/core/end2end/tests/bad_ping.cc b/test/core/end2end/tests/bad_ping.cc
index 9fff3bfb7d..f305ea5703 100644
--- a/test/core/end2end/tests/bad_ping.cc
+++ b/test/core/end2end/tests/bad_ping.cc
@@ -25,7 +25,6 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/end2end/cq_verifier.h"
diff --git a/test/core/end2end/tests/connectivity.cc b/test/core/end2end/tests/connectivity.cc
index d4887137f8..caa4265aa2 100644
--- a/test/core/end2end/tests/connectivity.cc
+++ b/test/core/end2end/tests/connectivity.cc
@@ -22,7 +22,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "test/core/end2end/cq_verifier.h"
static void* tag(intptr_t t) { return (void*)t; }
@@ -50,7 +50,6 @@ static void test_connectivity(grpc_end2end_test_config config) {
grpc_connectivity_state state;
cq_verifier* cqv = cq_verifier_create(f.cq);
child_events ce;
- gpr_thd_id thdid;
grpc_channel_args client_args;
grpc_arg arg_array[1];
@@ -66,7 +65,8 @@ static void test_connectivity(grpc_end2end_test_config config) {
ce.channel = f.client;
ce.cq = f.cq;
gpr_event_init(&ce.started);
- GPR_ASSERT(gpr_thd_new(&thdid, "grpc_connectivity", child_thread, &ce));
+ grpc_core::Thread thd("grpc_connectivity", child_thread, &ce);
+ thd.Start();
gpr_event_wait(&ce.started, gpr_inf_future(GPR_CLOCK_MONOTONIC));
@@ -83,7 +83,7 @@ static void test_connectivity(grpc_end2end_test_config config) {
f.client, GRPC_CHANNEL_IDLE, gpr_now(GPR_CLOCK_MONOTONIC), f.cq, tag(1));
/* eventually the child thread completion should trigger */
- gpr_thd_join(thdid);
+ thd.Join();
/* check that we're still in idle, and start connecting */
GPR_ASSERT(grpc_channel_check_connectivity_state(f.client, 1) ==
diff --git a/test/core/end2end/tests/ping.cc b/test/core/end2end/tests/ping.cc
index 8fce295f90..f523cbb0c7 100644
--- a/test/core/end2end/tests/ping.cc
+++ b/test/core/end2end/tests/ping.cc
@@ -22,7 +22,6 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/end2end/cq_verifier.h"
diff --git a/test/core/gpr/arena_test.cc b/test/core/gpr/arena_test.cc
index 1cfaefa686..717052eacd 100644
--- a/test/core/gpr/arena_test.cc
+++ b/test/core/gpr/arena_test.cc
@@ -18,15 +18,17 @@
#include "src/core/lib/gpr/arena.h"
+#include <new>
+#include <inttypes.h>
+#include <string.h>
+
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
-#include <inttypes.h>
-#include <string.h>
#include "src/core/lib/gpr/string.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/util/test_config.h"
@@ -97,16 +99,18 @@ static void concurrent_test(void) {
gpr_event_init(&args.ev_start);
args.arena = gpr_arena_create(1024);
- gpr_thd_id thds[CONCURRENT_TEST_THREADS];
+ grpc_core::Thread thds[CONCURRENT_TEST_THREADS];
for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) {
- gpr_thd_new(&thds[i], "grpc_concurrent_test", concurrent_test_body, &args);
+ new (&thds[i]) grpc_core::Thread("grpc_concurrent_test",
+ concurrent_test_body, &args);
+ thds[i].Start();
}
gpr_event_set(&args.ev_start, (void*)1);
- for (int i = 0; i < CONCURRENT_TEST_THREADS; i++) {
- gpr_thd_join(thds[i]);
+ for (auto& th : thds) {
+ th.Join();
}
gpr_arena_destroy(args.arena);
diff --git a/test/core/gpr/cpu_test.cc b/test/core/gpr/cpu_test.cc
index c97facef7d..4575fb643a 100644
--- a/test/core/gpr/cpu_test.cc
+++ b/test/core/gpr/cpu_test.cc
@@ -21,15 +21,18 @@
gpr_cpu_current_cpu()
*/
-#include <grpc/support/alloc.h>
#include <grpc/support/cpu.h>
+
+#include <new>
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-#include <stdio.h>
-#include <string.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
/* Test structure is essentially:
@@ -101,7 +104,6 @@ static void cpu_test(void) {
uint32_t i;
int cores_seen = 0;
struct cpu_test ct;
- gpr_thd_id* thd;
ct.ncores = gpr_cpu_num_cores();
GPR_ASSERT(ct.ncores > 0);
ct.nthreads = static_cast<int>(ct.ncores) * 3;
@@ -112,10 +114,12 @@ static void cpu_test(void) {
ct.is_done = 0;
uint32_t nthreads = ct.ncores * 3;
- thd = static_cast<gpr_thd_id*>(gpr_malloc(sizeof(thd[0]) * nthreads));
+ grpc_core::Thread* thd =
+ static_cast<grpc_core::Thread*>(gpr_malloc(sizeof(*thd)*nthreads));
for (i = 0; i < nthreads; i++) {
- GPR_ASSERT(gpr_thd_new(&thd[i], "grpc_cpu_test", &worker_thread, &ct));
+ new (&thd[i]) grpc_core::Thread("grpc_cpu_test", &worker_thread, &ct);
+ thd[i].Start();
}
gpr_mu_lock(&ct.mu);
while (!ct.is_done) {
@@ -123,7 +127,8 @@ static void cpu_test(void) {
}
gpr_mu_unlock(&ct.mu);
for (i = 0; i < nthreads; i++) {
- gpr_thd_join(thd[i]);
+ thd[i].Join();
+ thd[i].~Thread();
}
gpr_free(thd);
fprintf(stderr, "Saw cores [");
diff --git a/test/core/gpr/mpscq_test.cc b/test/core/gpr/mpscq_test.cc
index 55998445f6..bf65b2d0b9 100644
--- a/test/core/gpr/mpscq_test.cc
+++ b/test/core/gpr/mpscq_test.cc
@@ -18,13 +18,14 @@
#include "src/core/lib/gpr/mpscq.h"
+#include <new>
#include <stdlib.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/util/test_config.h"
@@ -76,7 +77,7 @@ static void test_mt(void) {
gpr_log(GPR_DEBUG, "test_mt");
gpr_event start;
gpr_event_init(&start);
- gpr_thd_id thds[100];
+ grpc_core::Thread thds[100];
thd_args ta[GPR_ARRAY_SIZE(thds)];
gpr_mpscq q;
gpr_mpscq_init(&q);
@@ -84,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], "grpc_mt_test", test_thread, &ta[i]));
+ new (&thds[i]) grpc_core::Thread("grpc_mt_test", test_thread, &ta[i]);
+ thds[i].Start();
}
size_t num_done = 0;
size_t spins = 0;
@@ -101,8 +103,8 @@ static void test_mt(void) {
gpr_free(tn);
}
gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, spins);
- for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
- gpr_thd_join(thds[i]);
+ for (auto& th : thds) {
+ th.Join();
}
gpr_mpscq_destroy(&q);
}
@@ -144,8 +146,8 @@ static void test_mt_multipop(void) {
gpr_log(GPR_DEBUG, "test_mt_multipop");
gpr_event start;
gpr_event_init(&start);
- gpr_thd_id thds[100];
- gpr_thd_id pull_thds[100];
+ grpc_core::Thread thds[100];
+ grpc_core::Thread pull_thds[100];
thd_args ta[GPR_ARRAY_SIZE(thds)];
gpr_mpscq q;
gpr_mpscq_init(&q);
@@ -153,8 +155,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], "grpc_multipop_test", test_thread, &ta[i]));
+ new (&thds[i]) grpc_core::Thread("grpc_multipop_test", test_thread, &ta[i]);
+ thds[i].Start();
}
pull_args pa;
pa.ta = ta;
@@ -165,16 +167,17 @@ static void test_mt_multipop(void) {
pa.start = &start;
gpr_mu_init(&pa.mu);
for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) {
- GPR_ASSERT(
- gpr_thd_new(&pull_thds[i], "grpc_multipop_pull", pull_thread, &pa));
+ new (&pull_thds[i]) grpc_core::Thread("grpc_multipop_pull",
+ pull_thread, &pa);
+ pull_thds[i].Start();
}
gpr_event_set(&start, (void*)1);
- for (size_t i = 0; i < GPR_ARRAY_SIZE(pull_thds); i++) {
- gpr_thd_join(pull_thds[i]);
+ for (auto& pth: pull_thds) {
+ pth.Join();
}
gpr_log(GPR_DEBUG, "spins: %" PRIdPTR, pa.spins);
- for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
- gpr_thd_join(thds[i]);
+ for (auto& th : thds) {
+ th.Join();
}
gpr_mpscq_destroy(&q);
}
diff --git a/test/core/gpr/spinlock_test.cc b/test/core/gpr/spinlock_test.cc
index 1392cff7ad..1a3475b8f2 100644
--- a/test/core/gpr/spinlock_test.cc
+++ b/test/core/gpr/spinlock_test.cc
@@ -16,24 +16,27 @@
*
*/
-/* Test of gpr synchronization support. */
+/* Test of gpr spin-lock support. */
#include "src/core/lib/gpr/spinlock.h"
+
+#include <new>
+#include <stdio.h>
+#include <stdlib.h>
+
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
/* ------------------------------------------------- */
/* Tests for gpr_spinlock. */
struct test {
int thread_count; /* number of threads */
- gpr_thd_id* threads;
+ grpc_core::Thread* threads;
int64_t iterations; /* number of iterations per thread */
int64_t counter;
@@ -46,7 +49,7 @@ struct test {
static struct test* test_new(int threads, int64_t iterations, int incr_step) {
struct test* m = static_cast<struct test*>(gpr_malloc(sizeof(*m)));
m->thread_count = threads;
- m->threads = static_cast<gpr_thd_id*>(
+ m->threads = static_cast<grpc_core::Thread*>(
gpr_malloc(sizeof(*m->threads) * static_cast<size_t>(threads)));
m->iterations = iterations;
m->counter = 0;
@@ -66,7 +69,8 @@ static void test_destroy(struct test* m) {
static void test_create_threads(struct test* m, void (*body)(void* arg)) {
int i;
for (i = 0; i != m->thread_count; i++) {
- GPR_ASSERT(gpr_thd_new(&m->threads[i], "grpc_create_threads", body, m));
+ new (&m->threads[i]) grpc_core::Thread("grpc_create_threads", body, m);
+ m->threads[i].Start();
}
}
@@ -74,7 +78,8 @@ static void test_create_threads(struct test* m, void (*body)(void* arg)) {
static void test_wait(struct test* m) {
int i;
for (i = 0; i != m->thread_count; i++) {
- gpr_thd_join(m->threads[i]);
+ m->threads[i].Join();
+ m->threads[i].~Thread();
}
}
diff --git a/test/core/gpr/sync_test.cc b/test/core/gpr/sync_test.cc
index d2d1f41775..2cdf061c71 100644
--- a/test/core/gpr/sync_test.cc
+++ b/test/core/gpr/sync_test.cc
@@ -18,14 +18,17 @@
/* Test of gpr synchronization support. */
-#include <grpc/support/alloc.h>
-#include <grpc/support/log.h>
#include <grpc/support/sync.h>
-#include <grpc/support/time.h>
+
+#include <new>
#include <stdio.h>
#include <stdlib.h>
-#include "src/core/lib/gpr/thd.h"
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+
+#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
/* ==================Example use of interface===================
@@ -133,8 +136,8 @@ int queue_remove(queue* q, int* head, gpr_timespec abs_deadline) {
/* ------------------------------------------------- */
/* Tests for gpr_mu and gpr_cv, and the queue example. */
struct test {
- int threads; /* number of threads */
- gpr_thd_id* thread_ids;
+ int nthreads; /* number of threads */
+ grpc_core::Thread* threads;
int64_t iterations; /* number of iterations per thread */
int64_t counter;
@@ -158,15 +161,15 @@ struct test {
};
/* Return pointer to a new struct test. */
-static struct test* test_new(int threads, int64_t iterations, int incr_step) {
+static struct test* test_new(int nthreads, int64_t iterations, int incr_step) {
struct test* m = static_cast<struct test*>(gpr_malloc(sizeof(*m)));
- m->threads = threads;
- m->thread_ids =
- static_cast<gpr_thd_id*>(gpr_malloc(sizeof(*m->thread_ids) * threads));
+ m->nthreads = nthreads;
+ m->threads =
+ static_cast<grpc_core::Thread*>(gpr_malloc(sizeof(*m->threads) * nthreads));
m->iterations = iterations;
m->counter = 0;
m->thread_count = 0;
- m->done = threads;
+ m->done = nthreads;
m->incr_step = incr_step;
gpr_mu_init(&m->mu);
gpr_cv_init(&m->cv);
@@ -174,7 +177,7 @@ static struct test* test_new(int threads, int64_t iterations, int incr_step) {
queue_init(&m->q);
gpr_stats_init(&m->stats_counter, 0);
gpr_ref_init(&m->refcount, 0);
- gpr_ref_init(&m->thread_refcount, threads);
+ gpr_ref_init(&m->thread_refcount, nthreads);
gpr_event_init(&m->event);
return m;
}
@@ -185,15 +188,16 @@ static void test_destroy(struct test* m) {
gpr_cv_destroy(&m->cv);
gpr_cv_destroy(&m->done_cv);
queue_destroy(&m->q);
- gpr_free(m->thread_ids);
+ gpr_free(m->threads);
gpr_free(m);
}
-/* Create m->threads threads, each running (*body)(m) */
+/* Create m->nthreads threads, each running (*body)(m) */
static void test_create_threads(struct test* m, void (*body)(void* arg)) {
int i;
- for (i = 0; i != m->threads; i++) {
- GPR_ASSERT(gpr_thd_new(&m->thread_ids[i], "grpc_create_threads", body, m));
+ for (i = 0; i != m->nthreads; i++) {
+ new (&m->threads[i]) grpc_core::Thread("grpc_create_threads", body, m);
+ m->threads[i].Start();
}
}
@@ -204,12 +208,13 @@ static void test_wait(struct test* m) {
gpr_cv_wait(&m->done_cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
gpr_mu_unlock(&m->mu);
- for (int i = 0; i != m->threads; i++) {
- gpr_thd_join(m->thread_ids[i]);
+ for (int i = 0; i != m->nthreads; i++) {
+ m->threads[i].Join();
+ m->threads[i].~Thread();
}
}
-/* Get an integer thread id in the raneg 0..threads-1 */
+/* Get an integer thread id in the raneg 0..nthreads-1 */
static int thread_id(struct test* m) {
int id;
gpr_mu_lock(&m->mu);
@@ -251,19 +256,20 @@ static void test(const char* name, void (*body)(void* m),
fprintf(stderr, " %ld", static_cast<long>(iterations));
fflush(stderr);
m = test_new(10, iterations, incr_step);
- gpr_thd_id extra_id;
+ grpc_core::Thread extra_thd;
if (extra != nullptr) {
- GPR_ASSERT(gpr_thd_new(&extra_id, name, extra, m));
+ new (&extra_thd) grpc_core::Thread(name, extra, m);
+ extra_thd.Start();
m->done++; /* one more thread to wait for */
}
test_create_threads(m, body);
test_wait(m);
if (extra != nullptr) {
- gpr_thd_join(extra_id);
+ extra_thd.Join();
}
- if (m->counter != m->threads * m->iterations * m->incr_step) {
+ if (m->counter != m->nthreads * m->iterations * m->incr_step) {
fprintf(stderr, "counter %ld threads %d iterations %ld\n",
- static_cast<long>(m->counter), m->threads,
+ static_cast<long>(m->counter), m->nthreads,
static_cast<long>(m->iterations));
fflush(stderr);
GPR_ASSERT(0);
@@ -305,7 +311,7 @@ static void inctry(void* v /*=m*/) {
mark_thread_done(m);
}
-/* Increment counter only when (m->counter%m->threads)==m->thread_id; then mark
+/* Increment counter only when (m->counter%m->nthreads)==m->thread_id; then mark
thread as done. */
static void inc_by_turns(void* v /*=m*/) {
struct test* m = static_cast<struct test*>(v);
@@ -313,7 +319,7 @@ static void inc_by_turns(void* v /*=m*/) {
int id = thread_id(m);
for (i = 0; i != m->iterations; i++) {
gpr_mu_lock(&m->mu);
- while ((m->counter % m->threads) != id) {
+ while ((m->counter % m->nthreads) != id) {
gpr_cv_wait(&m->cv, &m->mu, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
m->counter++;
@@ -378,12 +384,12 @@ static void many_producers(void* v /*=m*/) {
mark_thread_done(m);
}
-/* Consume elements from m->q until m->threads*m->iterations are seen,
+/* Consume elements from m->q until m->nthreads*m->iterations are seen,
wait an extra second to confirm that no more elements are arriving,
then mark thread as done. */
static void consumer(void* v /*=m*/) {
struct test* m = static_cast<struct test*>(v);
- int64_t n = m->iterations * m->threads;
+ int64_t n = m->iterations * m->nthreads;
int64_t i;
int value;
for (i = 0; i != n; i++) {
@@ -433,11 +439,11 @@ static void refinc(void* v /*=m*/) {
}
/* Wait until m->event is set to (void *)1, then decrement m->refcount by 1
- (m->threads * m->iterations * m->incr_step) times, and ensure that the last
+ (m->nthreads * m->iterations * m->incr_step) times, and ensure that the last
decrement caused the counter to reach zero, then mark thread as done. */
static void refcheck(void* v /*=m*/) {
struct test* m = static_cast<struct test*>(v);
- int64_t n = m->iterations * m->threads * m->incr_step;
+ int64_t n = m->iterations * m->nthreads * m->incr_step;
int64_t i;
GPR_ASSERT(gpr_event_wait(&m->event, gpr_inf_future(GPR_CLOCK_REALTIME)) ==
(void*)1);
diff --git a/test/core/gpr/time_test.cc b/test/core/gpr/time_test.cc
index e6bcc1247d..c80aac649d 100644
--- a/test/core/gpr/time_test.cc
+++ b/test/core/gpr/time_test.cc
@@ -26,7 +26,6 @@
#include <stdlib.h>
#include <string.h>
-#include "src/core/lib/gpr/thd.h"
#include "test/core/util/test_config.h"
static void to_fp(void* arg, const char* buf, size_t len) {
diff --git a/test/core/gpr/tls_test.cc b/test/core/gpr/tls_test.cc
index f3f0864d3d..15f329f21a 100644
--- a/test/core/gpr/tls_test.cc
+++ b/test/core/gpr/tls_test.cc
@@ -18,13 +18,16 @@
/* Test of gpr thread local storage support. */
-#include <grpc/support/log.h>
-#include <grpc/support/sync.h>
+#include "src/core/lib/gpr/tls.h"
+
+#include <new>
#include <stdio.h>
#include <stdlib.h>
-#include "src/core/lib/gpr/thd.h"
-#include "src/core/lib/gpr/tls.h"
+#include <grpc/support/log.h>
+#include <grpc/support/sync.h>
+
+#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/test_config.h"
#define NUM_THREADS 100
@@ -46,18 +49,18 @@ static void thd_body(void* arg) {
/* ------------------------------------------------- */
int main(int argc, char* argv[]) {
- int i;
- gpr_thd_id threads[NUM_THREADS];
+ grpc_core::Thread threads[NUM_THREADS];
grpc_test_init(argc, argv);
gpr_tls_init(&test_var);
- for (i = 0; i < NUM_THREADS; i++) {
- gpr_thd_new(&threads[i], "grpc_tls_test", thd_body, nullptr);
+ for (auto& th : threads) {
+ new (&th) grpc_core::Thread("grpc_tls_test", thd_body, nullptr);
+ th.Start();
}
- for (i = 0; i < NUM_THREADS; i++) {
- gpr_thd_join(threads[i]);
+ for (auto& th : threads) {
+ th.Join();
}
gpr_tls_destroy(&test_var);
diff --git a/test/core/gprpp/manual_constructor_test.cc b/test/core/gprpp/manual_constructor_test.cc
index 74777fe11c..af162ae8e8 100644
--- a/test/core/gprpp/manual_constructor_test.cc
+++ b/test/core/gprpp/manual_constructor_test.cc
@@ -26,7 +26,6 @@
#include <stdlib.h>
#include <cstring>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/gprpp/abstract.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/gpr/thd_test.cc b/test/core/gprpp/thd_test.cc
index 47e9a22fd8..d98f617288 100644
--- a/test/core/gpr/thd_test.cc
+++ b/test/core/gprpp/thd_test.cc
@@ -18,13 +18,15 @@
/* Test of gpr thread support. */
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
+
+#include <new>
+#include <stdio.h>
+#include <stdlib.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-#include <stdio.h>
-#include <stdlib.h>
#include "test/core/util/test_config.h"
@@ -51,23 +53,23 @@ static void thd_body1(void* v) {
/* Test that we can create a number of threads, wait for them, and join them. */
static void test1(void) {
- int i;
- gpr_thd_id thds[NUM_THREADS];
+ grpc_core::Thread thds[NUM_THREADS];
struct test t;
gpr_mu_init(&t.mu);
gpr_cv_init(&t.done_cv);
t.n = NUM_THREADS;
t.is_done = 0;
- for (i = 0; i < NUM_THREADS; i++) {
- GPR_ASSERT(gpr_thd_new(&thds[i], "grpc_thread_body1_test", &thd_body1, &t));
+ for (auto& th: thds) {
+ new (&th) grpc_core::Thread("grpc_thread_body1_test", &thd_body1, &t);
+ th.Start();
}
gpr_mu_lock(&t.mu);
while (!t.is_done) {
gpr_cv_wait(&t.done_cv, &t.mu, gpr_inf_future(GPR_CLOCK_REALTIME));
}
gpr_mu_unlock(&t.mu);
- for (i = 0; i < NUM_THREADS; i++) {
- gpr_thd_join(thds[i]);
+ for (auto& th: thds) {
+ th.Join();
}
GPR_ASSERT(t.n == 0);
}
@@ -76,14 +78,16 @@ static void thd_body2(void* v) {}
/* Test that we can create a number of threads and join them. */
static void test2(void) {
- int i;
- gpr_thd_id thds[NUM_THREADS];
- for (i = 0; i < NUM_THREADS; i++) {
- GPR_ASSERT(
- gpr_thd_new(&thds[i], "grpc_thread_body2_test", &thd_body2, nullptr));
+ grpc_core::Thread thds[NUM_THREADS];
+ for (auto& th: thds) {
+ bool ok;
+ new (&th) grpc_core::Thread("grpc_thread_body2_test", &thd_body2,
+ nullptr, &ok);
+ GPR_ASSERT(ok);
+ th.Start();
}
- for (i = 0; i < NUM_THREADS; i++) {
- gpr_thd_join(thds[i]);
+ for (auto& th: thds) {
+ th.Join();
}
}
diff --git a/test/core/handshake/client_ssl.cc b/test/core/handshake/client_ssl.cc
index 2581eb525c..8ac763ac4b 100644
--- a/test/core/handshake/client_ssl.cc
+++ b/test/core/handshake/client_ssl.cc
@@ -35,7 +35,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -230,9 +230,11 @@ static bool client_ssl_test(char* server_alpn_preferred) {
GPR_ASSERT(server_socket > 0 && port > 0);
// Launch the TLS server thread.
- gpr_thd_id thdid;
server_args args = {server_socket, server_alpn_preferred};
- GPR_ASSERT(gpr_thd_new(&thdid, "grpc_client_ssl_test", server_thread, &args));
+ bool ok;
+ grpc_core::Thread thd("grpc_client_ssl_test", server_thread, &args, &ok);
+ GPR_ASSERT(ok);
+ thd.Start();
// Load key pair and establish client SSL credentials.
grpc_ssl_pem_key_cert_pair pem_key_cert_pair;
@@ -300,7 +302,7 @@ static bool client_ssl_test(char* server_alpn_preferred) {
grpc_slice_unref(key_slice);
grpc_slice_unref(ca_slice);
- gpr_thd_join(thdid);
+ thd.Join();
grpc_shutdown();
diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc
index 80000ca8d3..9788320e0d 100644
--- a/test/core/handshake/readahead_handshaker_server_ssl.cc
+++ b/test/core/handshake/readahead_handshaker_server_ssl.cc
@@ -30,7 +30,6 @@
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/handshake/server_ssl.cc b/test/core/handshake/server_ssl.cc
index f0465c8e3e..8fa5f7fb35 100644
--- a/test/core/handshake/server_ssl.cc
+++ b/test/core/handshake/server_ssl.cc
@@ -30,7 +30,6 @@
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/handshake/server_ssl_common.cc b/test/core/handshake/server_ssl_common.cc
index a2d389954f..41b2829d8b 100644
--- a/test/core/handshake/server_ssl_common.cc
+++ b/test/core/handshake/server_ssl_common.cc
@@ -32,7 +32,7 @@
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
@@ -138,8 +138,10 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len,
gpr_event_init(&client_handshake_complete);
// Launch the gRPC server thread.
- gpr_thd_id thdid;
- GPR_ASSERT(gpr_thd_new(&thdid, "grpc_ssl_test", server_thread, &port));
+ bool ok;
+ grpc_core::Thread thd("grpc_ssl_test", server_thread, &port, &ok);
+ GPR_ASSERT(ok);
+ thd.Start();
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
@@ -232,7 +234,7 @@ bool server_ssl_test(const char* alpn_list[], unsigned int alpn_list_len,
EVP_cleanup();
close(sock);
- gpr_thd_join(thdid);
+ thd.Join();
grpc_shutdown();
diff --git a/test/core/handshake/server_ssl_common.h b/test/core/handshake/server_ssl_common.h
index f726a1cd3a..32bc6f9897 100644
--- a/test/core/handshake/server_ssl_common.h
+++ b/test/core/handshake/server_ssl_common.h
@@ -26,7 +26,6 @@
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/iomgr/load_file.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/iomgr/combiner_test.cc b/test/core/iomgr/combiner_test.cc
index 0cd63bd973..45afe53564 100644
--- a/test/core/iomgr/combiner_test.cc
+++ b/test/core/iomgr/combiner_test.cc
@@ -18,11 +18,13 @@
#include "src/core/lib/iomgr/combiner.h"
+#include <new>
+
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "test/core/util/test_config.h"
@@ -97,19 +99,20 @@ static void test_execute_many(void) {
gpr_log(GPR_DEBUG, "test_execute_many");
grpc_combiner* lock = grpc_combiner_create();
- gpr_thd_id thds[100];
+ grpc_core::Thread thds[100];
thd_args ta[GPR_ARRAY_SIZE(thds)];
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
ta[i].ctr = 0;
ta[i].lock = lock;
gpr_event_init(&ta[i].done);
- GPR_ASSERT(
- gpr_thd_new(&thds[i], "grpc_execute_many", execute_many_loop, &ta[i]));
+ new (&thds[i]) grpc_core::Thread("grpc_execute_many",
+ execute_many_loop, &ta[i]);
+ thds[i].Start();
}
for (size_t i = 0; i < GPR_ARRAY_SIZE(thds); i++) {
GPR_ASSERT(gpr_event_wait(&ta[i].done,
gpr_inf_future(GPR_CLOCK_REALTIME)) != nullptr);
- gpr_thd_join(thds[i]);
+ thds[i].Join();
}
grpc_core::ExecCtx exec_ctx;
GRPC_COMBINER_UNREF(lock, "test_execute_many");
diff --git a/test/core/iomgr/error_test.cc b/test/core/iomgr/error_test.cc
index f6292b72a9..a1628a1f71 100644
--- a/test/core/iomgr/error_test.cc
+++ b/test/core/iomgr/error_test.cc
@@ -24,7 +24,6 @@
#include <string.h>
-#include "src/core/lib/gpr/thd.h"
#include "test/core/util/test_config.h"
static void test_set_get_int() {
diff --git a/test/core/iomgr/ev_epollsig_linux_test.cc b/test/core/iomgr/ev_epollsig_linux_test.cc
index 5c30843588..751b80fa89 100644
--- a/test/core/iomgr/ev_epollsig_linux_test.cc
+++ b/test/core/iomgr/ev_epollsig_linux_test.cc
@@ -30,7 +30,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/iomgr/resolve_address_posix_test.cc b/test/core/iomgr/resolve_address_posix_test.cc
index 6a1564dd69..9d61c9818b 100644
--- a/test/core/iomgr/resolve_address_posix_test.cc
+++ b/test/core/iomgr/resolve_address_posix_test.cc
@@ -18,6 +18,7 @@
#include "src/core/lib/iomgr/resolve_address.h"
+#include <new>
#include <string.h>
#include <sys/un.h>
@@ -27,7 +28,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/executor.h"
#include "src/core/lib/iomgr/iomgr.h"
@@ -38,7 +39,7 @@ static gpr_timespec test_deadline(void) {
}
typedef struct args_struct {
- gpr_thd_id id;
+ grpc_core::Thread thd;
gpr_event ev;
grpc_resolved_addresses* addrs;
gpr_atm done_atm;
@@ -60,7 +61,9 @@ void args_init(args_struct* args) {
void args_finish(args_struct* args) {
GPR_ASSERT(gpr_event_wait(&args->ev, test_deadline()));
- gpr_thd_join(args->id);
+ args->thd.Join();
+ // Don't need to explicitly destruct args->thd since
+ // args is actually going to be destructed, not just freed
grpc_resolved_addresses_destroy(args->addrs);
grpc_pollset_set_del_pollset(args->pollset_set, args->pollset);
grpc_pollset_set_destroy(args->pollset_set);
@@ -103,7 +106,8 @@ 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_new(&args->id, "grpc_poll_pollset", actually_poll, args);
+ new (&args->thd) grpc_core::Thread("grpc_poll_pollset", actually_poll, args);
+ args->thd.Start();
}
static void must_succeed(void* argsp, grpc_error* err) {
diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc
index d77a3ec0b4..1b1c9ef811 100644
--- a/test/core/iomgr/wakeup_fd_cv_test.cc
+++ b/test/core/iomgr/wakeup_fd_cv_test.cc
@@ -26,7 +26,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/gpr/env.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/iomgr_posix.h"
@@ -103,7 +103,6 @@ void test_poll_cv_trigger(void) {
grpc_wakeup_fd cvfd1, cvfd2, cvfd3;
struct pollfd pfds[6];
poll_args pargs;
- gpr_thd_id t_id;
GPR_ASSERT(grpc_wakeup_fd_init(&cvfd1) == GRPC_ERROR_NONE);
GPR_ASSERT(grpc_wakeup_fd_init(&cvfd2) == GRPC_ERROR_NONE);
@@ -134,11 +133,12 @@ void test_poll_cv_trigger(void) {
pargs.timeout = 1000;
pargs.result = -2;
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
-
+ {
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
// Wakeup wakeup_fd not listening for events
GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd1) == GRPC_ERROR_NONE);
- gpr_thd_join(t_id);
+ thd.Join();
GPR_ASSERT(pargs.result == 0);
GPR_ASSERT(pfds[0].revents == 0);
GPR_ASSERT(pfds[1].revents == 0);
@@ -146,13 +146,16 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
+ }
+ {
// Pollin on socket fd
pargs.timeout = -1;
pargs.result = -2;
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
trigger_socket_event();
- gpr_thd_join(t_id);
+ thd.Join();
GPR_ASSERT(pargs.result == 1);
GPR_ASSERT(pfds[0].revents == 0);
GPR_ASSERT(pfds[1].revents == 0);
@@ -160,13 +163,16 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
+ }
+ {
// Pollin on wakeup fd
reset_socket_event();
pargs.result = -2;
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
GPR_ASSERT(grpc_wakeup_fd_wakeup(&cvfd2) == GRPC_ERROR_NONE);
- gpr_thd_join(t_id);
+ thd.Join();
GPR_ASSERT(pargs.result == 1);
GPR_ASSERT(pfds[0].revents == 0);
@@ -175,11 +181,14 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
+ }
+ {
// Pollin on wakeupfd before poll()
pargs.result = -2;
- gpr_thd_new(&t_id, "grpc_background_poll", &background_poll, &pargs);
- gpr_thd_join(t_id);
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
+ thd.Join();
GPR_ASSERT(pargs.result == 1);
GPR_ASSERT(pfds[0].revents == 0);
@@ -188,15 +197,18 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
+ }
+ {
// No Events
pargs.result = -2;
pargs.timeout = 1000;
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, "grpc_background_poll", &background_poll, &pargs);
- gpr_thd_join(t_id);
+ grpc_core::Thread thd("grpc_background_poll", &background_poll, &pargs);
+ thd.Start();
+ thd.Join();
GPR_ASSERT(pargs.result == 0);
GPR_ASSERT(pfds[0].revents == 0);
@@ -205,6 +217,7 @@ void test_poll_cv_trigger(void) {
GPR_ASSERT(pfds[3].revents == 0);
GPR_ASSERT(pfds[4].revents == 0);
GPR_ASSERT(pfds[5].revents == 0);
+ }
}
int main(int argc, char** argv) {
diff --git a/test/core/network_benchmarks/low_level_ping_pong.cc b/test/core/network_benchmarks/low_level_ping_pong.cc
index b90ad8d44d..afcd2da57a 100644
--- a/test/core/network_benchmarks/low_level_ping_pong.cc
+++ b/test/core/network_benchmarks/low_level_ping_pong.cc
@@ -38,7 +38,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/socket_utils_posix.h"
diff --git a/test/core/statistics/rpc_stats_test.cc b/test/core/statistics/rpc_stats_test.cc
index ff48075365..a2a648e2ad 100644
--- a/test/core/statistics/rpc_stats_test.cc
+++ b/test/core/statistics/rpc_stats_test.cc
@@ -27,7 +27,6 @@
#include "src/core/ext/census/census_interface.h"
#include "src/core/ext/census/census_rpc_stats.h"
#include "src/core/ext/census/census_tracing.h"
-#include "src/core/lib/gpr/thd.h"
#include "test/core/util/test_config.h"
/* Ensure all possible state transitions are called without causing problem */
diff --git a/test/core/surface/byte_buffer_reader_test.cc b/test/core/surface/byte_buffer_reader_test.cc
index 861ed5d1a8..cff05caec1 100644
--- a/test/core/surface/byte_buffer_reader_test.cc
+++ b/test/core/surface/byte_buffer_reader_test.cc
@@ -26,7 +26,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/compression/message_compress.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/util/test_config.h"
diff --git a/test/core/surface/completion_queue_threading_test.cc b/test/core/surface/completion_queue_threading_test.cc
index 37232a4fb1..391cbf39fa 100644
--- a/test/core/surface/completion_queue_threading_test.cc
+++ b/test/core/surface/completion_queue_threading_test.cc
@@ -18,11 +18,13 @@
#include "src/core/lib/surface/completion_queue.h"
+#include <new>
+
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "test/core/util/test_config.h"
@@ -78,7 +80,7 @@ static void test_too_many_plucks(void) {
grpc_completion_queue* cc;
void* tags[GRPC_MAX_COMPLETION_QUEUE_PLUCKERS];
grpc_cq_completion completions[GPR_ARRAY_SIZE(tags)];
- gpr_thd_id thread_ids[GPR_ARRAY_SIZE(tags)];
+ grpc_core::Thread threads[GPR_ARRAY_SIZE(tags)];
struct thread_state thread_states[GPR_ARRAY_SIZE(tags)];
grpc_core::ExecCtx exec_ctx;
unsigned i, j;
@@ -94,8 +96,9 @@ static void test_too_many_plucks(void) {
}
thread_states[i].cc = cc;
thread_states[i].tag = tags[i];
- gpr_thd_new(thread_ids + i, "grpc_pluck_test", pluck_one,
- thread_states + i);
+ new (&threads[i]) grpc_core::Thread("grpc_pluck_test", pluck_one,
+ thread_states + i);
+ threads[i].Start();
}
/* wait until all other threads are plucking */
@@ -111,8 +114,8 @@ static void test_too_many_plucks(void) {
nullptr, &completions[i]);
}
- for (i = 0; i < GPR_ARRAY_SIZE(tags); i++) {
- gpr_thd_join(thread_ids[i]);
+ for (auto& th : threads) {
+ th.Join();
}
shutdown_and_destroy(cc);
@@ -218,8 +221,9 @@ static void test_threading(size_t producers, size_t consumers) {
"test_threading", producers, consumers);
/* start all threads: they will wait for phase1 */
- gpr_thd_id* ids = static_cast<gpr_thd_id*>(
- gpr_malloc(sizeof(*ids) * (producers + consumers)));
+ grpc_core::Thread* threads =
+ reinterpret_cast<grpc_core::Thread*>(
+ gpr_malloc(sizeof(*threads) * (producers + consumers)));
for (i = 0; i < producers + consumers; i++) {
gpr_event_init(&options[i].on_started);
gpr_event_init(&options[i].on_phase1_done);
@@ -229,9 +233,14 @@ 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(
- &ids[i], i < producers ? "grpc_producer" : "grpc_consumer",
- i < producers ? producer_thread : consumer_thread, options + i));
+
+ bool ok;
+ new (&threads[i]) grpc_core::Thread(
+ i < producers ? "grpc_producer" : "grpc_consumer",
+ i < producers ? producer_thread : consumer_thread,
+ options + i, &ok);
+ GPR_ASSERT(ok);
+ threads[i].Start();
gpr_event_wait(&options[i].on_started, ten_seconds_time());
}
@@ -265,9 +274,10 @@ static void test_threading(size_t producers, size_t consumers) {
grpc_completion_queue_destroy(cc);
for (i = 0; i < producers + consumers; i++) {
- gpr_thd_join(ids[i]);
+ threads[i].Join();
+ threads[i].~Thread();
}
- gpr_free(ids);
+ gpr_free(threads);
/* verify that everything was produced and consumed */
for (i = 0; i < producers + consumers; i++) {
diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc
index 974263d914..9f27bacce6 100644
--- a/test/core/surface/concurrent_connectivity_test.cc
+++ b/test/core/surface/concurrent_connectivity_test.cc
@@ -22,6 +22,7 @@
headers. Therefore, sockaddr.h must always be included first */
#include "src/core/lib/iomgr/sockaddr.h"
+#include <new>
#include <memory.h>
#include <stdio.h>
@@ -30,7 +31,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/resolve_address.h"
@@ -172,21 +173,22 @@ int run_concurrent_connectivity_test() {
grpc_init();
- gpr_thd_id threads[NUM_THREADS];
- gpr_thd_id server;
-
- char* localhost = gpr_strdup("localhost:54321");
-
/* First round, no server */
+ {
gpr_log(GPR_DEBUG, "Wave 1");
- for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_new(&threads[i], "grpc_wave_1", create_loop_destroy, localhost);
+ char* localhost = gpr_strdup("localhost:54321");
+ grpc_core::Thread threads[NUM_THREADS];
+ for (auto& th : threads) {
+ new (&th) grpc_core::Thread("grpc_wave_1", create_loop_destroy, localhost);
+ th.Start();
}
- for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_join(threads[i]);
+ for (auto& th : threads) {
+ th.Join();
}
gpr_free(localhost);
+ }
+ {
/* Second round, actual grpc server */
gpr_log(GPR_DEBUG, "Wave 2");
int port = grpc_pick_unused_port_or_die();
@@ -196,44 +198,53 @@ 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, "grpc_wave_2_server", server_thread, &args);
-
- for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_new(&threads[i], "grpc_wave_2", create_loop_destroy, args.addr);
- }
- for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_join(threads[i]);
+ grpc_core::Thread server2("grpc_wave_2_server", server_thread, &args);
+ server2.Start();
+
+ grpc_core::Thread threads[NUM_THREADS];
+ for (auto& th : threads) {
+ new (&th) grpc_core::Thread("grpc_wave_2", create_loop_destroy, args.addr);
+ th.Start();
+ }
+ for (auto& th : threads) {
+ th.Join();
}
grpc_server_shutdown_and_notify(args.server, args.cq, tag(0xd1e));
- gpr_thd_join(server);
+ server2.Join();
grpc_server_destroy(args.server);
grpc_completion_queue_destroy(args.cq);
gpr_free(args.addr);
+ }
+ {
/* Third round, bogus tcp server */
gpr_log(GPR_DEBUG, "Wave 3");
args.pollset = static_cast<grpc_pollset*>(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);
+ grpc_core::Thread server3("grpc_wave_3_server", bad_server_thread, &args);
+ server3.Start();
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], "grpc_wave_3", create_loop_destroy, args.addr);
+ grpc_core::Thread threads[NUM_THREADS];
+ for (auto& th : threads) {
+ new (&th) grpc_core::Thread("grpc_wave_3", create_loop_destroy, args.addr);
+ th.Start();
}
- for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_join(threads[i]);
+ for (auto& th : threads) {
+ th.Join();
}
gpr_atm_rel_store(&args.stop, 1);
- gpr_thd_join(server);
+ server3.Join();
{
grpc_core::ExecCtx exec_ctx;
grpc_pollset_shutdown(
args.pollset, GRPC_CLOSURE_CREATE(done_pollset_shutdown, args.pollset,
grpc_schedule_on_exec_ctx));
}
+ }
grpc_shutdown();
return 0;
@@ -272,16 +283,17 @@ void watches_with_short_timeouts(void* addr) {
int run_concurrent_watches_with_short_timeouts_test() {
grpc_init();
- gpr_thd_id threads[NUM_THREADS];
+ grpc_core::Thread threads[NUM_THREADS];
char* localhost = gpr_strdup("localhost:54321");
- for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_new(&threads[i], "grpc_short_watches", watches_with_short_timeouts,
- localhost);
+ for (auto& th : threads) {
+ new (&th) grpc_core::Thread("grpc_short_watches",
+ watches_with_short_timeouts, localhost);
+ th.Start();
}
- for (size_t i = 0; i < NUM_THREADS; ++i) {
- gpr_thd_join(threads[i]);
+ for (auto& th : threads) {
+ th.Join();
}
gpr_free(localhost);
diff --git a/test/core/surface/num_external_connectivity_watchers_test.cc b/test/core/surface/num_external_connectivity_watchers_test.cc
index 49d28ad1c7..467deeeaec 100644
--- a/test/core/surface/num_external_connectivity_watchers_test.cc
+++ b/test/core/surface/num_external_connectivity_watchers_test.cc
@@ -23,7 +23,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc
index 8ca7b4f5dc..9aba4c499e 100644
--- a/test/core/surface/sequential_connectivity_test.cc
+++ b/test/core/surface/sequential_connectivity_test.cc
@@ -23,7 +23,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
-#include "src/core/lib/gpr/thd.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
@@ -67,8 +67,8 @@ static void run_test(const test_fixture* fixture) {
grpc_server_start(server);
server_thread_args sta = {server, server_cq};
- gpr_thd_id server_thread;
- gpr_thd_new(&server_thread, "grpc_server", server_thread_func, &sta);
+ grpc_core::Thread server_thread("grpc_server", server_thread_func, &sta);
+ server_thread.Start();
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
grpc_channel* channels[NUM_CONNECTIONS];
@@ -93,7 +93,7 @@ static void run_test(const test_fixture* fixture) {
}
grpc_server_shutdown_and_notify(server, server_cq, nullptr);
- gpr_thd_join(server_thread);
+ server_thread.Join();
grpc_completion_queue_shutdown(server_cq);
grpc_completion_queue_shutdown(cq);
diff --git a/test/core/tsi/transport_security_test_lib.cc b/test/core/tsi/transport_security_test_lib.cc
index 7af6431c66..8ea83f7088 100644
--- a/test/core/tsi/transport_security_test_lib.cc
+++ b/test/core/tsi/transport_security_test_lib.cc
@@ -24,7 +24,6 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-#include "src/core/lib/gpr/thd.h"
#include "src/core/lib/security/transport/tsi_error.h"
#include "test/core/tsi/transport_security_test_lib.h"