Skip to content

Commit 7ffbe09

Browse files
Abseil Teamgennadiycivil
Abseil Team
authored andcommitted
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
1 parent 01b471d commit 7ffbe09

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

absl/base/optimization.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@
111111
// See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0154r1.html
112112
// for more information.
113113
//
114-
// On some compilers, `ABSL_CACHELINE_ALIGNED` expands to
115-
// `__attribute__((aligned(ABSL_CACHELINE_SIZE)))`. For compilers where this is
116-
// not known to work, the macro expands to nothing.
114+
// On some compilers, `ABSL_CACHELINE_ALIGNED` expands to an `__attribute__`
115+
// or `__declspec` attribute. For compilers where this is not known to work,
116+
// the macro expands to nothing.
117117
//
118118
// No further guarantees are made here. The result of applying the macro
119119
// to variables and types is always implementation-defined.
@@ -122,6 +122,14 @@
122122
// of causing bugs that are difficult to diagnose, crash, etc. It does not
123123
// of itself guarantee that objects are aligned to a cache line.
124124
//
125+
// NOTE: Some compilers are picky about the locations of annotations such as
126+
// this attribute, so prefer to put it at the beginning of your declaration.
127+
// For example,
128+
//
129+
// ABSL_CACHELINE_ALIGNED static Foo* foo = ...
130+
//
131+
// class ABSL_CACHELINE_ALIGNED Bar { ...
132+
//
125133
// Recommendations:
126134
//
127135
// 1) Consult compiler documentation; this comment is not kept in sync as
@@ -131,8 +139,10 @@
131139
// 3) Prefer applying this attribute to individual variables. Avoid
132140
// applying it to types. This tends to localize the effect.
133141
#define ABSL_CACHELINE_ALIGNED __attribute__((aligned(ABSL_CACHELINE_SIZE)))
134-
135-
#else // not GCC
142+
#elif defined(_MSC_VER)
143+
#define ABSL_CACHELINE_SIZE 64
144+
#define ABSL_CACHELINE_ALIGNED __declspec(align(ABSL_CACHELINE_SIZE))
145+
#else
136146
#define ABSL_CACHELINE_SIZE 64
137147
#define ABSL_CACHELINE_ALIGNED
138148
#endif

0 commit comments

Comments
 (0)