aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar David G. Quintas <dgq@google.com>2017-08-03 09:40:56 -0700
committerGravatar GitHub <noreply@github.com>2017-08-03 09:40:56 -0700
commit8eb47ed2506991abce75b9147ed8378ad8df6c0a (patch)
tree826aa0fc1fe2a32daec49acf7401164c090b96b8
parent1420c1a3497a1fe808fb26383e737c72bd6af5ba (diff)
parentecabe09b8918b33a1cca2bc8c7f2e44f9949442b (diff)
Merge pull request #12051 from dgquintas/fix_grpclbend2end_condvars
Condition variables are not latches
-rw-r--r--test/cpp/end2end/grpclb_end2end_test.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc
index 4fef535506..b5cff664f6 100644
--- a/test/cpp/end2end/grpclb_end2end_test.cc
+++ b/test/cpp/end2end/grpclb_end2end_test.cc
@@ -215,7 +215,8 @@ class BalancerServiceImpl : public BalancerService {
{
std::unique_lock<std::mutex> lock(mu_);
if (shutdown_) goto done;
- serverlist_cond_.wait(lock);
+ serverlist_cond_.wait(lock, [this] { return serverlist_ready_; });
+ serverlist_ready_ = false;
}
if (client_load_reporting_interval_seconds_ > 0) {
@@ -242,6 +243,7 @@ class BalancerServiceImpl : public BalancerService {
.drop_token_counts[drop_token_count.load_balance_token()] +=
drop_token_count.num_calls();
}
+ load_report_ready_ = true;
load_report_cond_.notify_one();
}
done:
@@ -285,12 +287,14 @@ class BalancerServiceImpl : public BalancerService {
const ClientStats& WaitForLoadReport() {
std::unique_lock<std::mutex> lock(mu_);
- load_report_cond_.wait(lock);
+ load_report_cond_.wait(lock, [this] { return load_report_ready_; });
+ load_report_ready_ = false;
return client_stats_;
}
void NotifyDoneWithServerlists() {
std::lock_guard<std::mutex> lock(mu_);
+ serverlist_ready_ = true;
serverlist_cond_.notify_one();
}
@@ -313,7 +317,9 @@ class BalancerServiceImpl : public BalancerService {
std::vector<ResponseDelayPair> responses_and_delays_;
std::mutex mu_;
std::condition_variable load_report_cond_;
+ bool load_report_ready_ = false;
std::condition_variable serverlist_cond_;
+ bool serverlist_ready_ = false;
ClientStats client_stats_;
bool shutdown_;
};