Commit 8712f361 authored by Martin Martin's avatar Martin Martin Committed by Facebook Github Bot

When you read from a default-constructed MPMCQueue, assert instead of SIGFPE.

Summary:
I accidentally forgot to specify the capacity for my
MPMCQueue.  When I then did a blockingRead(), I got a SIGFPE.  Thanks
to a custom signal handler that doesn't print stack traces, and a few
more comedy of errors, I lost a day to this.  With this patch, I would
have gotten an assertion failure instead.

Reviewed By: yfeldblum

Differential Revision: D4169033

fbshipit-source-id: fab97ea0d5afc3c06885758b31a5e8c91ae75a45
parent 1d2d4f32
...@@ -888,6 +888,7 @@ class MPMCQueueBase<Derived<T, Atom, Dynamic>> : boost::noncopyable { ...@@ -888,6 +888,7 @@ class MPMCQueueBase<Derived<T, Atom, Dynamic>> : boost::noncopyable {
/// Same as blockingRead() but also records the ticket nunmer /// Same as blockingRead() but also records the ticket nunmer
void blockingReadWithTicket(uint64_t& ticket, T& elem) noexcept { void blockingReadWithTicket(uint64_t& ticket, T& elem) noexcept {
assert(capacity_ != 0);
ticket = popTicket_++; ticket = popTicket_++;
dequeueWithTicketBase(ticket, slots_, capacity_, stride_, elem); dequeueWithTicketBase(ticket, slots_, capacity_, stride_, elem);
} }
...@@ -1065,6 +1066,7 @@ class MPMCQueueBase<Derived<T, Atom, Dynamic>> : boost::noncopyable { ...@@ -1065,6 +1066,7 @@ class MPMCQueueBase<Derived<T, Atom, Dynamic>> : boost::noncopyable {
/// Maps an enqueue or dequeue ticket to the turn should be used at the /// Maps an enqueue or dequeue ticket to the turn should be used at the
/// corresponding SingleElementQueue /// corresponding SingleElementQueue
uint32_t turn(uint64_t ticket, size_t cap) noexcept { uint32_t turn(uint64_t ticket, size_t cap) noexcept {
assert(cap != 0);
return ticket / cap; return ticket / cap;
} }
...@@ -1270,6 +1272,7 @@ class MPMCQueueBase<Derived<T, Atom, Dynamic>> : boost::noncopyable { ...@@ -1270,6 +1272,7 @@ class MPMCQueueBase<Derived<T, Atom, Dynamic>> : boost::noncopyable {
void dequeueWithTicketBase( void dequeueWithTicketBase(
uint64_t ticket, Slot* slots, size_t cap, int stride, T& elem uint64_t ticket, Slot* slots, size_t cap, int stride, T& elem
) noexcept { ) noexcept {
assert(cap != 0);
slots[idx(ticket, cap, stride)] slots[idx(ticket, cap, stride)]
.dequeue(turn(ticket, cap), .dequeue(turn(ticket, cap),
popSpinCutoff_, popSpinCutoff_,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment