Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afa0527f authored by Josh Gao's avatar Josh Gao Committed by android-build-merger
Browse files

Merge "Revert "base: make boot_clock work on host linux, hide it on non-linux."" am: dd366705

am: 67cfaf4b

Change-Id: I379961d0b8b9e305f63e2937ca4aba8a44978594
parents c0923311 67cfaf4b
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -42,7 +42,6 @@ cc_library {
    clang: true,
    clang: true,
    host_supported: true,
    host_supported: true,
    srcs: [
    srcs: [
        "chrono_utils.cpp",
        "file.cpp",
        "file.cpp",
        "logging.cpp",
        "logging.cpp",
        "parsenetaddress.cpp",
        "parsenetaddress.cpp",
@@ -65,6 +64,7 @@ cc_library {
            srcs: [
            srcs: [
                "errors_unix.cpp",
                "errors_unix.cpp",
                "properties.cpp",
                "properties.cpp",
                "chrono_utils.cpp",
            ],
            ],
            cppflags: ["-Wexit-time-destructors"],
            cppflags: ["-Wexit-time-destructors"],
            sanitize: {
            sanitize: {
@@ -74,12 +74,14 @@ cc_library {
        },
        },
        darwin: {
        darwin: {
            srcs: [
            srcs: [
                "chrono_utils.cpp",
                "errors_unix.cpp",
                "errors_unix.cpp",
            ],
            ],
            cppflags: ["-Wexit-time-destructors"],
            cppflags: ["-Wexit-time-destructors"],
        },
        },
        linux_bionic: {
        linux_bionic: {
            srcs: [
            srcs: [
                "chrono_utils.cpp",
                "errors_unix.cpp",
                "errors_unix.cpp",
            ],
            ],
            cppflags: ["-Wexit-time-destructors"],
            cppflags: ["-Wexit-time-destructors"],
@@ -87,6 +89,7 @@ cc_library {
        },
        },
        linux: {
        linux: {
            srcs: [
            srcs: [
                "chrono_utils.cpp",
                "errors_unix.cpp",
                "errors_unix.cpp",
            ],
            ],
            cppflags: ["-Wexit-time-destructors"],
            cppflags: ["-Wexit-time-destructors"],
+5 −2
Original line number Original line Diff line number Diff line
@@ -21,14 +21,17 @@
namespace android {
namespace android {
namespace base {
namespace base {


#if defined(__linux__)
boot_clock::time_point boot_clock::now() {
boot_clock::time_point boot_clock::now() {
#ifdef __ANDROID__
  timespec ts;
  timespec ts;
  clock_gettime(CLOCK_BOOTTIME, &ts);
  clock_gettime(CLOCK_BOOTTIME, &ts);
  return boot_clock::time_point(std::chrono::seconds(ts.tv_sec) +
  return boot_clock::time_point(std::chrono::seconds(ts.tv_sec) +
                                std::chrono::nanoseconds(ts.tv_nsec));
                                std::chrono::nanoseconds(ts.tv_nsec));
#else
  // Darwin does not support clock_gettime.
  return boot_clock::time_point();
#endif  // __ANDROID__
}
}
#endif


}  // namespace base
}  // namespace base
}  // namespace android
}  // namespace android
+2 −7
Original line number Original line Diff line number Diff line
@@ -16,7 +16,6 @@


#include "android-base/chrono_utils.h"
#include "android-base/chrono_utils.h"


#include <err.h>
#include <time.h>
#include <time.h>


#include <chrono>
#include <chrono>
@@ -26,12 +25,9 @@
namespace android {
namespace android {
namespace base {
namespace base {


#if defined(__linux__)
std::chrono::seconds GetBootTimeSeconds() {
std::chrono::seconds GetBootTimeSeconds() {
  struct timespec now;
  struct timespec now;
  if (clock_gettime(CLOCK_BOOTTIME, &now) != 0) {
  clock_gettime(CLOCK_BOOTTIME, &now);
    err(1, "clock_gettime failed");
  }


  auto now_tp = boot_clock::time_point(std::chrono::seconds(now.tv_sec) +
  auto now_tp = boot_clock::time_point(std::chrono::seconds(now.tv_sec) +
                                       std::chrono::nanoseconds(now.tv_nsec));
                                       std::chrono::nanoseconds(now.tv_nsec));
@@ -45,7 +41,6 @@ TEST(ChronoUtilsTest, BootClockNowSeconds) {
      std::chrono::duration_cast<std::chrono::seconds>(boot_clock::now().time_since_epoch());
      std::chrono::duration_cast<std::chrono::seconds>(boot_clock::now().time_since_epoch());
  EXPECT_EQ(now, boot_seconds);
  EXPECT_EQ(now, boot_seconds);
}
}
#endif  // defined(__linux__)


}  // namespace base
}  // namespace base
}  // namespace android
}  // namespace android
 No newline at end of file
+0 −2
Original line number Original line Diff line number Diff line
@@ -22,7 +22,6 @@
namespace android {
namespace android {
namespace base {
namespace base {


#if defined(__linux__)
// A std::chrono clock based on CLOCK_BOOTTIME.
// A std::chrono clock based on CLOCK_BOOTTIME.
class boot_clock {
class boot_clock {
 public:
 public:
@@ -31,7 +30,6 @@ class boot_clock {


  static time_point now();
  static time_point now();
};
};
#endif  // defined(__linux__)


}  // namespace base
}  // namespace base
}  // namespace android
}  // namespace android