Commit 7e06aa20 authored by Misha Shneerson's avatar Misha Shneerson Committed by Facebook GitHub Bot

small refactor of AtomicNotificationQueue, move Node out of Queue

Reviewed By: andriigrynenko

Differential Revision: D24880761

fbshipit-source-id: 643da2b0fd461955ea33b4ba48f377c30720d442
parent ff2ecd36
......@@ -54,7 +54,7 @@ ssize_t AtomicNotificationQueue<Task, Consumer>::Queue::size() const {
}
template <typename Task, typename Consumer>
typename AtomicNotificationQueue<Task, Consumer>::Queue::Node&
typename AtomicNotificationQueue<Task, Consumer>::Node&
AtomicNotificationQueue<Task, Consumer>::Queue::front() {
return *head_;
}
......@@ -104,8 +104,7 @@ AtomicNotificationQueue<Task, Consumer>::AtomicQueue::~AtomicQueue() {
template <typename Task, typename Consumer>
template <typename T>
bool AtomicNotificationQueue<Task, Consumer>::AtomicQueue::push(T&& value) {
std::unique_ptr<typename Queue::Node> node(
new typename Queue::Node(std::forward<T>(value)));
std::unique_ptr<Node> node(new Node(std::forward<T>(value)));
auto head = head_.load(std::memory_order_relaxed);
while (true) {
node->next =
......@@ -147,7 +146,7 @@ AtomicNotificationQueue<Task, Consumer>::AtomicQueue::arm() {
if (!head &&
head_.compare_exchange_strong(
head,
reinterpret_cast<typename Queue::Node*>(kQueueArmedTag),
reinterpret_cast<Node*>(kQueueArmedTag),
std::memory_order_relaxed,
std::memory_order_relaxed)) {
++successfulArmCount_;
......
......@@ -44,15 +44,12 @@ class AtomicNotificationQueue : private EventBase::LoopCallback,
noexcept(std::declval<Consumer>()(std::declval<Task&&>())),
"Consumer::operator()(Task&&) should be noexcept.");
class AtomicQueue;
class Queue {
public:
struct Node {
Task task;
std::shared_ptr<RequestContext> rctx{RequestContext::saveContext()};
private:
friend class AtomicNotificationQueue::AtomicQueue;
friend class Queue;
friend class AtomicNotificationQueue;
template <typename T>
explicit Node(T&& t) : task(std::forward<T>(t)) {}
......@@ -60,6 +57,8 @@ class AtomicNotificationQueue : private EventBase::LoopCallback,
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<typename Queue::Node*> head_{};
alignas(folly::cacheline_align_v) std::atomic<Node*> head_{};
alignas(folly::cacheline_align_v) ssize_t successfulArmCount_{0};
ssize_t consumerDisarmCount_{0};
static constexpr intptr_t kQueueArmedTag = 1;
......
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