diff --git a/src/circ_elem_array.h b/src/circ_elem_array.h index 50d3282..9c6070f 100644 --- a/src/circ_elem_array.h +++ b/src/circ_elem_array.h @@ -102,7 +102,7 @@ public: } void* acquire(void) { - auto el = elem(wt_.fetch_add(1, std::memory_order_consume)); + auto el = elem(wt_.fetch_add(1, std::memory_order_acq_rel)); // check read finished by all consumers do { uc_t expected = 0; @@ -133,7 +133,7 @@ public: else { /* * commit is the current commit - * so we should increase the cursor & go check the next + * so we just increase the cursor & go check the next */ ++next; el->head_.wf_.store(0, std::memory_order_release); @@ -149,8 +149,10 @@ public: * so in this case we could just return */ if (no_next || (!cas/* && !no_next*/)) return; - // check next element has commited or not - } while(el = elem(++wi), el->head_.wf_.load(std::memory_order_consume)); + /* + * check next element has commited or not + */ + } while(el = elem(++wi), el->head_.wf_.exchange(0, std::memory_order_acq_rel)); } uc_t cursor(void) const { diff --git a/test/test_circ_elem_array.cpp b/test/test_circ_elem_array.cpp index 10c8f4b..e5f51b6 100644 --- a/test/test_circ_elem_array.cpp +++ b/test/test_circ_elem_array.cpp @@ -84,7 +84,7 @@ void test_prod_cons(void) { if (++fini == std::extent::value) { auto ts = sw.elapsed(); std::cout << "[" << N << ":" << M << ", " << Loops << "]" << std::endl - << "performance: " << (double(ts) / double(Loops)) << " us/d" << std::endl; + << "performance: " << (double(ts) / double(Loops * N)) << " us/d" << std::endl; } std::cout << "confirming..." << std::endl; for (int n = 0; n < static_cast(std::extent::value); ++n) { @@ -130,11 +130,11 @@ void test_prod_cons(void) { } void Unit::test_prod_cons_1v1(void) { - test_prod_cons<1, 1>(); +// test_prod_cons<1, 1>(); } void Unit::test_prod_cons_1vN(void) { - test_prod_cons<1, 3>(); +// test_prod_cons<1, 3>(); } void Unit::test_prod_cons_Nv1(void) {