Address some feedback from clang-tidy

This commit is contained in:
Tyler Neely 2022-08-01 15:37:16 +00:00
parent 5bb3361a2d
commit 9576eea051
8 changed files with 29 additions and 32 deletions

View File

@ -47,12 +47,10 @@ struct Address {
if (unique_id == other.unique_id) {
if (last_known_ip == other.last_known_ip) {
return last_known_port < other.last_known_port;
} else {
return last_known_ip < other.last_known_ip;
}
} else {
return unique_id < other.unique_id;
return last_known_ip < other.last_known_ip;
}
return unique_id < other.unique_id;
}
std::string ToString() const {

View File

@ -108,9 +108,9 @@ class Shared {
if (item_) {
return Take(lock);
} else {
return std::nullopt;
}
return std::nullopt;
}
void Fill(T item) {
@ -142,14 +142,14 @@ class Future {
explicit Future(std::shared_ptr<details::Shared<T>> shared) : shared_(shared) {}
Future() = delete;
Future(Future &&old) {
Future(Future &&old) noexcept {
MG_ASSERT(!old.consumed_or_moved_, "Future moved from after already being moved from or consumed.");
shared_ = std::move(old.shared_);
consumed_or_moved_ = old.consumed_or_moved_;
old.consumed_or_moved_ = true;
}
Future &operator=(Future &&old) {
Future &operator=(Future &&old) noexcept {
MG_ASSERT(!old.consumed_or_moved_, "Future moved from after already being moved from or consumed.");
shared_ = std::move(old.shared_);
old.consumed_or_moved_ = true;
@ -205,13 +205,13 @@ class Promise {
explicit Promise(std::shared_ptr<details::Shared<T>> shared) : shared_(shared) {}
Promise() = delete;
Promise(Promise &&old) {
Promise(Promise &&old) noexcept {
MG_ASSERT(!old.filled_or_moved_, "Promise moved from after already being moved from or filled.");
shared_ = std::move(old.shared_);
old.filled_or_moved_ = true;
}
Promise &operator=(Promise &&old) {
Promise &operator=(Promise &&old) noexcept {
MG_ASSERT(!old.filled_or_moved_, "Promise moved from after already being moved from or filled.");
shared_ = std::move(old.shared_);
old.filled_or_moved_ = true;

View File

@ -67,9 +67,9 @@ struct OpaqueMessage {
.request_id = request_id,
.from_address = from_address,
};
} else {
return std::nullopt;
}
return std::nullopt;
}
};
@ -82,17 +82,17 @@ class OpaquePromise {
std::function<void(void *)> time_out_;
public:
OpaquePromise(OpaquePromise &&old)
OpaquePromise(OpaquePromise &&old) noexcept
: ti_(old.ti_),
ptr_(old.ptr_),
dtor_(old.dtor_),
is_awaited_(old.is_awaited_),
fill_(old.fill_),
time_out_(old.time_out_) {
dtor_(std::move(old.dtor_)),
is_awaited_(std::move(old.is_awaited_)),
fill_(std::move(old.fill_)),
time_out_(std::move(old.time_out_)) {
old.ptr_ = nullptr;
}
OpaquePromise &operator=(OpaquePromise &&old) {
OpaquePromise &operator=(OpaquePromise &&old) noexcept {
MG_ASSERT(this != &old);
ptr_ = old.ptr_;
@ -115,7 +115,7 @@ class OpaquePromise {
MG_ASSERT(typeid(T) == *ti_);
MG_ASSERT(ptr_ != nullptr);
ResponsePromise<T> *ptr = static_cast<ResponsePromise<T> *>(ptr_);
auto ptr = static_cast<ResponsePromise<T> *>(ptr_);
ptr_ = nullptr;
@ -133,12 +133,12 @@ class OpaquePromise {
auto response_envelope = ResponseEnvelope<T>{.message = std::move(message),
.request_id = opaque_message.request_id,
.from_address = opaque_message.from_address};
ResponsePromise<T> *promise = static_cast<ResponsePromise<T> *>(this_ptr);
auto promise = static_cast<ResponsePromise<T> *>(this_ptr);
auto unique_promise = std::unique_ptr<ResponsePromise<T>>(promise);
unique_promise->Fill(std::move(response_envelope));
}),
time_out_([](void *ptr) {
ResponsePromise<T> *promise = static_cast<ResponsePromise<T> *>(ptr);
auto promise = static_cast<ResponsePromise<T> *>(ptr);
auto unique_promise = std::unique_ptr<ResponsePromise<T>>(promise);
ResponseResult<T> result = TimedOut{};
unique_promise->Fill(std::move(result));

View File

@ -33,7 +33,7 @@ class Simulator {
Io<SimulatorTransport> Register(Address address) {
std::uniform_int_distribution<uint64_t> seed_distrib;
uint64_t seed = seed_distrib(rng_);
return Io(SimulatorTransport(simulator_handle_, address, seed), address);
return Io{SimulatorTransport{simulator_handle_, address, seed}, address};
}
void IncrementServerCountAndWaitForQuiescentState(Address address) {

View File

@ -47,12 +47,10 @@ struct PromiseKey {
if (requester_address == other.requester_address) {
if (request_id == other.request_id) {
return replier_address < other.replier_address;
} else {
return request_id < other.request_id;
}
} else {
return requester_address < other.requester_address;
return request_id < other.request_id;
}
return requester_address < other.requester_address;
}
};
@ -120,9 +118,9 @@ class SimulatorHandle {
const Time deadline = cluster_wide_time_microseconds_ + timeout;
std::any message(std::move(request));
std::any message(std::forward(request));
OpaqueMessage om{.from_address = from_address, .request_id = request_id, .message = std::move(message)};
in_flight_.emplace_back(std::make_pair(std::move(to_address), std::move(om)));
in_flight_.emplace_back(std::make_pair(to_address, std::move(om)));
PromiseKey promise_key{.requester_address = from_address, .request_id = request_id, .replier_address = to_address};
OpaquePromise opaque_promise(std::move(promise).ToUnique());
@ -133,8 +131,6 @@ class SimulatorHandle {
stats_.total_requests++;
cv_.notify_all();
return;
}
template <Message... Ms>

View File

@ -11,6 +11,8 @@
#pragma once
#include <cstdint>
namespace memgraph::io::simulator {
struct SimulatorStats {
uint64_t total_messages = 0;

View File

@ -22,9 +22,10 @@
#include "io/time.hpp"
#include "utils/result.hpp"
namespace memgraph::io {
using memgraph::utils::BasicResult;
namespace memgraph::io {
// TODO(tyler) ensure that Message continues to represent
// reasonable constraints around message types over time,
// as we adapt things to use Thrift-generated message types.

View File

@ -30,7 +30,7 @@ struct CounterResponse {
};
void run_server(Io<SimulatorTransport> io) {
uint64_t highest_seen;
uint64_t highest_seen = 0;
while (!io.ShouldShutDown()) {
std::cout << "[SERVER] Is receiving..." << std::endl;