Commit 79c28f03 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Use static constexpr WaitOptions in UnboundedQueue

Summary: [Folly] Use `static constexpr WaitOptions` in `UnboundedQueue` to save one store-word-to-stack instruction in the inlined fast path with gcc.

Reviewed By: magedm

Differential Revision: D13187890

fbshipit-source-id: 79a4f4ba585ed8abaebef344081bd364144f6cf8
parent 875819ab
...@@ -231,6 +231,8 @@ class UnboundedQueue { ...@@ -231,6 +231,8 @@ class UnboundedQueue {
static_assert(LgSegmentSize < 32, "LgSegmentSize must be < 32"); static_assert(LgSegmentSize < 32, "LgSegmentSize must be < 32");
static_assert(LgAlign < 16, "LgAlign must be < 16"); static_assert(LgAlign < 16, "LgAlign must be < 16");
using Sem = folly::SaturatingSemaphore<MayBlock, Atom>;
struct Consumer { struct Consumer {
Atom<Segment*> head; Atom<Segment*> head;
Atom<Ticket> ticket; Atom<Ticket> ticket;
...@@ -754,7 +756,7 @@ class UnboundedQueue { ...@@ -754,7 +756,7 @@ class UnboundedQueue {
* Entry * Entry
*/ */
class Entry { class Entry {
folly::SaturatingSemaphore<MayBlock, Atom> flag_; Sem flag_;
typename std::aligned_storage<sizeof(T), alignof(T)>::type item_; typename std::aligned_storage<sizeof(T), alignof(T)>::type item_;
public: public:
...@@ -780,11 +782,11 @@ class UnboundedQueue { ...@@ -780,11 +782,11 @@ class UnboundedQueue {
} }
template <typename Clock, typename Duration> template <typename Clock, typename Duration>
FOLLY_ALWAYS_INLINE bool tryWaitUntil( FOLLY_EXPORT FOLLY_ALWAYS_INLINE bool tryWaitUntil(
const std::chrono::time_point<Clock, Duration>& deadline) noexcept { const std::chrono::time_point<Clock, Duration>& deadline) noexcept {
// wait-options from benchmarks on contended queues: // wait-options from benchmarks on contended queues:
auto const opt = static constexpr auto const opt =
flag_.wait_options().spin_max(std::chrono::microseconds(10)); Sem::wait_options().spin_max(std::chrono::microseconds(10));
return flag_.try_wait_until(deadline, opt); return flag_.try_wait_until(deadline, opt);
} }
......
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