mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
using yield when checks read finished failed; fix bugs
This commit is contained in:
parent
b3b0cc59f8
commit
453f93a69e
@ -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 */) {
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
#include <new>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <thread>
|
||||
|
||||
#include "circ_elem_array.h"
|
||||
#include "test.h"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user