mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
fix bugs
This commit is contained in:
parent
0222af2221
commit
b3b0cc59f8
@ -102,7 +102,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* acquire(void) {
|
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
|
// check read finished by all consumers
|
||||||
do {
|
do {
|
||||||
uc_t expected = 0;
|
uc_t expected = 0;
|
||||||
@ -133,7 +133,7 @@ public:
|
|||||||
else {
|
else {
|
||||||
/*
|
/*
|
||||||
* commit is the current commit
|
* 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;
|
++next;
|
||||||
el->head_.wf_.store(0, std::memory_order_release);
|
el->head_.wf_.store(0, std::memory_order_release);
|
||||||
@ -149,8 +149,10 @@ public:
|
|||||||
* so in this case we could just return
|
* so in this case we could just return
|
||||||
*/
|
*/
|
||||||
if (no_next || (!cas/* && !no_next*/)) 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 {
|
uc_t cursor(void) const {
|
||||||
|
|||||||
@ -84,7 +84,7 @@ void test_prod_cons(void) {
|
|||||||
if (++fini == std::extent<decltype(consumers)>::value) {
|
if (++fini == std::extent<decltype(consumers)>::value) {
|
||||||
auto ts = sw.elapsed<std::chrono::microseconds>();
|
auto ts = sw.elapsed<std::chrono::microseconds>();
|
||||||
std::cout << "[" << N << ":" << M << ", " << Loops << "]" << std::endl
|
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;
|
std::cout << "confirming..." << std::endl;
|
||||||
for (int n = 0; n < static_cast<int>(std::extent<decltype(producers)>::value); ++n) {
|
for (int n = 0; n < static_cast<int>(std::extent<decltype(producers)>::value); ++n) {
|
||||||
@ -130,11 +130,11 @@ void test_prod_cons(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_prod_cons_1v1(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) {
|
void Unit::test_prod_cons_1vN(void) {
|
||||||
test_prod_cons<1, 3>();
|
// test_prod_cons<1, 3>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_prod_cons_Nv1(void) {
|
void Unit::test_prod_cons_Nv1(void) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user