diff --git a/agent_based_epidemic_sim/core/simulation.cc b/agent_based_epidemic_sim/core/simulation.cc index aeaccc3..3d8ec62 100644 --- a/agent_based_epidemic_sim/core/simulation.cc +++ b/agent_based_epidemic_sim/core/simulation.cc @@ -298,7 +298,7 @@ class WorkQueueBroker : public Broker { WorkQueueBroker* const broker; }; virtual void Delete(std::vector>* const msgs) { - absl::MutexLock l(&mu_); + absl::MutexLock l(mu_); DCHECK_EQ(msgs, &consume_); std::for_each(consume_.begin(), consume_.end(), [](auto& v) { v.clear(); }); // We are using swapping buffers so we're always reading from one @@ -316,7 +316,7 @@ class WorkQueueBroker : public Broker { send_(chunker.Chunks().size()), consume_(chunker.Chunks().size()) {} void Send(const absl::Span msgs) override { - absl::MutexLock l(&mu_); + absl::MutexLock l(mu_); for (const Msg& msg : msgs) { int chunk = chunker_.Chunk(msg); send_[chunk].push_back(msg); @@ -324,7 +324,7 @@ class WorkQueueBroker : public Broker { sent_msgs_ = true; } virtual std::unique_ptr>, Deleter> Consume() { - absl::MutexLock l(&mu_); + absl::MutexLock l(mu_); DCHECK(std::all_of(consume_.begin(), consume_.end(), [](const std::vector& v) { return v.empty(); })); sent_msgs_ = false; @@ -369,7 +369,7 @@ void ParallelAgentPhase(const Timestep& timestep, Executor& executor, absl::Span my_reports; absl::Span> my_agents; { - absl::MutexLock l(&mu); + absl::MutexLock l(mu); int chunk = next_chunk++; if (chunk >= chunker.Chunks().size()) break; my_agents = chunker.Chunks()[chunk]; @@ -413,7 +413,7 @@ void ParallelLocationPhase(const Timestep& timestep, Executor& executor, absl::Span my_visits; absl::Span> my_locations; { - absl::MutexLock l(&mu); + absl::MutexLock l(mu); int chunk = next_chunk++; if (chunk >= chunker.Chunks().size()) break; my_locations = chunker.Chunks()[chunk]; diff --git a/agent_based_epidemic_sim/core/simulation_test.cc b/agent_based_epidemic_sim/core/simulation_test.cc index 71adaeb..24ff1b1 100644 --- a/agent_based_epidemic_sim/core/simulation_test.cc +++ b/agent_based_epidemic_sim/core/simulation_test.cc @@ -80,7 +80,7 @@ std::unique_ptr MakeAgent(int64 uuid, OutcomeMap* outcome_counts, ASSERT_EQ(outcome.agent_uuid, uuid); } { - absl::MutexLock l(&map_mu); + absl::MutexLock l(map_mu); (*outcome_counts)[uuid] += infection_outcomes.size(); } if (!last_timestep->has_value()) { @@ -98,7 +98,7 @@ std::unique_ptr MakeAgent(int64 uuid, OutcomeMap* outcome_counts, absl::Span symptom_reports, Broker* symptom_broker) { { - absl::MutexLock l(&map_mu); + absl::MutexLock l(map_mu); for (const auto& report : symptom_reports) { ASSERT_EQ(report.to_agent_uuid, uuid); ASSERT_EQ(report.test_result.time_received, @@ -128,7 +128,7 @@ std::unique_ptr MakeLocation(int64 uuid, VisitMap* visit_counts) { for (const Visit& visit : visits) { ASSERT_EQ(visit.location_uuid, uuid); { - absl::MutexLock l(&map_mu); + absl::MutexLock l(map_mu); (*visit_counts)[{uuid, visit.agent_uuid}]++; } infection_broker->Send({{.agent_uuid = visit.agent_uuid}}); @@ -228,7 +228,7 @@ std::unique_ptr BuildSimulator(SimBuilder builder, void CheckSimulatorResults(const OutcomeMap& outcomes, const VisitMap& visits, const ReportMap& reports) { - absl::MutexLock l(&map_mu); + absl::MutexLock l(map_mu); for (int i = 0; i < kNumAgents; i++) { auto outcome = outcomes.find(i); ASSERT_NE(outcome, outcomes.end()); diff --git a/agent_based_epidemic_sim/port/deps/logging.cc b/agent_based_epidemic_sim/port/deps/logging.cc index 0bfec43..0d069b4 100644 --- a/agent_based_epidemic_sim/port/deps/logging.cc +++ b/agent_based_epidemic_sim/port/deps/logging.cc @@ -38,13 +38,13 @@ constexpr char kDefaultDirectory[] = "/tmp/"; namespace { // The logging directory. -ABSL_CONST_INIT std::string *log_file_directory = nullptr; +ABSL_CONST_INIT std::string* log_file_directory = nullptr; // The log filename. -ABSL_CONST_INIT std::string *log_basename = nullptr; +ABSL_CONST_INIT std::string* log_basename = nullptr; -const char *GetBasename(const char *file_path) { - const char *slash = strrchr(file_path, '/'); +const char* GetBasename(const char* file_path) { + const char* slash = strrchr(file_path, '/'); return slash ? slash + 1 : file_path; } @@ -66,20 +66,20 @@ std::string get_log_directory() { namespace logging_internal { -LogMessage::LogMessage(const char *file, int line) +LogMessage::LogMessage(const char* file, int line) : LogMessage(file, line, absl::LogSeverity::kInfo) {} -LogMessage::LogMessage(const char *file, int line, const std::string &result) +LogMessage::LogMessage(const char* file, int line, const std::string& result) : LogMessage(file, line, absl::LogSeverity::kFatal) { stream() << "Check failed: " << result << " "; } -static constexpr const char *LogSeverityNames[4] = {"INFO", "WARNING", "ERROR", +static constexpr const char* LogSeverityNames[4] = {"INFO", "WARNING", "ERROR", "FATAL"}; -LogMessage::LogMessage(const char *file, int line, absl::LogSeverity severity) +LogMessage::LogMessage(const char* file, int line, absl::LogSeverity severity) : severity_(severity) { - const char *filename = GetBasename(file); + const char* filename = GetBasename(file); // Write a prefix into the log message, including local date/time, severity // level, filename, and line number. @@ -103,10 +103,10 @@ LogMessage::~LogMessage() { } } -void LogMessage::SendToLog(const std::string &message_text) { +void LogMessage::SendToLog(const std::string& message_text) { std::string log_path = get_log_directory() + get_log_basename(); - FILE *file = fopen(log_path.c_str(), "ab"); + FILE* file = fopen(log_path.c_str(), "ab"); if (file) { if (fprintf(file, "%s", message_text.c_str()) > 0) { if (message_text.back() != '\n') { diff --git a/agent_based_epidemic_sim/port/deps/logging.h b/agent_based_epidemic_sim/port/deps/logging.h index 787cec5..bf23208 100644 --- a/agent_based_epidemic_sim/port/deps/logging.h +++ b/agent_based_epidemic_sim/port/deps/logging.h @@ -30,14 +30,14 @@ class LogMessage { // // file: source file that produced the log. // line: source code line that produced the log. - LogMessage(const char *file, int line); + LogMessage(const char* file, int line); // Constructs a new message with the specified severity. // // file: source file that produced the log. // line: source code line that produced the log. // severity: severity level of the log. - LogMessage(const char *file, int line, absl::LogSeverity severity); + LogMessage(const char* file, int line, absl::LogSeverity severity); // Constructs a log message with additional text that is provided by CHECK // macros. Severity is implicitly FATAL. @@ -45,25 +45,25 @@ class LogMessage { // file: source file that produced the log. // line: source code line that produced the log. // result: result message of the failed check. - LogMessage(const char *file, int line, const std::string &result); + LogMessage(const char* file, int line, const std::string& result); // The destructor flushes the message. ~LogMessage(); - LogMessage(const LogMessage &) = delete; - void operator=(const LogMessage &) = delete; + LogMessage(const LogMessage&) = delete; + void operator=(const LogMessage&) = delete; // Gets a reference to the underlying string stream. - std::ostream &stream() { return stream_; } + std::ostream& stream() { return stream_; } protected: void Flush(); private: - void Init(const char *file, int line, absl::LogSeverity severity); + void Init(const char* file, int line, absl::LogSeverity severity); // Sends the message to print. - void SendToLog(const std::string &message_text); + void SendToLog(const std::string& message_text); // stream_ reads all the input messages into a stringstream, then it's // converted into a string in the destructor for printing. @@ -76,7 +76,7 @@ class LogMessage { // operator& is used because it has precedence lower than << but higher than :? class LogMessageVoidify { public: - void operator&(const std::ostream &) {} + void operator&(const std::ostream&) {} }; // Default LogSeverity FATAL version of LogMessage. @@ -87,7 +87,7 @@ class LogMessageFatal : public LogMessage { // // file: source file that produced the log. // line: source code line that produced the log. - LogMessageFatal(const char *file, int line) + LogMessageFatal(const char* file, int line) : LogMessage(file, line, absl::LogSeverity::kFatal) {} // Constructs a message with FATAL severity for use by CHECK macros. @@ -95,7 +95,7 @@ class LogMessageFatal : public LogMessage { // file: source file that produced the log. // line: source code line that produced the log. // result: result message when check fails. - LogMessageFatal(const char *file, int line, const std::string &result) + LogMessageFatal(const char* file, int line, const std::string& result) : LogMessage(file, line, result) {} // Suppresses warnings in some cases, example: