6#ifndef XENIUM_HAZARD_POINTER_HPP
7#define XENIUM_HAZARD_POINTER_HPP
9#include <xenium/reclamation/detail/concurrent_ptr.hpp>
10#include <xenium/reclamation/detail/guard_ptr.hpp>
11#include <xenium/reclamation/detail/deletable_object.hpp>
12#include <xenium/reclamation/detail/thread_block_list.hpp>
13#include <xenium/reclamation/detail/allocation_tracker.hpp>
15#include <xenium/acquire_guard.hpp>
16#include <xenium/parameter.hpp>
17#include <xenium/policy.hpp>
22namespace xenium {
namespace reclamation {
30 using std::runtime_error::runtime_error;
34 template <
class Strategy,
class Derived>
35 struct basic_hp_thread_control_block;
38 struct generic_hp_allocation_strategy
40 static constexpr size_t K =
K_;
42 static size_t retired_nodes_threshold() {
43 return A * number_of_active_hazard_pointers() +
B;
46 static size_t number_of_active_hazard_pointers() {
47 return number_of_active_hps.load(std::memory_order_relaxed);
50 using thread_control_block = ThreadControlBlock<generic_hp_allocation_strategy>;
52 friend thread_control_block;
53 friend basic_hp_thread_control_block<generic_hp_allocation_strategy, thread_control_block>;
55 inline static std::atomic<size_t> number_of_active_hps{0};
58 template <
class Strategy>
59 struct static_hp_thread_control_block;
61 template <
class Strategy>
62 struct dynamic_hp_thread_control_block;
65 namespace hp_allocation {
76 template <
size_t K = 2,
size_t A = 2,
size_t B = 100>
77 struct static_strategy :
78 detail::generic_hp_allocation_strategy<K, A, B, detail::static_hp_thread_control_block> {};
101 template <
size_t K = 2,
size_t A = 2,
size_t B = 100>
102 struct dynamic_strategy :
103 detail::generic_hp_allocation_strategy<K, A, B, detail::dynamic_hp_thread_control_block> {};
106 template <
class AllocationStrategy = hp_allocation::static_strategy<3>>
107 struct hazard_pointer_traits {
108 using allocation_strategy = AllocationStrategy;
110 template <
class... Policies>
111 using with = hazard_pointer_traits<
112 parameter::type_param_t<policy::allocation_strategy, AllocationStrategy, Policies...>
134 template <
typename Traits = hazard_po
inter_traits<>>
137 using allocation_strategy =
typename Traits::allocation_strategy;
138 using thread_control_block =
typename allocation_strategy::thread_control_block;
139 friend detail::basic_hp_thread_control_block<allocation_strategy, thread_control_block>;
141 template <
class T,
class MarkedPtr>
158 template <
class T, std::
size_t N = 0,
class Deleter = std::default_delete<T>>
159 class enable_concurrent_ptr;
161 class region_guard {};
163 template <
class T, std::
size_t N = T::number_of_mark_bits>
170 inline static detail::thread_block_list<thread_control_block> global_thread_block_list;
171 inline static thread_local thread_data local_thread_data;
173 ALLOCATION_TRACKING_FUNCTIONS;
176 template <
typename Traits>
177 template <
class T, std::
size_t N,
class Deleter>
178 class hazard_pointer<
Traits>::enable_concurrent_ptr :
179 private detail::deletable_object_impl<T, Deleter>,
180 private detail::tracked_object<hazard_pointer>
183 static constexpr std::size_t number_of_mark_bits =
N;
192 friend detail::deletable_object_impl<
T, Deleter>;
202 using base = detail::guard_ptr<T, MarkedPtr, guard_ptr>;
203 using Deleter =
typename T::Deleter;
209 guard_ptr(
const guard_ptr&
p);
219 bool acquire_if_equal(
const concurrent_ptr<
T>&
p,
227 void reclaim(Deleter
d = Deleter())
noexcept;
230 using enable_concurrent_ptr = hazard_pointer::enable_concurrent_ptr<
T,
MarkedPtr::number_of_mark_bits, Deleter>;
235 typename thread_control_block::hazard_pointer* hp =
nullptr;
239#define HAZARD_POINTER_IMPL
240#include <xenium/reclamation/impl/hazard_pointer.hpp>
241#undef HAZARD_POINTER_IMPL
This exception is thrown if a thread tries to allocate a new hazard pointer, but the number of availa...
Definition hazard_pointer.hpp:29
T must be derived from enable_concurrent_ptr<T>. D is a deleter.
Definition concurrent_ptr.hpp:21
An implementation of the hazard pointers reclamation scheme as proposed by Michael [Mic04].
Definition hazard_pointer.hpp:136
Slim wrapper around std::hash with specialization for pointer types.
Definition hash.hpp:25