3#include "../utility/os.hpp"
51template <
typename T, auto MemberPtr>
55 using NodeType = std::remove_pointer_t<T>;
58 std::is_same_v<T, std::remove_reference_t<
59 decltype(std::declval<NodeType>().*MemberPtr)
61 "MemberPtr must point to a field of type T within the node"
65 static T& _link(T node) {
return node->*MemberPtr; }
67 struct TaggedPointer {
72 alignas(TF_CACHELINE_SIZE) std::atomic<TaggedPointer> _head;
86 _head.store({
nullptr, 0}, std::memory_order_relaxed);
108 return _head.load(std::memory_order_relaxed).ptr ==
nullptr;
136 TaggedPointer curr = _head.load(std::memory_order_relaxed);
139 _link(node) = curr.ptr;
140 TaggedPointer next = {node, curr.tag + 1};
142 if(_head.compare_exchange_weak(curr, next,
143 std::memory_order_release,
144 std::memory_order_relaxed)) {
181 TaggedPointer curr = _head.load(std::memory_order_acquire);
183 while(curr.ptr !=
nullptr) {
184 TaggedPointer next = {_link(curr.ptr), curr.tag + 1};
186 if(_head.compare_exchange_weak(curr, next,
187 std::memory_order_release,
188 std::memory_order_acquire)) {
bool empty() const
queries whether the stack is empty at the time of this call
Definition freelist.hpp:107
AtomicIntrusiveStack()
constructs an empty stack
Definition freelist.hpp:85
void push(T node)
pushes a node onto the top of the stack
Definition freelist.hpp:134
T pop()
removes and returns the top node, or nullptr if the stack is empty
Definition freelist.hpp:179
taskflow namespace
Definition small_vector.hpp:20