diff options
author | Sree Kuchibhotla <sreek@google.com> | 2015-11-19 10:28:47 -0800 |
---|---|---|
committer | Sree Kuchibhotla <sreek@google.com> | 2015-11-19 10:28:47 -0800 |
commit | 52a514a25089991d78da66f8ab64080123d4debf (patch) | |
tree | 39a6fdea19d719350b9a5b913802d2dfe6837fd5 /test/cpp/util/metrics_server.cc | |
parent | 87f51663eef39993f939d5b1b5914d822fa1f8bc (diff) |
Address code review comments
Diffstat (limited to 'test/cpp/util/metrics_server.cc')
-rw-r--r-- | test/cpp/util/metrics_server.cc | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/test/cpp/util/metrics_server.cc b/test/cpp/util/metrics_server.cc index 5bb87e53f1..8db22fbecf 100644 --- a/test/cpp/util/metrics_server.cc +++ b/test/cpp/util/metrics_server.cc @@ -33,8 +33,6 @@ #include "test/cpp/util/metrics_server.h" -#include <vector> - #include <grpc++/server_builder.h> #include "test/proto/metrics.grpc.pb.h" @@ -43,15 +41,17 @@ namespace grpc { namespace testing { -using std::vector; - Gauge::Gauge(long initial_val) : val_(initial_val) {} void Gauge::Set(long new_val) { - val_.store(new_val, std::memory_order_relaxed); + std::lock_guard<std::mutex> lock(val_mu_); + val_ = new_val; } -long Gauge::Get() { return val_.load(std::memory_order_relaxed); } +long Gauge::Get() { + std::lock_guard<std::mutex> lock(val_mu_); + return val_; +} grpc::Status MetricsServiceImpl::GetAllGauges( ServerContext* context, const EmptyMessage* request, @@ -74,7 +74,7 @@ grpc::Status MetricsServiceImpl::GetGauge(ServerContext* context, GaugeResponse* response) { std::lock_guard<std::mutex> lock(mu_); - auto it = gauges_.find(request->name()); + const auto it = gauges_.find(request->name()); if (it != gauges_.end()) { response->set_name(it->first); response->set_long_value(it->second->Get()); @@ -88,16 +88,17 @@ std::shared_ptr<Gauge> MetricsServiceImpl::CreateGauge(const grpc::string& name, std::lock_guard<std::mutex> lock(mu_); std::shared_ptr<Gauge> gauge(new Gauge(0)); - auto p = gauges_.emplace(name, gauge); + const auto p = gauges_.emplace(name, gauge); // p.first is an iterator pointing to <name, shared_ptr<Gauge>> pair. p.second - // is a boolean indicating if the Gauge is already present in the map + // is a boolean which is set to 'true' if the Gauge is inserted in the guages_ + // map and 'false' if it is already present in the map *already_present = !p.second; return p.first->second; } -// Starts the metrics server and returns the grpc::Server instance. Call -// wait() on the returned server instance. +// Starts the metrics server and returns the grpc::Server instance. Call Wait() +// on the returned server instance. std::unique_ptr<grpc::Server> MetricsServiceImpl::StartServer(int port) { gpr_log(GPR_INFO, "Building metrics server.."); |