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
9 changes: 3 additions & 6 deletions include/beman/execution/detail/atomic_intrusive_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,11 @@ class atomic_intrusive_stack<Next> {
//!
//! @return If the stack is empty, returns an empty stack.
auto pop_all_and_shutdown() noexcept -> ::beman::execution::detail::intrusive_stack<Next> {
auto stack = ::beman::execution::detail::intrusive_stack<Next>{};
void* ptr = head_.exchange(this);
void* ptr = head_.exchange(this);
if (ptr == this) {
return stack;
return {};
}
auto item = static_cast<Item*>(ptr);
stack.head_ = item;
return stack;
return ::beman::execution::detail::intrusive_stack<Next>{static_cast<Item*>(ptr)};
}

private:
Expand Down
8 changes: 4 additions & 4 deletions include/beman/execution/detail/intrusive_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import std;

namespace beman::execution::detail {

template <auto Next>
class atomic_intrusive_stack;

template <auto Next>
class intrusive_stack;

//! @brief This data structure is an intrusive queue that is not thread-safe.
template <class Item, Item* Item::* Next>
class intrusive_stack<Next> {
public:
intrusive_stack() = default;

explicit intrusive_stack(Item* head) noexcept : head_{head} {}

//! @brief Pushes an item to the queue.
auto push(Item* item) noexcept -> void { item->*Next = std::exchange(head_, item); }

Expand All @@ -43,7 +44,6 @@ class intrusive_stack<Next> {
auto empty() const noexcept -> bool { return !head_; }

private:
friend class atomic_intrusive_stack<Next>;
Item* head_{nullptr};
};

Expand Down
Loading