@@ -125,7 +125,7 @@ constexpr T nil() noexcept {
125125}
126126
127127template <class T >
128- ATOMIC_QUEUE_INLINE static void destroy_n (T* p, unsigned n) noexcept {
128+ ATOMIC_QUEUE_INLINE static void destroy_n (T* ATOMIC_QUEUE_RESTRICT p, unsigned n) noexcept {
129129 for (auto q = p + n; p != q;)
130130 (p++)->~T ();
131131}
@@ -452,8 +452,14 @@ class AtomicQueueB : private std::allocator_traits<A>::template rebind_alloc<std
452452
453453 // AtomicQueueCommon members are stored into by readers and writers.
454454 // Allocate these immutable members on another cache line which never gets invalidated by stores.
455- alignas (CACHE_LINE_SIZE) unsigned size_;
456- std::atomic<T>* elements_;
455+ alignas (CACHE_LINE_SIZE)
456+ unsigned size_;
457+
458+ // The C++ strict aliasing rules assume that pointers to the same decayed type may alias.
459+ // The C++ strict aliasing rules assume that pointers to any char type may alias anything and everything.
460+ // A dynamically allocated array may not alias anything else by construction.
461+ // Explicitly annotate the circular buffer array pointer as not aliasing anything else with restrict keyword.
462+ std::atomic<T>* ATOMIC_QUEUE_RESTRICT elements_;
457463
458464 ATOMIC_QUEUE_INLINE T do_pop (unsigned tail) noexcept {
459465 std::atomic<T>& q_element = details::map<SHUFFLE_BITS>(elements_, tail & (size_ - 1 ));
@@ -533,9 +539,15 @@ class AtomicQueueB2 : private std::allocator_traits<A>::template rebind_alloc<un
533539
534540 // AtomicQueueCommon members are stored into by readers and writers.
535541 // Allocate these immutable members on another cache line which never gets invalidated by stores.
536- alignas (CACHE_LINE_SIZE) unsigned size_;
537- AtomicState* states_;
538- T* elements_;
542+ alignas (CACHE_LINE_SIZE)
543+ unsigned size_;
544+
545+ // The C++ strict aliasing rules assume that pointers to the same decayed type may alias.
546+ // The C++ strict aliasing rules assume that pointers to any char type may alias anything and everything.
547+ // A dynamically allocated array may not alias anything else by construction.
548+ // Explicitly annotate the circular buffer array pointers as not aliasing anything else with restrict keyword.
549+ AtomicState* ATOMIC_QUEUE_RESTRICT states_;
550+ T* ATOMIC_QUEUE_RESTRICT elements_;
539551
540552 static constexpr auto STATES_PER_CACHE_LINE = CACHE_LINE_SIZE / sizeof (AtomicState);
541553 static_assert (STATES_PER_CACHE_LINE, " Unexpected STATES_PER_CACHE_LINE." );
0 commit comments