Commit 58d507c1 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 4

Allow constexpr construction of AtomicStruct under MSVC

Summary: Attempting to use this under MSVC, as `MemoryIdler::defaultIdleTimeout` does, generated warnings about the symbol being dynamically initialized due to an implementation limation. Solve this by defining a union instead of calling `encode` in the constructor.

Reviewed By: yfeldblum

Differential Revision: D3387916

fbshipit-source-id: b0d628b6d086960e94121b6183a31348fb151aac
parent 5911efa1
......@@ -43,7 +43,10 @@ class AtomicStruct {
folly::IsTriviallyCopyable<T>::value,
"target type must be trivially copyable");
Atom<Raw> data;
union {
Atom<Raw> data;
T typedData;
};
static Raw encode(T v) noexcept {
// we expect the compiler to optimize away the memcpy, but without
......@@ -65,7 +68,7 @@ class AtomicStruct {
AtomicStruct(AtomicStruct<T> const &) = delete;
AtomicStruct<T>& operator= (AtomicStruct<T> const &) = delete;
constexpr /* implicit */ AtomicStruct(T v) noexcept : data(encode(v)) {}
constexpr /* implicit */ AtomicStruct(T v) noexcept : typedData(v) {}
bool is_lock_free() const noexcept {
return data.is_lock_free();
......
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