From 309dacedac6147e8c552b652e5fe2ffd02b6eac3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 23 Apr 2018 19:29:04 -0700 Subject: [PATCH] Atomics: remove requirement for alignment equality with plain types This was originally added so that you could replace a T with QAtomicInteger in the same class and still keep ABI. However, for legacy reasons, on 32-bit x86, types larger than 4 bytes keep an old 1990s alignment of only 4 bytes, but modern std::atomic for those 8- byte types enforces an alignment of 8 bytes. Therefore, the requirement to keep alignment is not possible to guarantee. In other words: you may not replace T with QAtomicInteger or std::atomic and assume no ABI breakages in all platforms. This is a requirement to implement atomicity. An 8-byte type aligned to only a 4-byte boundary could cross a 16-byte boundary or, worse, cross a cacheline boundary. Crossing the 16-byte boundary could be bad on some processors, but crossing the cacheline boundary (addresses ending in 0x3C, 0x7C, 0xCC and 0xFC, or 4 out of 64 possible addresses or 6.25%) is always bad: the CPUs cannot guarantee an atomic load or store operation. See also . Task-number: QTBUG-67858 Change-Id: If90a92b041d3442fa0a4fffd15283e4615474582 Reviewed-by: Frederik Gladhorn --- tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp index ca40927ef9..32e5b8ee56 100644 --- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp +++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp @@ -185,12 +185,10 @@ private Q_SLOTS: }; template inline void booleanHelper() { } -struct TypeInStruct { TEST_TYPE type; }; void tst_QAtomicIntegerXX::static_checks() { Q_STATIC_ASSERT(sizeof(QAtomicInteger) == sizeof(T)); - Q_STATIC_ASSERT(Q_ALIGNOF(QAtomicInteger) == Q_ALIGNOF(TypeInStruct)); // statements with no effect (void) QAtomicInteger::isReferenceCountingNative();