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/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;
}