aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/iomgr
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/iomgr
parent5e1298f0a826777b0e5b844328b81216e9c37476 (diff)
C++ize gpr_thread as grpc_core::Thread, make it 2-phase init (construct/Start)
Diffstat (limited to 'test/core/iomgr')
-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
5 files changed, 43 insertions, 24 deletions
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) {