Commit 8462db08 authored by Shoaib Meenai's avatar Shoaib Meenai Committed by Facebook Github Bot

Check CachelinePadded alignment requirement dynamically

Summary:
It's possible, but not required, for platforms to support alignment
requirements greater than std::max_align_t. For example, on some 32-bit
platforms (e.g. iPhone armv7), std::max_align_t is only 4, but
std::atomic<unsigned long long> has an alignment requirement of 8. Check
for alignment at runtime instead of compile time to avoid spurious
static assertion failures.

Reviewed By: nbronson

Differential Revision: D17488704

fbshipit-source-id: 54cd7c2d7aec4f7f93e5fa6d62f8237f66a6c018
parent fff74a54
...@@ -17,9 +17,11 @@ ...@@ -17,9 +17,11 @@
#pragma once #pragma once
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <utility> #include <utility>
#include <folly/lang/Align.h> #include <folly/lang/Align.h>
#include <folly/lang/SafeAssert.h>
namespace folly { namespace folly {
...@@ -35,14 +37,15 @@ namespace folly { ...@@ -35,14 +37,15 @@ namespace folly {
*/ */
template <typename T> template <typename T>
class CachelinePadded { class CachelinePadded {
static_assert(
alignof(T) <= max_align_v,
"CachelinePadded does not support over-aligned types.");
public: public:
template <typename... Args> template <typename... Args>
explicit CachelinePadded(Args&&... args) explicit CachelinePadded(Args&&... args)
: inner_(std::forward<Args>(args)...) {} : inner_(std::forward<Args>(args)...) {
FOLLY_SAFE_DCHECK(
(reinterpret_cast<uintptr_t>(&inner_) % alignof(T)) == 0,
"CachelinePadded requires types aligned to their ABI requirement");
}
T* get() { T* get() {
return &inner_; return &inner_;
......
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