about summary refs log tree commit diff
path: root/absl/time
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-08-02T17·08-0700
committerJon Cohen <cohenjon@google.com>2018-08-02T17·59-0400
commit8f96be6ca60d967bd4b37f93d0a03bcff4145200 (patch)
tree11d279916ab48665493b316570183bd0257e1a29 /absl/time
parent92e07e5590752d6b8e67f7f2f86c6286561e8cea (diff)
Export of internal Abseil changes.
--
586c41e29e80d9613434f18347d4a70a92a90989 by Jon Cohen <cohenjon@google.com>:

Whitespace cleanup

PiperOrigin-RevId: 207119388

--
e28fc6932d68f7097918f3092079f07112e684c1 by Abseil Team <absl-team@google.com>:

Fix comment typo in mutex.h

PiperOrigin-RevId: 207024211

--
b7714a5f189b2863f9cfc285ba428ca2059b83f4 by Abseil Team <absl-team@google.com>:

Raise the floor for gcc from gcc 4.7 to gcc 4.8.

PiperOrigin-RevId: 207021220

--
262ae79150278ea1b4e512dfe8ff05c32768f429 by Matt Armstrong <marmstrong@google.com>:

Raise the floor for gcc from gcc 4.7 to gcc 4.8.

PiperOrigin-RevId: 206997741

--
5aba0b15eaf6c5beff0e91670a7cdf5ad1151886 by Derek Mauro <dmauro@google.com>:

Use std::chrono to get the current time on both Apple and Windows
platforms, eliminating the unnecessarily complicated logic on Apple
platforms.

PiperOrigin-RevId: 206979219

--
807a91adf876f7532050d442f00268754c0f260b by Derek Mauro <dmauro@google.com>:

Fix multiple definition problem when Abseil is combined with
gperftools on PowerPC.

https://github.com/abseil/abseil-cpp/pull/152

PiperOrigin-RevId: 206963083
GitOrigin-RevId: 586c41e29e80d9613434f18347d4a70a92a90989
Change-Id: I0ee65a733c423890b97dd3500f2d17449792387c
Diffstat (limited to 'absl/time')
-rw-r--r--absl/time/BUILD.bazel3
-rw-r--r--absl/time/clock.cc6
-rw-r--r--absl/time/internal/get_current_time_chrono.inc29
-rw-r--r--absl/time/internal/get_current_time_ios.inc80
-rw-r--r--absl/time/internal/get_current_time_windows.inc17
5 files changed, 32 insertions, 103 deletions
diff --git a/absl/time/BUILD.bazel b/absl/time/BUILD.bazel
index e793da87d10e..c7c16d4376c7 100644
--- a/absl/time/BUILD.bazel
+++ b/absl/time/BUILD.bazel
@@ -30,9 +30,8 @@ cc_library(
         "clock.cc",
         "duration.cc",
         "format.cc",
-        "internal/get_current_time_ios.inc",
+        "internal/get_current_time_chrono.inc",
         "internal/get_current_time_posix.inc",
-        "internal/get_current_time_windows.inc",
         "time.cc",
     ],
     hdrs = [
diff --git a/absl/time/clock.cc b/absl/time/clock.cc
index 772f8525e84f..74ee1401b98c 100644
--- a/absl/time/clock.cc
+++ b/absl/time/clock.cc
@@ -57,10 +57,8 @@ Time Now() {
 #endif
 #endif
 
-#if defined(__APPLE__)
-#include "absl/time/internal/get_current_time_ios.inc"
-#elif defined(_WIN32)
-#include "absl/time/internal/get_current_time_windows.inc"
+#if defined(__APPLE__) || defined(_WIN32)
+#include "absl/time/internal/get_current_time_chrono.inc"
 #else
 #include "absl/time/internal/get_current_time_posix.inc"
 #endif
diff --git a/absl/time/internal/get_current_time_chrono.inc b/absl/time/internal/get_current_time_chrono.inc
new file mode 100644
index 000000000000..cf884a10ed9d
--- /dev/null
+++ b/absl/time/internal/get_current_time_chrono.inc
@@ -0,0 +1,29 @@
+// Copyright 2018 The Abseil Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <chrono>
+#include <cstdint>
+
+namespace absl {
+namespace time_internal {
+
+static int64_t GetCurrentTimeNanosFromSystem() {
+  return std::chrono::duration_cast<std::chrono::nanoseconds>(
+             std::chrono::system_clock::now() -
+             std::chrono::system_clock::from_time_t(0))
+      .count();
+}
+
+}  // namespace time_internal
+}  // namespace absl
diff --git a/absl/time/internal/get_current_time_ios.inc b/absl/time/internal/get_current_time_ios.inc
deleted file mode 100644
index f3db32bf7854..000000000000
--- a/absl/time/internal/get_current_time_ios.inc
+++ /dev/null
@@ -1,80 +0,0 @@
-#include "absl/time/clock.h"
-
-#include <sys/time.h>
-#include <ctime>
-#include <cstdint>
-
-#include "absl/base/internal/raw_logging.h"
-
-// These are not defined in the Xcode 7.3.1 SDK Headers.
-// Once we are no longer supporting Xcode 7.3.1 we can
-// remove these.
-#ifndef __WATCHOS_3_0
-#define __WATCHOS_3_0 30000
-#endif
-
-#ifndef __TVOS_10_0
-#define __TVOS_10_0 100000
-#endif
-
-#ifndef __IPHONE_10_0
-#define __IPHONE_10_0 100000
-#endif
-
-#ifndef __MAC_10_12
-#define __MAC_10_12 101200
-#endif
-
-namespace absl {
-namespace time_internal {
-
-static int64_t GetCurrentTimeNanosFromSystem() {
-#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_12) ||    \
-    (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0) || \
-    (__WATCH_OS_VERSION_MAX_ALLOWED >= __WATCHOS_3_0) ||  \
-    (__TV_OS_VERSION_MAX_ALLOWED >= __TVOS_10_0)
-  // clock_gettime_nsec_np is not defined on SDKs before Xcode 8.0.
-  // This preprocessor logic is based upon __CLOCK_AVAILABILITY in
-  // usr/include/time.h. Once we are no longer supporting Xcode 7.3.1 we can
-  // remove this #if.
-  // We must continue to check if it is defined until we are sure that ALL the
-  // platforms we are shipping on support it.
-  // clock_gettime_nsec_np is preferred because it may give higher accuracy than
-  // gettimeofday in future Apple operating systems.
-  // Currently (macOS 10.12/iOS 10.2) clock_gettime_nsec_np accuracy is
-  // microsecond accuracy (i.e. equivalent to gettimeofday).
-  if (&clock_gettime_nsec_np != nullptr) {
-    return clock_gettime_nsec_np(CLOCK_REALTIME);
-  }
-#endif
-#if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) &&            \
-     (__MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_12)) ||    \
-    (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) &&           \
-     (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)) || \
-    (defined(__WATCH_OS_VERSION_MIN_REQUIRED) &&            \
-     (__WATCH_OS_VERSION_MIN_REQUIRED < __WATCHOS_3_0)) ||  \
-    (defined(__TV_OS_VERSION_MIN_REQUIRED) &&               \
-     (__TV_OS_VERSION_MIN_REQUIRED < __TVOS_10_0))
-  // We need this block in 2 different cases:
-  // a) where we are compiling with Xcode 7 in which case the block above
-  //    will not be compiled in, and this is the only block executed.
-  // b) where we are compiling with Xcode 8+ but supporting operating systems
-  //    that do not define clock_gettime_nsec_np, so this is in effect
-  //    an else block to the block above.
-  // This block will not be compiled if the min supported version is
-  // guaranteed to supply clock_gettime_nsec_np.
-  //
-  // Once we know that clock_gettime_nsec_np is in the SDK *AND* exists on
-  // all the platforms we support, we can remove both this block and alter the
-  // block above to just call clock_gettime_nsec_np directly.
-  const int64_t kNanosPerSecond = 1000 * 1000 * 1000;
-  const int64_t kNanosPerMicrosecond = 1000;
-  struct timeval tp;
-  ABSL_RAW_CHECK(gettimeofday(&tp, nullptr) == 0, "Failed gettimeofday");
-  return (int64_t{tp.tv_sec} * kNanosPerSecond +
-          int64_t{tp.tv_usec} * kNanosPerMicrosecond);
-#endif
-}
-
-}  // namespace time_internal
-}  // namespace absl
diff --git a/absl/time/internal/get_current_time_windows.inc b/absl/time/internal/get_current_time_windows.inc
deleted file mode 100644
index b22a9c9e9e2e..000000000000
--- a/absl/time/internal/get_current_time_windows.inc
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "absl/time/clock.h"
-
-#include <chrono>
-#include <cstdint>
-
-namespace absl {
-namespace time_internal {
-
-static int64_t GetCurrentTimeNanosFromSystem() {
-  return std::chrono::duration_cast<std::chrono::nanoseconds>(
-             std::chrono::system_clock::now() -
-             std::chrono::system_clock::from_time_t(0))
-      .count();
-}
-
-}  // namespace time_internal
-}  // namespace absl