about summary refs log tree commit diff
path: root/absl/base
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2017-09-29T15·44-0700
committerDerek Mauro <dmauro@google.com>2017-09-29T15·50-0400
commit8d8dcb0ae550fbfdbd7392a3c9d2c5c596bdcde3 (patch)
treea6ac55aa5c82e4170d059d0bbdeb10752c76742f /absl/base
parentcdf20caa491f59c0a35a8d8fbec0d948e4bc7e4c (diff)
Changes imported from Abseil "staging" branch:
  - b76f5d50e1cb55050ef6004d6097dfdf0a806ff5 Fix ABSL_HAVE_THREAD_LOCAL for iOS < 8.0. by Matt Armstrong <marmstrong@google.com>
  - 1dc71788a3f4ef601e03cbea59e36901479cde35 Add missing #include <intrin.h> to use __nop() on MSVC. by Derek Mauro <dmauro@google.com>
  - f63ca6c7e87a7961912995b518b93af41b04bfa1 Fix typo (implict -> implicit) by Abseil Team <absl-team@google.com>
  - 8096006dc52368f166ccd22e25fcee334e142508 Fix a typo. by Abseil Team <absl-team@google.com>
  - c673a4a59790329fab33536caed6733dc03ec2a1 Add missing ":" in TODO. by Abseil Team <absl-team@google.com>
  - 8125d214356501af0f3a8b3bb577eed083f0493f Fix comment nit. by Abseil Team <absl-team@google.com>

GitOrigin-RevId: b76f5d50e1cb55050ef6004d6097dfdf0a806ff5
Change-Id: I0168eb0c92b20ece2fe5ee54573c7720d00fd0b3
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/BUILD.bazel1
-rw-r--r--absl/base/casts.h2
-rw-r--r--absl/base/config.h16
-rw-r--r--absl/base/config_test.cc20
-rw-r--r--absl/base/optimization.h1
5 files changed, 33 insertions, 7 deletions
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel
index 5f88635998c9..23439a090418 100644
--- a/absl/base/BUILD.bazel
+++ b/absl/base/BUILD.bazel
@@ -286,6 +286,7 @@ cc_test(
     copts = ABSL_TEST_COPTS,
     deps = [
         ":config",
+        "//absl/synchronization:thread_pool",
         "@com_google_googletest//:gtest_main",
     ],
 )
diff --git a/absl/base/casts.h b/absl/base/casts.h
index 2a0adc29504b..266c4a0a9356 100644
--- a/absl/base/casts.h
+++ b/absl/base/casts.h
@@ -50,7 +50,7 @@ namespace absl {
 //
 // An `implicit_cast()` may also be used to annotate numeric type conversions
 // that, although safe, may produce compiler warnings (such as `long` to `int`).
-// Additionally, an `implict_cast()` is also useful within return statements to
+// Additionally, an `implicit_cast()` is also useful within return statements to
 // indicate a specific implicit conversion is being undertaken.
 //
 // Example:
diff --git a/absl/base/config.h b/absl/base/config.h
index cf47f84c3356..c768e7223b93 100644
--- a/absl/base/config.h
+++ b/absl/base/config.h
@@ -56,6 +56,13 @@
 #include <cstddef>
 #endif  // __cplusplus
 
+#if defined(__APPLE__)
+// Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
+// __IPHONE_8_0.
+#include <Availability.h>
+#include <TargetConditionals.h>
+#endif
+
 #include "absl/base/policy_checks.h"
 
 // -----------------------------------------------------------------------------
@@ -151,12 +158,13 @@
 //
 // Checks whether C++11's `thread_local` storage duration specifier is
 // supported.
-//
-// Notes: Clang implements the `thread_local` keyword but Xcode did not support
-// the implementation until Xcode 8.
 #ifdef ABSL_HAVE_THREAD_LOCAL
 #error ABSL_HAVE_THREAD_LOCAL cannot be directly set
-#elif !defined(__apple_build_version__) || __apple_build_version__ >= 8000042
+#elif !defined(__apple_build_version__) ||   \
+    ((__apple_build_version__ >= 8000042) && \
+     !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0))
+// Notes: Xcode's clang did not support `thread_local` until version
+// 8, and even then not for iOS < 8.0.
 #define ABSL_HAVE_THREAD_LOCAL 1
 #endif
 
diff --git a/absl/base/config_test.cc b/absl/base/config_test.cc
index ab04b447406b..c839712a537e 100644
--- a/absl/base/config_test.cc
+++ b/absl/base/config_test.cc
@@ -17,12 +17,12 @@
 #include <cstdint>
 
 #include "gtest/gtest.h"
+#include "absl/synchronization/internal/thread_pool.h"
 
 namespace {
 
 TEST(ConfigTest, Endianness) {
-  union
-  {
+  union {
     uint32_t value;
     uint8_t data[sizeof(uint32_t)];
   } number;
@@ -41,4 +41,20 @@ TEST(ConfigTest, Endianness) {
 #endif
 }
 
+#if defined(ABSL_HAVE_THREAD_LOCAL)
+TEST(ConfigTest, ThreadLocal) {
+  static thread_local int mine_mine_mine = 16;
+  EXPECT_EQ(16, mine_mine_mine);
+  {
+    absl::synchronization_internal::ThreadPool pool(1);
+    pool.Schedule([&] {
+      EXPECT_EQ(16, mine_mine_mine);
+      mine_mine_mine = 32;
+      EXPECT_EQ(32, mine_mine_mine);
+    });
+  }
+  EXPECT_EQ(16, mine_mine_mine);
+}
+#endif
+
 }  // namespace
diff --git a/absl/base/optimization.h b/absl/base/optimization.h
index db8beafa3f2e..aaaffa495a9a 100644
--- a/absl/base/optimization.h
+++ b/absl/base/optimization.h
@@ -46,6 +46,7 @@
 // GCC will not tail call given inline volatile assembly.
 #define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION() __asm__ __volatile__("")
 #elif defined(_MSC_VER)
+#include <intrin.h>
 // The __nop() intrinsic blocks the optimisation.
 #define ABSL_BLOCK_TAIL_CALL_OPTIMIZATION() __nop()
 #else