Commit 51ad358e authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

cacheline_align_t, cacheline_align_v

Summary: [Folly] `cacheline_align_t`, `cacheline_align_v` - since it is theoretically possible on some platforms for `alignas(hardware_destructive_interference_size)` to be a compile-time error.

Reviewed By: aary

Differential Revision: D16598497

fbshipit-source-id: d0dfe99b726cec5dba96e26147e73e494e62a895
parent a93eb033
......@@ -17,6 +17,7 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <folly/Portability.h>
......@@ -118,4 +119,16 @@ static_assert(hardware_destructive_interference_size >= max_align_v, "math?");
constexpr std::size_t hardware_constructive_interference_size = 64;
static_assert(hardware_constructive_interference_size >= max_align_v, "math?");
// A value corresponding to hardware_constructive_interference_size but which
// may be used with alignas, since hardware_constructive_interference_size may
// be too large on some platforms to be used with alignas.
//
// Currently, very heuristical - only non-mobile 64-bit linux gets the extended
// alignment treatment. Theoretically, this could be tuned better.
constexpr std::size_t cacheline_align_v =
kIsLinux && sizeof(void*) >= sizeof(std::uint64_t)
? hardware_constructive_interference_size
: max_align_v;
struct alignas(cacheline_align_v) cacheline_align_t {};
} // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment