Skip to content

Commit c74a628

Browse files
falucocodebot
authored andcommitted
Fix #3610
1 parent a96edc3 commit c74a628

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

external/rigtorp/SPSCQueue.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ template <typename T, typename Allocator = std::allocator<T>> class SPSCQueue {
8484

8585
static_assert(alignof(SPSCQueue<T>) == kCacheLineSize, "");
8686
static_assert(sizeof(SPSCQueue<T>) >= 3 * kCacheLineSize, "");
87-
assert(reinterpret_cast<char *>(&readIdx_) -
88-
reinterpret_cast<char *>(&writeIdx_) >=
89-
static_cast<std::ptrdiff_t>(kCacheLineSize));
87+
static_assert(offsetof(SPSCQueue<T>, readIdx_) -
88+
offsetof(SPSCQueue<T>, writeIdx_) >= kCacheLineSize, "");
9089
}
9190

9291
~SPSCQueue() {
@@ -180,7 +179,8 @@ template <typename T, typename Allocator = std::allocator<T>> class SPSCQueue {
180179
static_assert(std::is_nothrow_destructible<T>::value,
181180
"T must be nothrow destructible");
182181
auto const readIdx = readIdx_.load(std::memory_order_relaxed);
183-
assert(writeIdx_.load(std::memory_order_acquire) != readIdx);
182+
assert(writeIdx_.load(std::memory_order_acquire) != readIdx &&
183+
"Can only call pop() after front() has returned a non-nullptr");
184184
slots_[readIdx + kPadding].~T();
185185
auto nextReadIdx = readIdx + 1;
186186
if (nextReadIdx == capacity_) {
@@ -227,9 +227,5 @@ template <typename T, typename Allocator = std::allocator<T>> class SPSCQueue {
227227
alignas(kCacheLineSize) size_t readIdxCache_ = 0;
228228
alignas(kCacheLineSize) std::atomic<size_t> readIdx_ = {0};
229229
alignas(kCacheLineSize) size_t writeIdxCache_ = 0;
230-
231-
// Padding to avoid adjacent allocations to share cache line with
232-
// writeIdxCache_
233-
char padding_[kCacheLineSize - sizeof(writeIdxCache_)];
234230
};
235231
} // namespace rigtorp

0 commit comments

Comments
 (0)