diff options
Diffstat (limited to 'test/core/gpr/cpu_test.cc')
-rw-r--r-- | test/core/gpr/cpu_test.cc | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/test/core/gpr/cpu_test.cc b/test/core/gpr/cpu_test.cc index 9f2c3f1923..1052d40b42 100644 --- a/test/core/gpr/cpu_test.cc +++ b/test/core/gpr/cpu_test.cc @@ -21,15 +21,17 @@ gpr_cpu_current_cpu() */ -#include <grpc/support/alloc.h> #include <grpc/support/cpu.h> + +#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 +103,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; @@ -110,15 +111,24 @@ static void cpu_test(void) { gpr_mu_init(&ct.mu); gpr_cv_init(&ct.done_cv); ct.is_done = 0; - for (i = 0; i < ct.ncores * 3; i++) { - GPR_ASSERT( - gpr_thd_new(&thd, "grpc_cpu_test", &worker_thread, &ct, nullptr)); + + uint32_t nthreads = ct.ncores * 3; + grpc_core::Thread* thd = + static_cast<grpc_core::Thread*>(gpr_malloc(sizeof(*thd) * nthreads)); + + for (i = 0; i < nthreads; i++) { + thd[i] = grpc_core::Thread("grpc_cpu_test", &worker_thread, &ct); + thd[i].Start(); } gpr_mu_lock(&ct.mu); while (!ct.is_done) { gpr_cv_wait(&ct.done_cv, &ct.mu, gpr_inf_future(GPR_CLOCK_MONOTONIC)); } gpr_mu_unlock(&ct.mu); + for (i = 0; i < nthreads; i++) { + thd[i].Join(); + } + gpr_free(thd); fprintf(stderr, "Saw cores ["); fflush(stderr); for (i = 0; i < ct.ncores; i++) { |