Intrusive linked list

template<typename T>
class intrusive_list : private lf::impl::immovable<intrusive_list<T>>

A multi-producer, single-consumer intrusive list.

This implementation is lock-free, allocates no memory and is optimized for weak memory models.

Public Functions

inline constexpr void push(node *new_node) noexcept

Push a new node, this can be called concurrently from any number of threads.

new_node should be an unlinked node e.g. not part of a list.

inline constexpr auto try_pop_all() noexcept -> node*

Pop all the nodes from the list and return a pointer to the root (nullptr if empty).

Only the owner (thread) of the list can call this function, this will reverse the direction of the list such that for_each_elem will operate if FIFO order.

class node : private lf::impl::immovable<node>

An intruded node in the list.

Public Functions

inline explicit constexpr node(T const &data) noexcept(std::is_nothrow_copy_constructible_v<T>)

Construct a node storing a copy of data.

Friends

template<std::invocable<T&> F>
inline friend constexpr void for_each_elem(node *root, F &&func) noexcept(std::is_nothrow_invocable_v<F, T&>)

Call func on each unwrapped node linked in the list.

This is a noop if root is nullptr.

inline friend constexpr auto unwrap(node *ptr) noexcept -> T&

Access the value stored in a node of the list.