1 #ifndef TELAMON_OPERATION_HELPING_HH
2 #define TELAMON_OPERATION_HELPING_HH
13 template<NormalizedRepresentation LockFree>
15 using Output =
typename LockFree::Output;
16 using Input =
typename LockFree::Input;
17 using Commit =
typename LockFree::Commit;
27 explicit ExecutingCas (Commit t_cas_list) : cas_list{std::move(t_cas_list)} {}
33 nonstd::expected<std::monostate, std::optional<int>> executed;
34 PostCas (Commit t_cas_list, nonstd::expected<std::monostate, std::optional<int>> t_executed) : cas_list{t_cas_list},
35 executed{std::move(t_executed)} {}
41 explicit Completed (Output t_output) : output{std::move(t_output)} {}
45 using OperationState = std::variant<PreCas, ExecutingCas, PostCas, Completed>;
48 OperationRecord (
int t_owner, OperationState t_state,
const typename LockFree::Input &t_input)
51 m_state{std::move(t_state)} {}
54 : m_owner{copy.m_owner},
55 m_input{copy.m_input},
56 m_state{std::move(t_state)} {}
58 OperationRecord (OperationRecord &&) noexcept = default;
59 OperationRecord (const OperationRecord &) = default;
61 bool operator== (const OperationRecord &rhs)
const {
62 return std::tie(m_owner, m_input) == std::tie(rhs.m_owner, rhs.m_input);
64 bool operator!= (
const OperationRecord &rhs)
const {
65 return !(rhs == *
this);
69 [[nodiscard]]
auto owner () const noexcept ->
int {
return m_owner; }
70 [[nodiscard]]
auto state () const noexcept -> OperationState {
return m_state; }
71 [[nodiscard]]
auto input () const noexcept -> const typename LockFree::Input & {
return m_input; }
73 [[maybe_unused]]
void set_state (
const OperationState &t_state) noexcept { m_state = t_state; }
77 OperationState m_state;
78 const typename LockFree::Input &m_input;
80 static_assert(std::is_copy_constructible_v<OperationState>);
84 template<
typename LockFree> requires NormalizedRepresentation<LockFree>
87 OperationRecordBox (
int t_owner,
typename OperationRecord<LockFree>::OperationState t_state,
const typename LockFree::Input &t_input)
94 return *m_ptr.load() == *rhs.m_ptr.load();
98 return !(rhs == *
this);
101 [[nodiscard]]
auto state()
const noexcept ->
typename OperationRecord<LockFree>::OperationState {
return m_ptr.load()->state(); }
105 [[maybe_unused]]
auto atomic_ptr () noexcept -> std::atomic<OperationRecord<LockFree> *> & {
return m_ptr; }
112 return m_ptr.compare_exchange_strong(expected_ptr, desired_ptr);
117 std::atomic<OperationRecord<LockFree> *> m_ptr;
Provides the foundational structure of a normalized structure which the simulated algorithm is requir...
A class which represents a single operation stored in the help queue.
Definition: OperationHelping.hh:85
auto swap(OperationRecordBox desired, OperationRecordBox *expected_ptr) -> bool
Atomically swaps the pointer m_ptr with pointer the given box record.
Definition: OperationHelping.hh:110
A class which represents a single operation contained in a OperationRecordBox.
Definition: OperationHelping.hh:14
This module encapsulates the implementation of the simulator.
Definition: NormalizedRepresentation.hh:25
Meta data related to CAS which is complete.
Definition: OperationHelping.hh:39
Meta data related to CAS which is going to be executed.
Definition: OperationHelping.hh:25
Meta data related to CAS which has already been executed.
Definition: OperationHelping.hh:31
Meta data related to CAS which is still pending.
Definition: OperationHelping.hh:20