don't make so many clock_gettime syscalls
For all of the code that runs periodically for short periods of time,
making more than just 1 syscall to figure out what time it currently is
is pointless and a waste of CPU.
diff --git a/aos/common/controls/control_loop-tmpl.h b/aos/common/controls/control_loop-tmpl.h
index dde33c0..baf352b 100644
--- a/aos/common/controls/control_loop-tmpl.h
+++ b/aos/common/controls/control_loop-tmpl.h
@@ -146,8 +146,12 @@
template <class T, bool has_position, bool fail_no_position, bool fail_no_goal>
void ControlLoop<T, has_position, fail_no_position, fail_no_goal>::Run() {
+ ::aos::time::Time::EnableMockTime();
while (true) {
- time::SleepUntil(NextLoopTime());
+ ::aos::time::Time::UpdateMockTime();
+ const ::aos::time::Time next_loop = NextLoopTime();
+ time::SleepUntil(next_loop);
+ ::aos::time::Time::SetMockTime(next_loop);
Iterate();
}
}
diff --git a/aos/common/controls/control_loop.h b/aos/common/controls/control_loop.h
index 0889b48..becb080 100644
--- a/aos/common/controls/control_loop.h
+++ b/aos/common/controls/control_loop.h
@@ -1,7 +1,7 @@
#ifndef AOS_CONTROL_LOOP_CONTROL_LOOP_H_
#define AOS_CONTROL_LOOP_CONTROL_LOOP_H_
-#include <cstring>
+#include <string.h>
#include "aos/common/type_traits.h"
#include "aos/common/queue.h"