aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/gpr/mpscq_test.cc
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/gpr/mpscq_test.cc
parent5e1298f0a826777b0e5b844328b81216e9c37476 (diff)
C++ize gpr_thread as grpc_core::Thread, make it 2-phase init (construct/Start)
Diffstat (limited to 'test/core/gpr/mpscq_test.cc')
-rw-r--r--test/core/gpr/mpscq_test.cc33
1 files changed, 18 insertions, 15 deletions
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);
}