25 #ifndef __TERVEL_CONTAINERS_WF_VECTOR_POPWRA_OP_H
26 #define __TERVEL_CONTAINERS_WF_VECTOR_POPWRA_OP_H
36 #include <tervel/containers/wf/vector/vector.hpp>
39 namespace containers {
56 assert(temp !=
nullptr);
65 if (temp ==
nullptr) {
71 size_t placed_pos =
vec_->size();
72 if (placed_pos <= 0) {
76 std::atomic<T> *spot =
vec_->internal_array.get_spot(placed_pos - 1);
77 T current_prev = spot->load();
84 while (
helper_.load() ==
nullptr) {
85 if (current_prev == Vector<T>::c_not_value_) {
87 if (placed_pos <= 0) {
91 spot =
vec_->internal_array.get_spot(placed_pos - 1);
92 current_prev = spot->load();
93 helper->
val_ = current_prev;
96 }
else if (
vec_->internal_array.is_descriptor(current_prev, spot)) {
100 if (!spot->compare_exchange_strong(current_prev, help_t)) {
103 helper->
complete(reinterpret_cast<void *>(help_t),
104 reinterpret_cast< std::atomic<void *> *
>(spot));
105 assert(
helper_.load() == helper);
114 assert(temp !=
nullptr);
124 assert(temp !=
nullptr);
136 std::atomic<T>
value_ {Vector<T>::c_not_value_};
138 std::atomic<PopWRAOpHelper<T> *>
helper_ {
nullptr};
153 void *
complete(
void *value, std::atomic<void *> *address) {
157 bool is_valid = associate();
159 void * new_val =
reinterpret_cast<void *
>(Vector<T>::c_not_value_);
164 if (address->compare_exchange_strong(value, new_val)) {
174 bool res = op_->helper_.compare_exchange_strong(temp_null,
this);
175 if (res || temp_null ==
this) {
176 assert(op_->helper_.load() ==
this);
185 if (op_->helper_.load() ==
nullptr) {
186 bool res = associate();
190 }
else if (op_->helper_.load() ==
this) {
194 assert(op_->helper_.load() !=
nullptr);
201 if (op_->helper_.load() ==
nullptr) {
203 }
else if (op_->helper_.load() ==
this) {
206 assert(op_->helper_.load() !=
nullptr);
222 #endif // __TERVEL_CONTAINERS_WF_VECTOR_POPWRA_OP_H
DescrType * get_descriptor(Args &&...args)
Constructs and returns a descriptor.
Definition: descriptor_util.h:50
void set_failed()
Definition: popbackwra_op.h:63
bool result()
Definition: popbackwra_op.h:122
__thread void * tl_control_word
~PopWRAOpHelper()
Definition: popbackwra_op.h:149
void * mark_first(tervel::util::Descriptor *descr)
This returns the passed reference with its least signifcant bit set to 1.
Definition: descriptor_util.h:157
bool associate()
Definition: popbackwra_op.h:171
void help_complete()
Implementations of this function that upon its return the operation described in the OpRecord has bee...
Definition: popbackwra_op.h:70
T val_
Definition: popbackwra_op.h:213
void free_descriptor(tervel::util::Descriptor *descr, bool dont_check=false)
Once a user is done with a descriptor, they should free it with this method.
Definition: descriptor_util.h:65
void * complete(void *value, std::atomic< void * > *address)
This method is implemented by each sub class and must guarantee that upon return that the descriptor ...
Definition: popbackwra_op.h:153
TODO(steven):
Definition: mcas.h:36
std::atomic< T > * prev_spot_
Definition: popbackwra_op.h:137
Vector< T > * vec_
Definition: popbackwra_op.h:135
std::atomic< PopWRAOpHelper< T > * > helper_
Definition: popbackwra_op.h:138
PopWRAOpHelper(PopWRAOp< T > *op, T val)
Definition: popbackwra_op.h:145
This defines the Descriptor class, this class is designed to be extend and be used in conjunction wit...
Definition: descriptor.h:60
bool result()
Definition: popbackwra_op.h:199
virtual void * complete(void *current, std::atomic< void * > *address)=0
This method is implemented by each sub class and must guarantee that upon return that the descriptor ...
static constexpr PopWRAOpHelper< T > * is_empty_const
Definition: popbackwra_op.h:49
This class is used to create Operation Records.
Definition: progress_assurance.h:52
bool result(T &val)
Definition: popbackwra_op.h:184
PopWRAOp(Vector< T > *vec)
Definition: popbackwra_op.h:51
Definition: popbackwra_op.h:44
std::atomic< T > value_
Definition: popbackwra_op.h:136
Definition: popbackwra_op.h:47
bool result(T &val)
Definition: popbackwra_op.h:112
~PopWRAOp()
Definition: popbackwra_op.h:54