using yield when checks read finished failed; fix bugs

This commit is contained in:
mutouyun 2018-11-26 16:53:41 +08:00
parent b3b0cc59f8
commit 453f93a69e
2 changed files with 9 additions and 7 deletions

View File

@ -7,6 +7,7 @@
#include <utility>
#include <limits>
#include <algorithm>
#include <thread>
namespace ipc {
@ -102,7 +103,7 @@ public:
}
void* acquire(void) {
auto el = elem(wt_.fetch_add(1, std::memory_order_acq_rel));
auto el = elem(wt_.load(std::memory_order_consume));
// check read finished by all consumers
do {
uc_t expected = 0;
@ -110,7 +111,9 @@ public:
expected, static_cast<uc_t>(conn_count()), std::memory_order_acq_rel)) {
break;
}
std::this_thread::yield();
} while(1);
wt_.fetch_add(1, std::memory_order_release);
return el->data_;
}
@ -119,7 +122,7 @@ public:
ui_t wi = index_of(el); // get the index of this element (the write index)
do {
bool no_next, cas;
uc_t curr = cr_.load(std::memory_order_relaxed), next;
uc_t curr = cr_.load(std::memory_order_consume), next;
do {
next = curr;
if ((no_next = (index_of(curr) != wi)) /* assign & judge */) {

View File

@ -5,7 +5,6 @@
#include <new>
#include <vector>
#include <unordered_map>
#include <thread>
#include "circ_elem_array.h"
#include "test.h"