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

Fixed initialization of Tearable with libstdc++-v4.9.2

Summary: [Folly] Fixed initialization of `Tearable` with libstdc++-v4.9.2, which is missing definitions of `atomic_init`.

Reviewed By: davidtgoldblatt

Differential Revision: D6833004

fbshipit-source-id: 88d4cc91f90618a98df110bec5e434c35e750b16
parent 137443e8
......@@ -53,11 +53,7 @@ class Tearable {
IsTriviallyCopyable<T>::value,
"Tearable types must be trivially copyable.");
Tearable() {
for (std::size_t i = 0; i < kNumDataWords; ++i) {
std::atomic_init(&data_[i], RawWord{});
}
}
Tearable() = default;
Tearable(const T& val) : Tearable() {
store(val);
......@@ -91,10 +87,15 @@ class Tearable {
// trailing data word in write(), for instance).
unsigned char data alignas(void*)[sizeof(void*)];
};
// Because std::atomic_init is declared but undefined in libstdc++-v4.9.2:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64658.
struct AtomicWord : std::atomic<RawWord> {
AtomicWord() noexcept : std::atomic<RawWord>{RawWord{}} {}
};
const static std::size_t kNumDataWords =
(sizeof(T) + sizeof(RawWord) - 1) / sizeof(RawWord);
std::atomic<RawWord> data_[kNumDataWords];
AtomicWord data_[kNumDataWords];
};
} // namespace folly
......@@ -26,6 +26,8 @@ using namespace folly;
namespace {
struct Data {
using IsTriviallyCopyable = std::true_type;
Data(unsigned char value) {
setValue(value);
}
......
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