about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-12-27T10·49-0800
committerGennadiy Civil <misterg@google.com>2018-12-27T16·50-0500
commit7ffbe09f3d85504bd018783bbe1e2c12992fe47c (patch)
treef91fa25267d411ba91edbb8c447e9fdc2bd91881
parent01b471d9f3ebef27f5aaca14b66509099fa8cd6c (diff)
Export of internal Abseil changes.
--
027adbb0bceda5c3908f7f4d3a911284ee407b3d by Abseil Team <absl-team@google.com>:

Make ABSL_CACHELINE_ALIGNED work for Visual C++.

PiperOrigin-RevId: 227007205
GitOrigin-RevId: 027adbb0bceda5c3908f7f4d3a911284ee407b3d
Change-Id: I572ec7e79dda1291eb324c90a39be90e744b4b05
-rw-r--r--absl/base/optimization.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/absl/base/optimization.h b/absl/base/optimization.h
index 2fddfc800c1d..9789c2ccd6a1 100644
--- a/absl/base/optimization.h
+++ b/absl/base/optimization.h
@@ -111,9 +111,9 @@
 // See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0154r1.html
 // for more information.
 //
-// On some compilers, `ABSL_CACHELINE_ALIGNED` expands to
-// `__attribute__((aligned(ABSL_CACHELINE_SIZE)))`. For compilers where this is
-// not known to work, the macro expands to nothing.
+// On some compilers, `ABSL_CACHELINE_ALIGNED` expands to an `__attribute__`
+// or `__declspec` attribute. For compilers where this is not known to work,
+// the macro expands to nothing.
 //
 // No further guarantees are made here. The result of applying the macro
 // to variables and types is always implementation-defined.
@@ -122,6 +122,14 @@
 // of causing bugs that are difficult to diagnose, crash, etc. It does not
 // of itself guarantee that objects are aligned to a cache line.
 //
+// NOTE: Some compilers are picky about the locations of annotations such as
+// this attribute, so prefer to put it at the beginning of your declaration.
+// For example,
+//
+//   ABSL_CACHELINE_ALIGNED static Foo* foo = ...
+//
+//   class ABSL_CACHELINE_ALIGNED Bar { ...
+//
 // Recommendations:
 //
 // 1) Consult compiler documentation; this comment is not kept in sync as
@@ -131,8 +139,10 @@
 // 3) Prefer applying this attribute to individual variables. Avoid
 //    applying it to types. This tends to localize the effect.
 #define ABSL_CACHELINE_ALIGNED __attribute__((aligned(ABSL_CACHELINE_SIZE)))
-
-#else  // not GCC
+#elif defined(_MSC_VER)
+#define ABSL_CACHELINE_SIZE 64
+#define ABSL_CACHELINE_ALIGNED __declspec(align(ABSL_CACHELINE_SIZE))
+#else
 #define ABSL_CACHELINE_SIZE 64
 #define ABSL_CACHELINE_ALIGNED
 #endif