Prefix LOG and CHECK with AOS_
This prepares us for introducing glog more widely and transitioning
things over where they make sense.
Change-Id: Ic6c208882407bc2153fe875ffc736d66f5c8ade5
diff --git a/aos/util/BUILD b/aos/util/BUILD
index be6055d..f18fd82 100644
--- a/aos/util/BUILD
+++ b/aos/util/BUILD
@@ -113,6 +113,7 @@
deps = [
"//aos/logging",
"//aos/time",
+ "@com_github_google_glog//:glog",
],
)
diff --git a/aos/util/file.cc b/aos/util/file.cc
index 9c81b3e..5418aab 100644
--- a/aos/util/file.cc
+++ b/aos/util/file.cc
@@ -14,15 +14,15 @@
::std::string r;
ScopedFD fd(open(::std::string(filename).c_str(), O_RDONLY));
if (fd.get() == -1) {
- PLOG(FATAL, "opening %*s", static_cast<int>(filename.size()),
- filename.data());
+ AOS_PLOG(FATAL, "opening %*s", static_cast<int>(filename.size()),
+ filename.data());
}
while (true) {
char buffer[1024];
const ssize_t result = read(fd.get(), buffer, sizeof(buffer));
if (result < 0) {
- PLOG(FATAL, "reading from %*s", static_cast<int>(filename.size()),
- filename.data());
+ AOS_PLOG(FATAL, "reading from %*s", static_cast<int>(filename.size()),
+ filename.data());
} else if (result == 0) {
break;
}
diff --git a/aos/util/linked_list.h b/aos/util/linked_list.h
index 5a5824e..14f1788 100644
--- a/aos/util/linked_list.h
+++ b/aos/util/linked_list.h
@@ -64,7 +64,7 @@
}
pointer = &(*pointer)->next;
}
- LOG(FATAL, "%p is not in the list\n", t);
+ AOS_LOG(FATAL, "%p is not in the list\n", t);
}
// Calls function for each element of the list.
diff --git a/aos/util/log_interval.h b/aos/util/log_interval.h
index acd32e8..54ebd6d 100644
--- a/aos/util/log_interval.h
+++ b/aos/util/log_interval.h
@@ -66,7 +66,7 @@
const ::std::string &message)
: interval_(interval), level_(level), message_(message) {}
-#define LOG_INTERVAL(simple_log) \
+#define AOS_LOG_INTERVAL(simple_log) \
simple_log.WantToLog(LOG_SOURCENAME ": " STRINGIFY(__LINE__))
void WantToLog(const char *context) {
context_ = context;
@@ -75,7 +75,7 @@
void Print() {
if (interval_.ShouldLog()) {
- CHECK_NOTNULL(context_);
+ AOS_CHECK_NOTNULL(context_);
log_do(level_, "%s: %.*s %d times over %f sec\n", context_,
static_cast<int>(message_.size()), message_.data(),
interval_.Count(),
diff --git a/aos/util/phased_loop.cc b/aos/util/phased_loop.cc
index a349718..7369a93 100644
--- a/aos/util/phased_loop.cc
+++ b/aos/util/phased_loop.cc
@@ -1,8 +1,41 @@
#include "aos/util/phased_loop.h"
+#include "glog/logging.h"
+
namespace aos {
namespace time {
+PhasedLoop::PhasedLoop(const monotonic_clock::duration interval,
+ const monotonic_clock::time_point monotonic_now,
+ const monotonic_clock::duration offset)
+ : interval_(interval), offset_(offset), last_time_(offset) {
+ CHECK(offset >= monotonic_clock::duration(0));
+ CHECK(interval > monotonic_clock::duration(0));
+ CHECK(offset < interval);
+ Reset(monotonic_now);
+}
+
+void PhasedLoop::set_interval_and_offset(
+ const monotonic_clock::duration interval,
+ const monotonic_clock::duration offset) {
+ interval_ = interval;
+ offset_ = offset;
+ CHECK(offset_ >= monotonic_clock::duration(0));
+ CHECK(interval_ > monotonic_clock::duration(0));
+ CHECK(offset_ < interval_);
+}
+
+monotonic_clock::duration PhasedLoop::OffsetFromIntervalAndTime(
+ const monotonic_clock::duration interval,
+ const monotonic_clock::time_point monotonic_trigger) {
+ CHECK(interval > monotonic_clock::duration(0));
+ return monotonic_trigger.time_since_epoch() -
+ (monotonic_trigger.time_since_epoch() / interval) * interval +
+ ((monotonic_trigger.time_since_epoch() >= monotonic_clock::zero())
+ ? monotonic_clock::zero()
+ : interval);
+}
+
int PhasedLoop::Iterate(const monotonic_clock::time_point now) {
const monotonic_clock::time_point next_time =
monotonic_clock::time_point(
@@ -17,8 +50,8 @@
const int result = difference / interval_;
CHECK_EQ(
0, (next_time - offset_).time_since_epoch().count() % interval_.count());
- CHECK_GE(next_time, now);
- CHECK_LE(next_time - now, interval_);
+ CHECK(next_time >= now);
+ CHECK(next_time - now <= interval_);
last_time_ = next_time;
return result;
}
diff --git a/aos/util/phased_loop.h b/aos/util/phased_loop.h
index 7aa51d2..3e1752b 100644
--- a/aos/util/phased_loop.h
+++ b/aos/util/phased_loop.h
@@ -3,8 +3,6 @@
#include "aos/time/time.h"
-#include "aos/logging/logging.h"
-
namespace aos {
namespace time {
@@ -20,35 +18,16 @@
PhasedLoop(
const monotonic_clock::duration interval,
const monotonic_clock::time_point monotonic_now,
- const monotonic_clock::duration offset = monotonic_clock::duration(0))
- : interval_(interval), offset_(offset), last_time_(offset) {
- CHECK_GE(offset, monotonic_clock::duration(0));
- CHECK_GT(interval, monotonic_clock::duration(0));
- CHECK_LT(offset, interval);
- Reset(monotonic_now);
- }
+ const monotonic_clock::duration offset = monotonic_clock::duration(0));
// Updates the offset and interval.
void set_interval_and_offset(const monotonic_clock::duration interval,
- const monotonic_clock::duration offset) {
- interval_ = interval;
- offset_ = offset;
- CHECK_GE(offset_, monotonic_clock::duration(0));
- CHECK_GT(interval_, monotonic_clock::duration(0));
- CHECK_LT(offset_, interval_);
- }
+ const monotonic_clock::duration offset);
// Computes the offset given an interval and a time that we should trigger.
static monotonic_clock::duration OffsetFromIntervalAndTime(
const monotonic_clock::duration interval,
- const monotonic_clock::time_point monotonic_trigger) {
- CHECK_GT(interval, monotonic_clock::duration(0));
- return monotonic_trigger.time_since_epoch() -
- (monotonic_trigger.time_since_epoch() / interval) * interval +
- ((monotonic_trigger.time_since_epoch() >= monotonic_clock::zero())
- ? monotonic_clock::zero()
- : interval);
- }
+ const monotonic_clock::time_point monotonic_trigger);
// Resets the count of skipped iterations.
// Iterate(monotonic_now) will return 1 and set sleep_time() to something
diff --git a/aos/util/phased_loop_test.cc b/aos/util/phased_loop_test.cc
index 4f07bcc..0a0d5db 100644
--- a/aos/util/phased_loop_test.cc
+++ b/aos/util/phased_loop_test.cc
@@ -183,16 +183,16 @@
TEST_F(PhasedLoopDeathTest, InvalidValues) {
EXPECT_DEATH(
PhasedLoop(milliseconds(1), monotonic_clock::epoch(), milliseconds(2)),
- ".*offset<interval.*");
+ ".*offset < interval.*");
EXPECT_DEATH(
PhasedLoop(milliseconds(1), monotonic_clock::epoch(), milliseconds(1)),
- ".*offset<interval.*");
+ ".*offset < interval.*");
EXPECT_DEATH(
PhasedLoop(milliseconds(1), monotonic_clock::epoch(), milliseconds(-1)),
- ".*offset>=monotonic_clock::duration\\(0\\).*");
+ ".*offset >= monotonic_clock::duration\\(0\\).*");
EXPECT_DEATH(
PhasedLoop(milliseconds(0), monotonic_clock::epoch(), milliseconds(0)),
- ".*interval>monotonic_clock::duration\\(0\\).*");
+ ".*interval > monotonic_clock::duration\\(0\\).*");
}
} // namespace testing
diff --git a/aos/util/run_command.cc b/aos/util/run_command.cc
index 2b08cb2..40782da 100644
--- a/aos/util/run_command.cc
+++ b/aos/util/run_command.cc
@@ -21,14 +21,14 @@
sigemptyset(&to_block);
sigaddset(&to_block, SIGCHLD);
if (sigprocmask(SIG_BLOCK, &to_block, &original_blocked_) == -1) {
- PLOG(FATAL, "sigprocmask(SIG_BLOCK, %p, %p) failed",
- &to_block, &original_blocked_);
+ AOS_PLOG(FATAL, "sigprocmask(SIG_BLOCK, %p, %p) failed", &to_block,
+ &original_blocked_);
}
}
~BlockSIGCHLD() {
if (sigprocmask(SIG_SETMASK, &original_blocked_, nullptr) == -1) {
- PLOG(FATAL, "sigprocmask(SIG_SETMASK, %p, nullptr) failed",
- &original_blocked_);
+ AOS_PLOG(FATAL, "sigprocmask(SIG_SETMASK, %p, nullptr) failed",
+ &original_blocked_);
}
}
diff --git a/aos/util/thread.cc b/aos/util/thread.cc
index 6b3ef76..ae18fe9 100644
--- a/aos/util/thread.cc
+++ b/aos/util/thread.cc
@@ -11,24 +11,24 @@
Thread::Thread() : started_(false), joined_(false), should_terminate_(false) {}
Thread::~Thread() {
- CHECK(!(started_ && !joined_));
+ AOS_CHECK(!(started_ && !joined_));
}
void Thread::Start() {
- CHECK(!started_);
+ AOS_CHECK(!started_);
started_ = true;
- CHECK(pthread_create(&thread_, NULL, &Thread::StaticRun, this) == 0);
+ AOS_CHECK(pthread_create(&thread_, NULL, &Thread::StaticRun, this) == 0);
}
void Thread::Join() {
- CHECK(!joined_ && started_);
+ AOS_CHECK(!joined_ && started_);
joined_ = true;
should_terminate_.store(true);
- CHECK(pthread_join(thread_, NULL) == 0);
+ AOS_CHECK(pthread_join(thread_, NULL) == 0);
}
bool Thread::TryJoin() {
- CHECK(!joined_ && started_);
+ AOS_CHECK(!joined_ && started_);
#ifdef AOS_SANITIZER_thread
// ThreadSanitizer misses the tryjoin and then complains about leaking the
// thread. Instead, we'll just check if the thread is still around and then
@@ -39,7 +39,7 @@
if (kill_ret == 0) return false;
// If it died, we'll get ESRCH. Otherwise, something went wrong.
if (kill_ret != ESRCH) {
- PELOG(FATAL, kill_ret, "pthread_kill(thread_, 0) failed");
+ AOS_PELOG(FATAL, kill_ret, "pthread_kill(thread_, 0) failed");
}
Join();
return true;
@@ -51,20 +51,20 @@
} else if (ret == EBUSY) {
return false;
} else {
- PELOG(FATAL, ret, "pthread_tryjoin_np(thread_, nullptr) failed");
+ AOS_PELOG(FATAL, ret, "pthread_tryjoin_np(thread_, nullptr) failed");
}
#endif
}
void Thread::RequestStop() {
- CHECK(!joined_ && started_);
+ AOS_CHECK(!joined_ && started_);
should_terminate_.store(true);
}
void Thread::WaitUntilDone() {
- CHECK(!joined_ && started_);
+ AOS_CHECK(!joined_ && started_);
joined_ = true;
- CHECK(pthread_join(thread_, NULL) == 0);
+ AOS_CHECK(pthread_join(thread_, NULL) == 0);
}
void *Thread::StaticRun(void *self) {
diff --git a/aos/util/trapezoid_profile.cc b/aos/util/trapezoid_profile.cc
index a1e8abb..e74110f 100644
--- a/aos/util/trapezoid_profile.cc
+++ b/aos/util/trapezoid_profile.cc
@@ -108,7 +108,7 @@
acceleration_time_ = (top_velocity - output_(1)) / acceleration_;
}
- CHECK_GT(top_velocity, -maximum_velocity_);
+ AOS_CHECK_GT(top_velocity, -maximum_velocity_);
if (output_(1) > maximum_velocity_) {
constant_time_ = 0;