aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/gpr/cpu_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/cpu_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/cpu_test.cc')
-rw-r--r--test/core/gpr/cpu_test.cc21
1 files changed, 13 insertions, 8 deletions
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 [");