25 #ifndef __TERVEL_CONTAINERS_WF_VECTOR_VECTOR_IMP_
26 #define __TERVEL_CONTAINERS_WF_VECTOR_VECTOR_IMP_
31 #include <tervel/containers/wf/vector/vector.hpp>
44 namespace containers {
49 size_t Vector<T>::push_back_only(T value) {
50 if (!internal_array.is_valid(value)) {
55 size_t placed_pos = size(1);
56 std::atomic<T> *spot = internal_array.get_spot(placed_pos);
58 spot->store(value, std::memory_order_relaxed);
63 size_t Vector<T>::push_back_w_ra(T value) {
66 if (!internal_array.is_valid(value)) {
71 size_t placed_pos = size();
76 std::atomic<T> *spot = internal_array.get_spot(placed_pos);
77 T expected = spot->load();
78 if ( (expected == Vector<T>::c_not_value_) &&
79 spot->compare_exchange_weak(expected, value) ) {
82 }
else if (internal_array.is_descriptor(expected, spot)) {
89 PushWRAOp<T> *op =
new PushWRAOp<T>(
this, value);
91 reinterpret_cast<tervel::util::OpRecord *>(op));
93 size_t result = op->result(value);
100 bool Vector<T>::pop_back_only(T &value) {
101 size_t poped_pos = size(-1);
103 if (poped_pos <= 0) {
107 std::atomic<T> *spot = internal_array.get_spot(poped_pos);
108 value = spot->load(std::memory_order_relaxed);
109 spot->store(Vector<T>::c_not_value_, std::memory_order_relaxed);
117 bool Vector<T>::pop_back_w_ra(T &value) {
120 size_t poped_pos = size();
125 if (poped_pos <= 0) {
131 std::atomic<T> *spot = internal_array.get_spot(poped_pos - 1);
132 T current = spot->load();
134 if (current == Vector<T>::c_not_value_) {
137 }
else if (internal_array.is_descriptor(current, spot)) {
139 }
else if (spot->compare_exchange_weak(current, Vector<T>::c_not_value_)) {
148 PopWRAOp<T> *op =
new PopWRAOp<T>(
this, value);
150 reinterpret_cast<tervel::util::OpRecord *>(op));
152 bool result = op->result(value);
160 size_t Vector<T>::push_back(T value) {
163 if(!internal_array.is_valid(value)){
176 bool Vector<T>::pop_back(T &value) {
188 bool Vector<T>::at(
size_t idx, T &value) {
191 std::atomic<void *> control_address(
nullptr);
194 if (idx < capacity()) {
195 std::atomic<T> *spot = internal_array.get_spot(idx,
false);
199 T cvalue = spot->load(std::memory_order_relaxed);
201 if (cvalue == Vector<T>::c_not_value_) {
203 }
else if (internal_array.is_descriptor(cvalue, spot)) {
206 assert(internal_array.is_valid(cvalue));
212 ReadOp<T> *op =
new ReadOp<T>(
this, idx);
216 reinterpret_cast<tervel::util::OpRecord *>(op));
218 bool op_succ = op->result(value);
228 bool Vector<T>::cas(
size_t idx, T &expected,
const T val) {
229 assert(internal_array.is_valid(expected));
230 assert(internal_array.is_valid(val));
234 std::atomic<void *> control_address(
nullptr);
237 if (idx < capacity()) {
238 std::atomic<T> *spot = internal_array.get_spot(idx,
false);
242 T cvalue = spot->load(std::memory_order_relaxed);
244 if (cvalue == c_not_value_) {
246 }
else if (internal_array.is_descriptor(cvalue, spot)) {
248 }
else if (cvalue == expected) {
250 bool suc = spot->compare_exchange_strong(temp, val);
260 WriteOp<T> *op =
new WriteOp<T>(
this, idx, expected, val);
263 reinterpret_cast<tervel::util::OpRecord *>(op));
265 bool op_succ = op->result(expected);
271 expected = Vector<T>::c_not_value_;
317 #endif // __TERVEL_CONTAINERS_WF_VECTOR_VECTOR_IMP_
static void check_for_announcement(ProgressAssurance *const progress_assuarance=nullptr)
This function checks at most one position in the op_table_ for an OPRecod If one is found it will cal...
Definition: progress_assurance.h:151
static size_t execute(Vector< T > *vec, T val)
Definition: pushback_op.h:63
__thread void * tl_control_word
TODO(steven):
Definition: mcas.h:36
static bool execute(Vector< T > *vec, T &val)
Definition: popback_op.h:67
static void make_announcement(OpRecord *op, const uint64_t tid=tervel::tl_thread_info->get_thread_id(), ProgressAssurance *const prog_assur=tervel::tl_thread_info->get_progress_assurance())
This function places the.
Definition: progress_assurance.h:172
bool isDelayed(size_t val=1)
Definition: progress_assurance.h:125
Definition: progress_assurance.h:120