From f50020ce038411b2a0864cb61296b67ac1cc032e Mon Sep 17 00:00:00 2001 From: Vijay Pai <vpai@google.com> Date: Mon, 8 Aug 2016 07:29:31 -0700 Subject: [PATCH] Appease the const gods, improve readability, stop using 0 and 1 as proxies for false and true. --- test/cpp/qps/client.h | 11 ++++------- test/cpp/qps/client_sync.cc | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 5b1a1c3b82..fada4ba767 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -169,7 +169,7 @@ class Client { // Must call AwaitThreadsCompletion before destructor to avoid a race // between destructor and invocation of virtual ThreadFunc void AwaitThreadsCompletion() { - gpr_atm_rel_store(&thread_pool_done_, static_cast<gpr_atm>(1)); + gpr_atm_rel_store(&thread_pool_done_, static_cast<gpr_atm>(true)); DestroyMultithreading(); std::unique_lock<std::mutex> g(thread_completion_mu_); while (threads_remaining_ != 0) { @@ -182,7 +182,7 @@ class Client { gpr_atm thread_pool_done_; void StartThreads(size_t num_threads) { - gpr_atm_rel_store(&thread_pool_done_, static_cast<gpr_atm>(0)); + gpr_atm_rel_store(&thread_pool_done_, static_cast<gpr_atm>(false)); threads_remaining_ = num_threads; for (size_t i = 0; i < num_threads; i++) { threads_.emplace_back(new Thread(this, i)); @@ -274,14 +274,11 @@ class Client { if (entry.used()) { histogram_.Add(entry.value()); } - bool done = false; if (!thread_still_ok) { gpr_log(GPR_ERROR, "Finishing client thread due to RPC error"); - done = true; } - done = done || (gpr_atm_acq_load(&client_->thread_pool_done_) != - static_cast<gpr_atm>(0)); - if (done) { + if (!thread_still_ok || + static_cast<bool>(gpr_atm_acq_load(&client_->thread_pool_done_))) { client_->CompleteThread(); return; } diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index 53e004ffa0..8062424a1f 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -82,12 +82,12 @@ class SynchronousClient // WaitToIssue returns false if we realize that we need to break out bool WaitToIssue(int thread_idx) { if (!closed_loop_) { - gpr_timespec next_issue_time = NextIssueTime(thread_idx); + const gpr_timespec next_issue_time = NextIssueTime(thread_idx); // Avoid sleeping for too long continuously because we might // need to terminate before then. This is an issue since // exponential distribution can occasionally produce bad outliers while (true) { - gpr_timespec one_sec_delay = + const gpr_timespec one_sec_delay = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(1, GPR_TIMESPAN)); if (gpr_time_cmp(next_issue_time, one_sec_delay) <= 0) { -- GitLab