From f07fd710bbbe57c2153eda3d3065d92e17d7306d Mon Sep 17 00:00:00 2001 From: Misha Shneerson Date: Mon, 16 Nov 2020 17:52:26 -0800 Subject: [PATCH] small refactor of AtomicNotificationQueue, move Node out of Queue Reviewed By: andriigrynenko Differential Revision: D24880761 fbshipit-source-id: 643da2b0fd461955ea33b4ba48f377c30720d442 --- folly/io/async/AtomicNotificationQueue-inl.h | 7 +++--- folly/io/async/AtomicNotificationQueue.h | 26 +++++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/folly/io/async/AtomicNotificationQueue-inl.h b/folly/io/async/AtomicNotificationQueue-inl.h index d127fa5b804..603f019240b 100644 --- a/folly/io/async/AtomicNotificationQueue-inl.h +++ b/folly/io/async/AtomicNotificationQueue-inl.h @@ -54,7 +54,7 @@ ssize_t AtomicNotificationQueue::Queue::size() const { } template -typename AtomicNotificationQueue::Queue::Node& +typename AtomicNotificationQueue::Node& AtomicNotificationQueue::Queue::front() { return *head_; } @@ -104,8 +104,7 @@ AtomicNotificationQueue::AtomicQueue::~AtomicQueue() { template template bool AtomicNotificationQueue::AtomicQueue::push(T&& value) { - std::unique_ptr node( - new typename Queue::Node(std::forward(value))); + std::unique_ptr node(new Node(std::forward(value))); auto head = head_.load(std::memory_order_relaxed); while (true) { node->next = @@ -147,7 +146,7 @@ AtomicNotificationQueue::AtomicQueue::arm() { if (!head && head_.compare_exchange_strong( head, - reinterpret_cast(kQueueArmedTag), + reinterpret_cast(kQueueArmedTag), std::memory_order_relaxed, std::memory_order_relaxed)) { ++successfulArmCount_; diff --git a/folly/io/async/AtomicNotificationQueue.h b/folly/io/async/AtomicNotificationQueue.h index 72411b992eb..45656a0af58 100644 --- a/folly/io/async/AtomicNotificationQueue.h +++ b/folly/io/async/AtomicNotificationQueue.h @@ -44,22 +44,21 @@ class AtomicNotificationQueue : private EventBase::LoopCallback, noexcept(std::declval()(std::declval())), "Consumer::operator()(Task&&) should be noexcept."); class AtomicQueue; - class Queue { - public: - struct Node { - Task task; - std::shared_ptr rctx{RequestContext::saveContext()}; + struct Node { + Task task; + std::shared_ptr rctx{RequestContext::saveContext()}; - private: - friend class AtomicNotificationQueue::AtomicQueue; - friend class Queue; + private: + friend class AtomicNotificationQueue; - template - explicit Node(T&& t) : task(std::forward(t)) {} + template + explicit Node(T&& t) : task(std::forward(t)) {} - Node* next{}; - }; + Node* next{}; + }; + class Queue { + public: Queue() {} Queue(Queue&& other) noexcept; Queue& operator=(Queue&& other) noexcept; @@ -174,8 +173,7 @@ class AtomicNotificationQueue : private EventBase::LoopCallback, } private: - alignas( - folly::cacheline_align_v) std::atomic head_{}; + alignas(folly::cacheline_align_v) std::atomic head_{}; alignas(folly::cacheline_align_v) ssize_t successfulArmCount_{0}; ssize_t consumerDisarmCount_{0}; static constexpr intptr_t kQueueArmedTag = 1;