userver: userver/concurrent/impl/intrusive_hooks.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
intrusive_hooks.hpp
1#pragma once
2
3#include <atomic>
4#include <type_traits>
5
6USERVER_NAMESPACE_BEGIN
7
8namespace concurrent::impl {
9
10template <auto Member>
11struct MemberHook final {
12 template <typename T>
13 auto& operator()(T& node) const noexcept {
14 return node.*Member;
15 }
16};
17
18template <typename HookExtractor1, typename HookExtractor2>
19struct CombinedHook final {
20 static_assert(std::is_empty_v<HookExtractor1>);
21 static_assert(std::is_empty_v<HookExtractor2>);
22
23 template <typename T>
24 auto& operator()(T& node) const noexcept {
25 return HookExtractor2{}(HookExtractor1{}(node));
26 }
27};
28
29template <typename T>
30class SinglyLinkedHook final {
31 public:
32 SinglyLinkedHook() = default;
33
34 private:
35 template <typename U, typename HookExtractor>
36 friend class IntrusiveStack;
37
38 friend class IntrusiveMpscQueueImpl;
39
40 std::atomic<T*> next_{nullptr};
41};
42
43template <typename T>
44struct IntrusiveWalkablePoolHook final {
45 SinglyLinkedHook<T> permanent_list_hook;
46 SinglyLinkedHook<T> free_list_hook;
47};
48
49// IntrusiveMpscQueue element types must inherit from this.
50class SinglyLinkedBaseHook {
51 public:
52 SinglyLinkedHook<SinglyLinkedBaseHook> singly_linked_hook;
53};
54
55} // namespace concurrent::impl
56
57USERVER_NAMESPACE_END