Remove mock time
We have better ways to mock time now with the event loop. This removes
an atomic out of reading time, which should help speed up sending.
Change-Id: I966105c5f8fea096774402c7bc2634c65176958a
diff --git a/aos/time/time.cc b/aos/time/time.cc
index 6c2d254..549dae7 100644
--- a/aos/time/time.cc
+++ b/aos/time/time.cc
@@ -55,52 +55,6 @@
namespace aos {
namespace time {
-#ifdef __linux__
-
-// State required to enable and use mock time.
-namespace {
-// True if mock time is enabled.
-// This does not need to be checked with the mutex held because setting time to
-// be enabled or disabled is atomic, and all future operations are atomic
-// anyways. If there is a race condition setting or clearing whether time is
-// enabled or not, it will still be a race condition if current_mock_time is
-// also set atomically with enabled.
-::std::atomic<bool> mock_time_enabled{false};
-// Mutex to make time reads and writes thread safe.
-Mutex time_mutex;
-// Current time when time is mocked.
-monotonic_clock::time_point current_mock_time = monotonic_clock::epoch();
-
-} // namespace
-
-void EnableMockTime(monotonic_clock::time_point now) {
- MutexLocker time_mutex_locker(&time_mutex);
- mock_time_enabled = true;
- current_mock_time = now;
-}
-
-void UpdateMockTime() { SetMockTime(monotonic_clock::now()); }
-
-void DisableMockTime() {
- MutexLocker time_mutex_locker(&time_mutex);
- mock_time_enabled = false;
-}
-
-void SetMockTime(monotonic_clock::time_point now) {
- MutexLocker time_mutex_locker(&time_mutex);
- CHECK(mock_time_enabled)
- << ": Tried to set mock time and mock time is not enabled";
- current_mock_time = now;
-}
-
-void IncrementMockTime(monotonic_clock::duration amount) {
- static ::aos::Mutex mutex;
- ::aos::MutexLocker sync(&mutex);
- SetMockTime(monotonic_clock::now() + amount);
-}
-
-#endif // __linux__
-
struct timespec to_timespec(
const ::aos::monotonic_clock::duration duration) {
struct timespec time_timespec;
@@ -126,12 +80,6 @@
monotonic_clock::time_point monotonic_clock::now() noexcept {
#ifdef __linux__
-
- if (time::mock_time_enabled.load(::std::memory_order_relaxed)) {
- MutexLocker time_mutex_locker(&time::time_mutex);
- return time::current_mock_time;
- }
-
struct timespec current_time;
PCHECK(clock_gettime(CLOCK_MONOTONIC, ¤t_time) == 0)
<< ": clock_gettime(" << static_cast<uintmax_t>(CLOCK_MONOTONIC) << ", "
diff --git a/aos/time/time.h b/aos/time/time.h
index 881f0f1..37455f4 100644
--- a/aos/time/time.h
+++ b/aos/time/time.h
@@ -69,19 +69,6 @@
#ifdef __linux__
-// Enables returning the mock time value for Now instead of checking the system
-// clock.
-void EnableMockTime(monotonic_clock::time_point now);
-// Calls SetMockTime with the current actual time.
-void UpdateMockTime();
-// Sets now when time is being mocked.
-void SetMockTime(monotonic_clock::time_point now);
-// Convenience function to just increment the mock time by a certain amount in
-// a thread safe way.
-void IncrementMockTime(monotonic_clock::duration amount);
-// Disables mocking time.
-void DisableMockTime();
-
// Construct a time representing the period of hertz.
constexpr ::std::chrono::nanoseconds FromRate(int hertz) {
return ::std::chrono::duration_cast<::std::chrono::nanoseconds>(
@@ -99,17 +86,6 @@
return TypedDurationInSeconds<double>(dt);
}
-// RAII class that freezes monotonic_clock::now() (to avoid making large numbers
-// of syscalls to find the real time).
-class TimeFreezer {
- public:
- TimeFreezer() { EnableMockTime(monotonic_clock::now()); }
- ~TimeFreezer() { DisableMockTime(); }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TimeFreezer);
-};
-
#endif // __linux__
// Converts a monotonic_clock::duration into a timespec object.