Commit 39080c90 authored by Hannes Roth's avatar Hannes Roth Committed by facebook-github-bot-9

(Wangle) Align lambdaBuf_

Summary: Not aligning `lambdaBuf_` can lead to unaligned reads, which can be a problem on some platforms.

We use `lambdaBuf_` to store a type of up to `lambdaBufSize`, so aligning it to that should always be safe.

Reviewed By: @alexshap

Differential Revision: D2319347
parent 344f7d2a
...@@ -148,7 +148,7 @@ class Core { ...@@ -148,7 +148,7 @@ class Core {
// Move the lambda into the Core if it fits // Move the lambda into the Core if it fits
if (sizeof(LambdaBufHelper<F>) <= lambdaBufSize) { if (sizeof(LambdaBufHelper<F>) <= lambdaBufSize) {
auto funcLoc = static_cast<LambdaBufHelper<F>*>((void*)lambdaBuf_); auto funcLoc = reinterpret_cast<LambdaBufHelper<F>*>(&lambdaBuf_);
new (funcLoc) LambdaBufHelper<F>(std::forward<F>(func)); new (funcLoc) LambdaBufHelper<F>(std::forward<F>(func));
callback_ = std::ref(*funcLoc); callback_ = std::ref(*funcLoc);
} else { } else {
...@@ -366,7 +366,7 @@ class Core { ...@@ -366,7 +366,7 @@ class Core {
// lambdaBuf occupies exactly one cache line // lambdaBuf occupies exactly one cache line
static constexpr size_t lambdaBufSize = 8 * sizeof(void*); static constexpr size_t lambdaBufSize = 8 * sizeof(void*);
char lambdaBuf_[lambdaBufSize]; typename std::aligned_storage<lambdaBufSize>::type lambdaBuf_;
// place result_ next to increase the likelihood that the value will be // place result_ next to increase the likelihood that the value will be
// contained entirely in one cache line // contained entirely in one cache line
folly::Optional<Try<T>> result_; folly::Optional<Try<T>> result_;
......
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