Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions agent_based_epidemic_sim/core/simulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class WorkQueueBroker : public Broker<Msg> {
WorkQueueBroker* const broker;
};
virtual void Delete(std::vector<std::vector<Msg>>* 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
Expand All @@ -316,15 +316,15 @@ class WorkQueueBroker : public Broker<Msg> {
send_(chunker.Chunks().size()),
consume_(chunker.Chunks().size()) {}
void Send(const absl::Span<const Msg> 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);
}
sent_msgs_ = true;
}
virtual std::unique_ptr<std::vector<std::vector<Msg>>, Deleter> Consume() {
absl::MutexLock l(&mu_);
absl::MutexLock l(mu_);
DCHECK(std::all_of(consume_.begin(), consume_.end(),
[](const std::vector<Msg>& v) { return v.empty(); }));
sent_msgs_ = false;
Expand Down Expand Up @@ -369,7 +369,7 @@ void ParallelAgentPhase(const Timestep& timestep, Executor& executor,
absl::Span<ContactReport> my_reports;
absl::Span<const std::unique_ptr<Agent>> 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];
Expand Down Expand Up @@ -413,7 +413,7 @@ void ParallelLocationPhase(const Timestep& timestep, Executor& executor,
absl::Span<Visit> my_visits;
absl::Span<const std::unique_ptr<Location>> 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];
Expand Down
8 changes: 4 additions & 4 deletions agent_based_epidemic_sim/core/simulation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ std::unique_ptr<Agent> 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()) {
Expand All @@ -98,7 +98,7 @@ std::unique_ptr<Agent> MakeAgent(int64 uuid, OutcomeMap* outcome_counts,
absl::Span<const ContactReport> symptom_reports,
Broker<ContactReport>* 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,
Expand Down Expand Up @@ -128,7 +128,7 @@ std::unique_ptr<Location> 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}});
Expand Down Expand Up @@ -228,7 +228,7 @@ std::unique_ptr<Simulation> 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());
Expand Down
22 changes: 11 additions & 11 deletions agent_based_epidemic_sim/port/deps/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.
Expand All @@ -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') {
Expand Down
22 changes: 11 additions & 11 deletions agent_based_epidemic_sim/port/deps/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ 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.
//
// 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.
Expand All @@ -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.
Expand All @@ -87,15 +87,15 @@ 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.
//
// 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:
Expand Down