Merge "Remove Leftover Constants Dependancy y2017 constants"
diff --git a/aos/network/BUILD b/aos/network/BUILD
index 6fe0585..d5c27b3 100644
--- a/aos/network/BUILD
+++ b/aos/network/BUILD
@@ -9,7 +9,7 @@
"team_number.h",
],
deps = [
- "//aos:once",
+ "@com_google_absl//absl/base",
"//aos/logging",
"//aos/util:string_to_num",
"//aos:configuration",
diff --git a/aos/network/team_number.cc b/aos/network/team_number.cc
index c4fa5c2..852ce93 100644
--- a/aos/network/team_number.cc
+++ b/aos/network/team_number.cc
@@ -10,7 +10,7 @@
#include "aos/logging/logging.h"
#include "aos/util/string_to_num.h"
#include "aos/configuration.h"
-#include "aos/once.h"
+#include "absl/base/call_once.h"
namespace aos {
namespace network {
@@ -51,33 +51,35 @@
return buf;
}
-uint16_t *DoGetTeamNumber() {
- if (override_team != 0) return &override_team;
-
- static uint16_t r;
+void DoGetTeamNumber(uint16_t *result) {
+ if (override_team != 0) {
+ *result = override_team;
+ return;
+ }
const char *override_number = getenv("AOS_TEAM_NUMBER");
if (override_number != nullptr) {
- if (!::aos::util::StringToNumber(override_number, &r)) {
+ if (!::aos::util::StringToNumber(override_number, result)) {
AOS_LOG(FATAL, "error parsing AOS_TEAM_NUMBER '%s'\n", override_number);
}
AOS_LOG(WARNING,
- "team number overridden by AOS_TEAM_NUMBER to %" PRIu16 "\n", r);
+ "team number overridden by AOS_TEAM_NUMBER to %" PRIu16 "\n", *result);
} else {
- int error = internal::ParseTeamNumber(GetHostname(), &r);
+ int error = internal::ParseTeamNumber(GetHostname(), result);
if (error) {
AOS_LOG(FATAL, "Invalid hostname %s\n", GetHostname().c_str());
}
- AOS_LOG(INFO, "team number is %" PRIu16 "\n", r);
+ AOS_LOG(INFO, "team number is %" PRIu16 "\n", *result);
}
- return &r;
}
} // namespace
uint16_t GetTeamNumber() {
- static Once<uint16_t> once(DoGetTeamNumber);
- return *once.Get();
+ static absl::once_flag once;
+ static uint16_t result;
+ absl::call_once(once, DoGetTeamNumber, &result);
+ return result;
}
void OverrideTeamNumber(uint16_t team) { override_team = team; }
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.