summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2017-06-19 12:27:08 -0400
committerAndrew Morrow <acm@mongodb.com>2017-06-20 09:47:22 -0400
commite05068da490e900c68d5254a7336d6f7b9354ad6 (patch)
tree3ecac75a41fa59fe9f69408629556001fc10eb56 /SConstruct
parent3d25846ea31d91468475086035f4794ad126ed0f (diff)
downloadmongo-e05068da490e900c68d5254a7336d6f7b9354ad6.tar.gz
SERVER-29712 Add a polyfill for std::hardware_constructive_interference_size
Diffstat (limited to 'SConstruct')
-rw-r--r--SConstruct44
1 files changed, 44 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct
index d76ccfab807..041967fc278 100644
--- a/SConstruct
+++ b/SConstruct
@@ -2957,6 +2957,50 @@ def doConfigure(myenv):
if not check_all_atomics(' with libatomic'):
myenv.ConfError("The toolchain does not support std::atomic, cannot continue")
+ def CheckExtendedAlignment(context, size):
+ test_body = """
+ #include <atomic>
+ #include <mutex>
+ #include <cstddef>
+
+ static_assert(alignof(std::max_align_t) < {0}, "whatever");
+
+ alignas({0}) std::mutex aligned_mutex;
+ alignas({0}) std::atomic<int> aligned_atomic;
+
+ struct alignas({0}) aligned_struct_mutex {{
+ std::mutex m;
+ }};
+
+ struct alignas({0}) aligned_struct_atomic {{
+ std::atomic<int> m;
+ }};
+
+ struct holds_aligned_mutexes {{
+ alignas({0}) std::mutex m1;
+ alignas({0}) std::mutex m2;
+ }} hm;
+
+ struct holds_aligned_atomics {{
+ alignas({0}) std::atomic<int> a1;
+ alignas({0}) std::atomic<int> a2;
+ }} ha;
+ """.format(size)
+
+ context.Message('Checking for extended alignment {0} for concurrency types... '.format(size))
+ ret = context.TryCompile(textwrap.dedent(test_body), ".cpp")
+ context.Result(ret)
+ return ret
+
+ conf.AddTest('CheckExtendedAlignment', CheckExtendedAlignment)
+
+ # We are aware of no architecture with a cache line bigger than
+ # 256. If we had a way to get the cache line size of TARGET_ARCH
+ # that would be better, but we don't seem to have that.
+ for size in (64, 128, 256):
+ if conf.CheckExtendedAlignment(size):
+ conf.env.SetConfigHeaderDefine("MONGO_CONFIG_MAX_EXTENDED_ALIGNMENT", size)
+
# ask each module to configure itself and the build environment.
moduleconfig.configure_modules(mongo_modules, conf)