diff --git a/folly/synchronization/Tearable.h b/folly/synchronization/Tearable.h index 97ac0b8cc68f2d1b35045c80056c3b235547ec5c..21c94b20f98fb716f9b24e91b502087913753b6e 100644 --- a/folly/synchronization/Tearable.h +++ b/folly/synchronization/Tearable.h @@ -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 diff --git a/folly/synchronization/test/TearableTest.cpp b/folly/synchronization/test/TearableTest.cpp index 96101f59088187ea0849287e8251bdc72cf18f6e..b10dbb25623af9db7deb6ada8fc69e6fc5935751 100644 --- a/folly/synchronization/test/TearableTest.cpp +++ b/folly/synchronization/test/TearableTest.cpp @@ -26,6 +26,8 @@ using namespace folly; namespace { struct Data { + using IsTriviallyCopyable = std::true_type; + Data(unsigned char value) { setValue(value); }