Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/rigtorp/SPSCQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class SPSCQueue {
/// consumed. Calling pop() on an empty queue violates this precondition.
void pop() noexcept {
auto const readIdx = readIdx_.load(std::memory_order_relaxed);
assert(writeIdx_.load(std::memory_order_acquire) != readIdx &&
// A successful front() has already acquired and cached the write index.
assert(writeIdxCache_ != readIdx &&
"Can only call pop() after front() has returned a non-nullptr");
std::destroy_at(&slots_[readIdx + kPadding]);
auto nextReadIdx = readIdx + 1;
Expand Down
12 changes: 9 additions & 3 deletions src/SPSCQueueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ static void testConcurrency() {
}
}

static void testDeathPopEmpty() {
static void testDeathPopWithoutFront(bool enqueue) {
#if (defined(__unix__) || defined(__APPLE__)) && !defined(NDEBUG)
using namespace rigtorp;

Expand All @@ -722,13 +722,18 @@ static void testDeathPopEmpty() {
// coredumpctl / ABRT via default SIGABRT termination.
std::signal(SIGABRT, [](int) { _exit(42); });
SPSCQueue<int> q(2);
q.pop(); // Must abort in debug builds
if (enqueue) {
q.push(1);
}
q.pop(); // Must abort in debug builds without a successful front()
_exit(0);
}

int status = 0;
CHECK(waitpid(pid, &status, 0) == pid);
CHECK(WIFEXITED(status) && WEXITSTATUS(status) == 42);
#else
(void)enqueue;
#endif
}

Expand Down Expand Up @@ -842,7 +847,8 @@ int main(int argc, char *argv[]) {
testAlignedElementPadding();
testCapacityAllocationBounds<RecordingAllocator<char>>();
testCapacityAllocationBounds<RecordingAtLeastAllocator<char>>();
testDeathPopEmpty();
testDeathPopWithoutFront(false);
testDeathPopWithoutFront(true);
testTryPop();
testConcurrency();

Expand Down
Loading