aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/surface/completion_queue_threading_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/surface/completion_queue_threading_test.cc
parent5e1298f0a826777b0e5b844328b81216e9c37476 (diff)
C++ize gpr_thread as grpc_core::Thread, make it 2-phase init (construct/Start)
Diffstat (limited to 'test/core/surface/completion_queue_threading_test.cc')
-rw-r--r--test/core/surface/completion_queue_threading_test.cc36
1 files changed, 23 insertions, 13 deletions
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++) {