about summary refs log tree commit diff
path: root/absl/base
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2017-12-15T19·12-0800
committerAshley Hedberg <ahedberg@google.com>2017-12-18T15·00-0500
commit4972c72c5cf2f27e2a0846ce9ff5d377d3f2b7af (patch)
treec95abdf920010c988925dbc22d11eb789552534d /absl/base
parent6280bddf55e675219cacc25a6a12bc5ddc0fdc74 (diff)
Changes imported from Abseil "staging" branch:
  - f59c2332341d6b1a3e045d61eb0065f7a226f807 Avoid preprocessing  '__CUDACC_VER__ >= 70000' on CUDA 9,... by Abseil Team <absl-team@google.com>
  - 12dd22cf967603e9a12d58abfe877989d61844e3 Internal change. by Greg Falcon <gfalcon@google.com>

GitOrigin-RevId: f59c2332341d6b1a3e045d61eb0065f7a226f807
Change-Id: If4f5274e6d638a2ac86f1377e6ac0481dc584f19
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/config.h24
-rw-r--r--absl/base/internal/malloc_hook.cc1
-rw-r--r--absl/base/internal/spinlock.cc5
-rw-r--r--absl/base/internal/spinlock.h6
-rw-r--r--absl/base/internal/sysinfo.cc2
-rw-r--r--absl/base/internal/thread_identity_test.cc1
-rw-r--r--absl/base/spinlock_test_common.cc5
7 files changed, 24 insertions, 20 deletions
diff --git a/absl/base/config.h b/absl/base/config.h
index 5802b653baff..3f3b8b3a64e3 100644
--- a/absl/base/config.h
+++ b/absl/base/config.h
@@ -181,21 +181,21 @@
 // __SIZEOF_INT128__ but not all versions actually support __int128.
 #ifdef ABSL_HAVE_INTRINSIC_INT128
 #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
-#elif (defined(__clang__) && defined(__SIZEOF_INT128__) &&               \
-       !defined(__aarch64__)) ||                                         \
-    (defined(__CUDACC__) && defined(__SIZEOF_INT128__) &&                \
-     __CUDACC_VER_MAJOR__ >= 9) ||                                       \
-    (!defined(__clang__) && !defined(__CUDACC__) && defined(__GNUC__) && \
-     defined(__SIZEOF_INT128__))
+#elif defined(__SIZEOF_INT128__)
+#if (defined(__clang__) && !defined(__aarch64__)) ||      \
+    (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
+    (!defined(__clang__) && !defined(__CUDACC__) && defined(__GNUC__))
 #define ABSL_HAVE_INTRINSIC_INT128 1
+#elif defined(__CUDACC__)
 // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
-// std::string explaining that it has been removed starting with CUDA 9. We can't
-// compare both variants in a single boolean expression because there is no
-// short-circuiting in the preprocessor.
-#elif defined(__CUDACC__) && defined(__SIZEOF_INT128__) && \
-    __CUDACC_VER__ >= 7000
+// std::string explaining that it has been removed starting with CUDA 9. We use
+// nested #ifs because there is no short-circuiting in the preprocessor.
+// NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
+#if __CUDACC_VER__ >= 70000
 #define ABSL_HAVE_INTRINSIC_INT128 1
-#endif
+#endif  // __CUDACC_VER__ >= 70000
+#endif  // defined(__CUDACC__)
+#endif  // ABSL_HAVE_INTRINSIC_INT128
 
 // ABSL_HAVE_EXCEPTIONS
 //
diff --git a/absl/base/internal/malloc_hook.cc b/absl/base/internal/malloc_hook.cc
index 7165d4cbd02a..52531c680148 100644
--- a/absl/base/internal/malloc_hook.cc
+++ b/absl/base/internal/malloc_hook.cc
@@ -12,6 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#include "absl/base/attributes.h"
 #include "absl/base/config.h"
 
 #if ABSL_HAVE_MMAP
diff --git a/absl/base/internal/spinlock.cc b/absl/base/internal/spinlock.cc
index 3ac1f4dc96c3..28a2059f3287 100644
--- a/absl/base/internal/spinlock.cc
+++ b/absl/base/internal/spinlock.cc
@@ -83,11 +83,6 @@ void RegisterSpinLockProfiler(void (*fn)(const void *contendedlock,
   submit_profile_data.Store(fn);
 }
 
-static inline bool IsCooperative(
-    base_internal::SchedulingMode scheduling_mode) {
-  return scheduling_mode == base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL;
-}
-
 // Uncommon constructors.
 SpinLock::SpinLock(base_internal::SchedulingMode mode)
     : lockword_(IsCooperative(mode) ? kSpinLockCooperative : 0) {
diff --git a/absl/base/internal/spinlock.h b/absl/base/internal/spinlock.h
index f486f68a04f9..a9037e3ed05c 100644
--- a/absl/base/internal/spinlock.h
+++ b/absl/base/internal/spinlock.h
@@ -151,6 +151,12 @@ class LOCKABLE SpinLock {
   enum { kWaitTimeMask =                      // Includes kSpinLockSleeper.
     ~(kSpinLockHeld | kSpinLockCooperative | kSpinLockDisabledScheduling) };
 
+  // Returns true if the provided scheduling mode is cooperative.
+  static constexpr bool IsCooperative(
+      base_internal::SchedulingMode scheduling_mode) {
+    return scheduling_mode == base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL;
+  }
+
   uint32_t TryLockInternal(uint32_t lock_value, uint32_t wait_cycles);
   void InitLinkerInitializedAndCooperative();
   void SlowLock() ABSL_ATTRIBUTE_COLD;
diff --git a/absl/base/internal/sysinfo.cc b/absl/base/internal/sysinfo.cc
index 884c31262877..dca7d8fdc020 100644
--- a/absl/base/internal/sysinfo.cc
+++ b/absl/base/internal/sysinfo.cc
@@ -14,6 +14,8 @@
 
 #include "absl/base/internal/sysinfo.h"
 
+#include "absl/base/attributes.h"
+
 #ifdef _WIN32
 #include <shlwapi.h>
 #include <windows.h>
diff --git a/absl/base/internal/thread_identity_test.cc b/absl/base/internal/thread_identity_test.cc
index 7695a091cdf9..ecb8af689829 100644
--- a/absl/base/internal/thread_identity_test.cc
+++ b/absl/base/internal/thread_identity_test.cc
@@ -18,6 +18,7 @@
 #include <vector>
 
 #include "gtest/gtest.h"
+#include "absl/base/attributes.h"
 #include "absl/base/internal/spinlock.h"
 #include "absl/base/macros.h"
 #include "absl/synchronization/internal/per_thread_sem.h"
diff --git a/absl/base/spinlock_test_common.cc b/absl/base/spinlock_test_common.cc
index 6918603ca954..1b508848611e 100644
--- a/absl/base/spinlock_test_common.cc
+++ b/absl/base/spinlock_test_common.cc
@@ -23,6 +23,7 @@
 #include <vector>
 
 #include "gtest/gtest.h"
+#include "absl/base/attributes.h"
 #include "absl/base/internal/low_level_scheduling.h"
 #include "absl/base/internal/scheduling_mode.h"
 #include "absl/base/internal/spinlock.h"
@@ -53,7 +54,6 @@ namespace {
 
 static constexpr int kArrayLength = 10;
 static uint32_t values[kArrayLength];
-
 static SpinLock static_spinlock(base_internal::kLinkerInitialized);
 static SpinLock static_cooperative_spinlock(
     base_internal::kLinkerInitialized,
@@ -61,6 +61,7 @@ static SpinLock static_cooperative_spinlock(
 static SpinLock static_noncooperative_spinlock(
     base_internal::kLinkerInitialized, base_internal::SCHEDULE_KERNEL_ONLY);
 
+
 // Simple integer hash function based on the public domain lookup2 hash.
 // http://burtleburtle.net/bob/c/lookup2.c
 static uint32_t Hash32(uint32_t a, uint32_t c) {
@@ -187,11 +188,9 @@ TEST(SpinLock, WaitCyclesEncoding) {
     SpinLockTest::DecodeWaitCycles(before_max_value);
   EXPECT_GT(expected_max_value_decoded, before_max_value_decoded);
 }
-
 TEST(SpinLockWithThreads, StaticSpinLock) {
   ThreadedTest(&static_spinlock);
 }
-
 TEST(SpinLockWithThreads, StackSpinLock) {
   SpinLock spinlock;
   ThreadedTest(&spinlock);