Tervel  1.0.0
A collection of wait-free containers and algorithms.
earaseat_op.h
Go to the documentation of this file.
1 
2 
3 template<class T>
4 class EraseAt : public OpRecord{
5 typedef ShiftHelper< EraseAt<T> > helper_t
6 public:
7 
8  const size_t idx_;
9  const Vector<T> *vector_;
10  std::atomic<bool> is_complete_;
11  std::atomic<helper_t *> next_;
12 
13 
14  EraseAt(const Vector *vector, const size_t idx)
15  : idx_(idx)
16  , vector_(vector)
17  , is_complete_(false)
18  , next_(nullptr) {};
19 
20  bool begin(const T &result) {
21  execute();
22 
23  if (next_.load() != reinterpret_cast<helper_t *>(0x1)) {
24  result = next_.load()->rvalue;
25  return true;
26  } else {
27  return false;
28  }
29  };
30 
31  void execute() {
32  tl_control_word=(std::atomic<void *> *)&(this->is_complete_);
33  complete(vector_, idx_);
34  };
35 
36  void cleanup();
37 
38  bool complete(int pos) {
39  return completeShift< EraseAt<T> >(this, vector_, pos);
40  };
41 
42  bool is_complete() {
43  return is_complete_.load();
44  }
45 };
46 
47 template<class T>
49  helper_t *parent = next;
50  helper_t *helper = parent->next.load();
51  int i;
52 
53  for (i = idx_+1; helper != NULL; i++) {
54  ArrayElement *spot = vec->getSpot(i);
55  T current = spot->load();
56 
57  T unmark_helper =
58  reinterpret_cast<T>(util::memory::rc::unmark_first(helper));
59  if (current == unmark_helper) {
60  if (helper->next.load() == NULL) {
61  spot->compare_exchange_strong(current, Vector::c_not_value_);
62  } else {
63  spot->compare_exchange_strong(current, helper->next.load()->rvalue);
64  }
65  }
66  parent = helper;
67  helper = helper->next.load();
68  }
69 };
__thread void * tl_control_word
void cleanup()
Definition: earaseat_op.h:48
const Vector< T > * vector_
Definition: earaseat_op.h:9
Definition: shift_helper.h:7
void execute()
Definition: earaseat_op.h:31
EraseAt(const Vector *vector, const size_t idx)
Definition: earaseat_op.h:14
bool complete(int pos)
Definition: earaseat_op.h:38
tervel::util::Descriptor * unmark_first(void *descr)
This returns an unbitmarked reference.
Definition: descriptor_util.h:178
const size_t idx_
Definition: earaseat_op.h:8
bool is_complete()
Definition: earaseat_op.h:42
std::atomic< bool > is_complete_
Definition: earaseat_op.h:10
bool begin(const T &result)
Definition: earaseat_op.h:20
Definition: earaseat_op.h:4
std::atomic< helper_t * > next_
Definition: earaseat_op.h:11