1#include "lockfree_list.hpp"
18 auto tmp = pos->next_.load();
19 pos->next_.store(
nullptr);
31 current_head =
head_.
next_.load(std::memory_order_acquire);
32 data.
next_.store(current_head, std::memory_order_relaxed);
34 current_head, &data, std::memory_order_release, std::memory_order_acquire));
40 for (
auto pos =
head_.
next_.load(std::memory_order_acquire); pos != &
head_;
41 pos = pos->
next_.load(std::memory_order_relaxed))
链表基础节点,所有节点都继承自该类。 Base node for the linked list, serving as a parent for all nodes.
BaseNode(size_t size)
构造 BaseNode 并设置节点大小。 Constructs a BaseNode and sets its size.
~BaseNode()
析构函数,确保节点不会在列表中残留。 Destructor ensuring the node does not remain in the list.
std::atomic< BaseNode * > next_
指向下一个节点的原子指针。 Atomic pointer to the next node.
LockFreeList() noexcept
默认构造函数,初始化链表头节点。 Default constructor initializing the linked list head node.
void Add(BaseNode &data)
向链表添加一个节点。 Adds a node to the linked list.
BaseNode head_
链表头节点。 The head node of the list.
~LockFreeList()
析构函数,释放所有节点。 Destructor releasing all nodes.
uint32_t Size() noexcept
获取链表中的节点数量。 Gets the number of nodes in the linked list.