Skip to content

Commit

Permalink
Fixed more lambda warnings throughout the sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
grixa committed Jun 23, 2018
1 parent 15bf817 commit cd402ca
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 110 deletions.
2 changes: 1 addition & 1 deletion blocks/http/test.cc
Expand Up @@ -1615,7 +1615,7 @@ TEST(HTTPAPI, ResponseSmokeTest) {
}) +
HTTP(FLAGS_net_api_test_port)
.Register("/response10",
[send_response](Request r) {
[](Request r) {
SerializableVariant v;
v.template Construct<SerializableObject>();
r(v);
Expand Down
4 changes: 1 addition & 3 deletions blocks/http/types.h
Expand Up @@ -122,9 +122,7 @@ template <typename REQUEST>
struct FillBody<REQUEST, false> {
template <typename T>
static typename std::enable_if<IS_CURRENT_STRUCT_OR_VARIANT(current::decay<T>)>::type Fill(
REQUEST& request,
T&& object,
const std::string& content_type) {
REQUEST& request, T&& object, const std::string& content_type) {
request.body = JSON(std::forward<T>(object));
request.content_type = !content_type.empty() ? content_type : net::constants::kDefaultJSONContentType;
}
Expand Down
4 changes: 2 additions & 2 deletions bricks/graph/gnuplot.h
Expand Up @@ -235,8 +235,8 @@ struct GNUPlot {
}
}
if (output_format_ != "gnuplot") {
CURRENT_ASSERT(!bricks::system::SystemCall(current::strings::Printf(
strings::Printf("gnuplot <%s >%s", input_file_name.c_str(), output_file_name.c_str()).c_str())));
CURRENT_ASSERT(!bricks::system::SystemCall(
strings::Printf("gnuplot <%s >%s", input_file_name.c_str(), output_file_name.c_str())));
return current::FileSystem::ReadFileAsString(output_file_name.c_str());
} else {
// For unit tests, just compare the inputs.
Expand Down
2 changes: 1 addition & 1 deletion bricks/sync/test.cc
Expand Up @@ -181,7 +181,7 @@ TEST(OwnedBorrowed, BorrowedWithCallbackOutlivingTheOwner) {
std::atomic_bool terminating(false);
// The `unique_ptr` ugliness is to have the pre-initialized `current::BorrowedWithCallback` movable.
thread = std::make_unique<std::thread>(
[&log, &terminating](std::unique_ptr<current::BorrowedWithCallback<Container>> y0) {
[&terminating](std::unique_ptr<current::BorrowedWithCallback<Container>> y0) {
current::BorrowedWithCallback<Container>& y = *y0.get();
EXPECT_TRUE(static_cast<bool>(y));
// Keep incrementing until external termination request.
Expand Down
187 changes: 91 additions & 96 deletions karl/karl.h
Expand Up @@ -336,7 +336,7 @@ class GenericKarl final : private KarlStorage<STORAGE_TYPE>,
public:
~GenericKarl() {
destructing_ = true;
storage_->ReadWriteTransaction([this](MutableFields<storage_t> fields) {
storage_->ReadWriteTransaction([](MutableFields<storage_t> fields) {
KarlInfo self_info;
self_info.up = false;
fields.karl.Add(self_info);
Expand Down Expand Up @@ -547,105 +547,100 @@ class GenericKarl final : private KarlStorage<STORAGE_TYPE>,
}

auto& notifiable_ref = notifiable_ref_;
storage_->ReadWriteTransaction(
[this,
now,
location,
&parsed_status,
&detailed_parsed_status,
optional_behind_this_by,
&notifiable_ref](MutableFields<storage_t> fields) -> Response {
// OK to call from within a transaction.
// The call is fast, and `storage_`'s transaction guarantees thread safety. -- D.K.
notifiable_ref.OnKeepalive(now, location, parsed_status.codename, detailed_parsed_status);

const auto& service = parsed_status.service;
const auto& codename = parsed_status.codename;
const auto& optional_build = parsed_status.build;
const auto& optional_instance = parsed_status.cloud_instance_name;
const auto& optional_av_group = parsed_status.cloud_availability_group;

// Update per-server information in the `DB`.
ServerInfo server;
server.ip = location.ip;
bool need_to_update_server_info = false;
const ImmutableOptional<ServerInfo> current_server_info = fields.servers[location.ip];
if (Exists(current_server_info)) {
server = Value(current_server_info);
}
// Check the instance name.
if (Exists(optional_instance)) {
if (!Exists(server.cloud_instance_name) ||
Value(server.cloud_instance_name) != Value(optional_instance)) {
server.cloud_instance_name = Value(optional_instance);
need_to_update_server_info = true;
}
}
// Check the availability group.
if (Exists(optional_av_group)) {
if (!Exists(server.cloud_availability_group) ||
Value(server.cloud_availability_group) != Value(optional_av_group)) {
server.cloud_availability_group = Value(optional_av_group);
need_to_update_server_info = true;
}
}
// Check the time skew.
if (Exists(optional_behind_this_by)) {
const std::chrono::microseconds behind_this_by = Value(optional_behind_this_by);
const auto time_skew_difference = server.behind_this_by - behind_this_by;
if (static_cast<uint64_t>(std::abs(time_skew_difference.count())) >=
kUpdateServerInfoThresholdByTimeSkewDifference) {
server.behind_this_by = behind_this_by;
need_to_update_server_info = true;
}
}
if (need_to_update_server_info) {
fields.servers.Add(server);
}
storage_
->ReadWriteTransaction(
[now, location, &parsed_status, &detailed_parsed_status, optional_behind_this_by, &notifiable_ref](
MutableFields<storage_t> fields) -> Response {
// OK to call from within a transaction.
// The call is fast, and `storage_`'s transaction guarantees thread safety. -- D.K.
notifiable_ref.OnKeepalive(now, location, parsed_status.codename, detailed_parsed_status);

const auto& service = parsed_status.service;
const auto& codename = parsed_status.codename;
const auto& optional_build = parsed_status.build;
const auto& optional_instance = parsed_status.cloud_instance_name;
const auto& optional_av_group = parsed_status.cloud_availability_group;

// Update per-server information in the `DB`.
ServerInfo server;
server.ip = location.ip;
bool need_to_update_server_info = false;
const ImmutableOptional<ServerInfo> current_server_info = fields.servers[location.ip];
if (Exists(current_server_info)) {
server = Value(current_server_info);
}
// Check the instance name.
if (Exists(optional_instance)) {
if (!Exists(server.cloud_instance_name) ||
Value(server.cloud_instance_name) != Value(optional_instance)) {
server.cloud_instance_name = Value(optional_instance);
need_to_update_server_info = true;
}
}
// Check the availability group.
if (Exists(optional_av_group)) {
if (!Exists(server.cloud_availability_group) ||
Value(server.cloud_availability_group) != Value(optional_av_group)) {
server.cloud_availability_group = Value(optional_av_group);
need_to_update_server_info = true;
}
}
// Check the time skew.
if (Exists(optional_behind_this_by)) {
const std::chrono::microseconds behind_this_by = Value(optional_behind_this_by);
const auto time_skew_difference = server.behind_this_by - behind_this_by;
if (static_cast<uint64_t>(std::abs(time_skew_difference.count())) >=
kUpdateServerInfoThresholdByTimeSkewDifference) {
server.behind_this_by = behind_this_by;
need_to_update_server_info = true;
}
}
if (need_to_update_server_info) {
fields.servers.Add(server);
}

// Update the `DB` if the build information was not stored there yet.
const ImmutableOptional<ClaireBuildInfo> current_claire_build_info = fields.builds[codename];
if (Exists(optional_build) &&
(!Exists(current_claire_build_info) ||
Value(current_claire_build_info).build != Value(optional_build))) {
ClaireBuildInfo build;
build.codename = codename;
build.build = Value(optional_build);
fields.builds.Add(build);
}
// Update the `DB` if the build information was not stored there yet.
const ImmutableOptional<ClaireBuildInfo> current_claire_build_info = fields.builds[codename];
if (Exists(optional_build) && (!Exists(current_claire_build_info) ||
Value(current_claire_build_info).build != Value(optional_build))) {
ClaireBuildInfo build;
build.codename = codename;
build.build = Value(optional_build);
fields.builds.Add(build);
}

// Update the `DB` if "codename", "location", or "dependencies" differ.
const ImmutableOptional<ClaireInfo> current_claire_info = fields.claires[codename];
if ([&]() {
if (!Exists(current_claire_info)) {
return true;
} else if (Value(current_claire_info).location != location) {
return true;
} else if (Value(current_claire_info).registered_state !=
ClaireRegisteredState::Active) {
return true;
} else {
return false;
}
}()) {
ClaireInfo claire;
if (Exists(current_claire_info)) {
// Do not overwrite `build` with `null`.
claire = Value(current_claire_info);
// Update the `DB` if "codename", "location", or "dependencies" differ.
const ImmutableOptional<ClaireInfo> current_claire_info = fields.claires[codename];
if ([&]() {
if (!Exists(current_claire_info)) {
return true;
} else if (Value(current_claire_info).location != location) {
return true;
} else if (Value(current_claire_info).registered_state != ClaireRegisteredState::Active) {
return true;
} else {
return false;
}
}()) {
ClaireInfo claire;
if (Exists(current_claire_info)) {
// Do not overwrite `build` with `null`.
claire = Value(current_claire_info);
}

claire.codename = codename;
claire.service = service;
claire.location = location;
claire.reported_timestamp = now;
claire.url_status_page_direct = location.StatusPageURL();
claire.registered_state = ClaireRegisteredState::Active;
claire.codename = codename;
claire.service = service;
claire.location = location;
claire.reported_timestamp = now;
claire.url_status_page_direct = location.StatusPageURL();
claire.registered_state = ClaireRegisteredState::Active;

fields.claires.Add(claire);
}
return Response("OK\n");
},
std::move(r)).Wait();
fields.claires.Add(claire);
}
return Response("OK\n");
},
std::move(r))
.Wait();
{
std::lock_guard<std::mutex> lock(services_keepalive_cache_mutex_);
auto& placeholder = services_keepalive_time_cache_[parsed_status.codename];
Expand Down Expand Up @@ -704,7 +699,7 @@ class GenericKarl final : private KarlStorage<STORAGE_TYPE>,

void ServeBuild(Request r) {
const auto codename = r.url_path_args[0];
storage_->ReadOnlyTransaction([this, codename](ImmutableFields<storage_t> fields) -> Response {
storage_->ReadOnlyTransaction([codename](ImmutableFields<storage_t> fields) -> Response {
const auto result = fields.builds[codename];
if (Exists(result)) {
return Value(result);
Expand Down
2 changes: 1 addition & 1 deletion karl/test_service/http_subscriber.h
Expand Up @@ -66,7 +66,7 @@ class HTTPStreamSubscriber {
HTTP(ChunkedGET(url,
[this](const std::string& header, const std::string& value) { OnHeader(header, value); },
[this](const std::string& chunk_body) { OnChunk(chunk_body); },
[this]() {}));
[]() {}));
} catch (current::net::NetworkException& e) {
std::cerr << e.DetailedDescription() << std::endl;
CURRENT_ASSERT(false);
Expand Down
10 changes: 4 additions & 6 deletions nlp/nlp.h
Expand Up @@ -146,10 +146,8 @@ struct OrImplWithVariant {
size_t begin,
size_t end,
std::function<void(const emitted_t&)> emit) const {
lhs_impl_.EvalImpl(
query, begin, end, [&query, begin, end, &emit](const LHS_TYPE& value) { emit(emitted_t(value)); });
rhs_impl_.EvalImpl(
query, begin, end, [&query, begin, end, &emit](const RHS_TYPE& value) { emit(emitted_t(value)); });
lhs_impl_.EvalImpl(query, begin, end, [&emit](const LHS_TYPE& value) { emit(emitted_t(value)); });
rhs_impl_.EvalImpl(query, begin, end, [&emit](const RHS_TYPE& value) { emit(emitted_t(value)); });
}
};

Expand All @@ -165,8 +163,8 @@ struct OrImplSameType {
size_t begin,
size_t end,
std::function<void(const emitted_t&)> emit) const {
lhs_impl_.EvalImpl(query, begin, end, [&query, begin, end, &emit](const TYPE& value) { emit(emitted_t(value)); });
rhs_impl_.EvalImpl(query, begin, end, [&query, begin, end, &emit](const TYPE& value) { emit(emitted_t(value)); });
lhs_impl_.EvalImpl(query, begin, end, [&emit](const TYPE& value) { emit(emitted_t(value)); });
rhs_impl_.EvalImpl(query, begin, end, [&emit](const TYPE& value) { emit(emitted_t(value)); });
}
};

Expand Down

0 comments on commit cd402ca

Please sign in to comment.