25 #ifndef __TERVEL_CONTAINERS_WF_VECTOR_WRITE_OP_H
26 #define __TERVEL_CONTAINERS_WF_VECTOR_WRITE_OP_H
36 #include <tervel/containers/wf/vector/vector.hpp>
39 namespace containers {
50 WriteOp(Vector<T> *vec,
size_t idx, T expected, T val)
60 assert(temp !=
nullptr);
61 if (temp != c_fail_pointer_) {
71 if (idx_ < vec_->size()) {
72 std::atomic<T> *spot =
vec_->internal_array.get_spot(
idx_,
false);
74 while (
helper_.load() ==
nullptr) {
75 T cvalue = spot->load();
77 if (cvalue == Vector<T>::c_not_value_) {
79 }
else if (
vec_->internal_array.is_descriptor(cvalue, spot)) {
82 assert(
vec_->internal_array.is_valid(cvalue));
87 bool res = spot->compare_exchange_strong(cvalue, help_t);
89 WriteHelper<T> * helper_null =
nullptr;
90 res =
helper_.compare_exchange_strong(helper_null, helper);
91 res = (res || (helper_null == helper));
92 assert(
helper_.load() !=
nullptr);
100 spot->compare_exchange_strong(help_t, new_val);
116 helper_.compare_exchange_strong(helper_null, c_fail_pointer_);
117 assert(
helper_.load() !=
nullptr);
124 if (temp == c_fail_pointer_) {
129 expected = temp->
value();
139 if (temp ==
nullptr) {
155 std::atomic<WriteHelper<T> *>
helper_ {
nullptr};
171 void * marked =
reinterpret_cast<void *
>(
173 assert(marked == value);
176 bool res =
op_->helper_.compare_exchange_strong(helper_null,
this);
177 res = (res || (helper_null ==
this));
178 assert(
op_->helper_.load() !=
nullptr);
181 if (res && (
op_->expected_ ==
val_)) {
182 new_val =
reinterpret_cast<void *
>(
op_->new_val_);
184 new_val =
reinterpret_cast<void *
>(
val_);
187 res = address->compare_exchange_strong(marked, new_val);
197 if (helper ==
this) {
198 return reinterpret_cast<void *
>(
op_->new_val_);
200 return reinterpret_cast<void *
>(
val_);
219 t_SlotID::SHORTUSE,
op_, address, value);
226 if (helper ==
nullptr) {
227 if (
op_->helper_.compare_exchange_strong(helper,
this)) {
234 assert(
op_->helper_.load() == helper);
236 if (helper !=
this) {
240 address->compare_exchange_strong(value, reinterpret_cast<void *>(
val_));
242 address->compare_exchange_strong(value, reinterpret_cast<void *>(
op_->new_val_));
263 #endif // __TERVEL_CONTAINERS_WF_VECTOR_WRITE_OP_H
WriteOp(Vector< T > *vec, size_t idx, T expected, T val)
Definition: write_op.h:50
DescrType * get_descriptor(Args &&...args)
Constructs and returns a descriptor.
Definition: descriptor_util.h:50
__thread void * tl_control_word
WriteOp< T > * op_
Definition: write_op.h:256
WriteHelper(WriteOp< T > *op, T val)
Definition: write_op.h:161
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: write_op.h:170
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
T new_val_
Definition: write_op.h:154
bool result(T &expected)
Definition: write_op.h:120
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 help_complete()
Implementations of this function that upon its return the operation described in the OpRecord has bee...
Definition: write_op.h:66
TODO(steven):
Definition: mcas.h:36
const T val_
Definition: write_op.h:257
void * get_logical_value()
This method is implemented by each sub class.
Definition: write_op.h:195
Definition: write_op.h:44
Definition: write_op.h:48
This defines the Descriptor class, this class is designed to be extend and be used in conjunction wit...
Definition: descriptor.h:60
bool is_watched()
Definition: write_op.h:136
static void unwatch(SlotID slot_id, HazardPointer *const hazard_pointer=tervel::tl_thread_info->get_hazard_pointer())
This method is used to remove the hazard pointer watch.
static bool watch(SlotID slot_id, Element *elem, std::atomic< void * > *address, void *expected, HazardPointer *const hazard_pointer=tervel::tl_thread_info->get_hazard_pointer())
This method is used to achieve a hazard pointer watch on the the based descr.
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 ...
This class is used to create Operation Records.
Definition: progress_assurance.h:52
~WriteOp()
Definition: write_op.h:56
virtual bool on_watch(std::atomic< void * > *, void *)
This method is optional to implement for each sub class.
Definition: descriptor.h:99
Vector< T > * vec_
Definition: write_op.h:151
T value()
Definition: write_op.h:165
std::atomic< WriteHelper< T > * > helper_
Definition: write_op.h:155
bool on_watch(std::atomic< void * > *address, void *value)
This method is optional to implement for each sub class.
Definition: write_op.h:216
size_t idx_
Definition: write_op.h:152
T expected_
Definition: write_op.h:153
SlotID
Definition: hazard_pointer.h:58