mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
use cas instead of load & store; modify "commit" to "put"
This commit is contained in:
parent
4e67eebb4f
commit
aef0ed035d
@ -83,10 +83,11 @@ public:
|
||||
|
||||
void* acquire(void) {
|
||||
auto st = elem_start() + id(cr_.load(std::memory_order_relaxed));
|
||||
// check remain count of consumers
|
||||
do {
|
||||
// check remain count of consumers
|
||||
if (!st->head_.load(std::memory_order_acquire)) {
|
||||
st->head_.store(conn_count());
|
||||
std::size_t expected = 0;
|
||||
if (st->head_.compare_exchange_weak(expected, conn_count(),
|
||||
std::memory_order_acquire, std::memory_order_relaxed)) {
|
||||
break;
|
||||
}
|
||||
} while(1);
|
||||
@ -105,7 +106,7 @@ public:
|
||||
return (elem_start() + id(index))->data_;
|
||||
}
|
||||
|
||||
void commit(std::uint16_t index) {
|
||||
void put(std::uint16_t index) {
|
||||
auto st = elem_start() + id(index);
|
||||
st->head_.fetch_sub(1, std::memory_order_release);
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ void Unit::test_producer(void) {
|
||||
do {
|
||||
while (cur != cq__->cursor()) {
|
||||
int d = *static_cast<const int*>(cq__->get(cur));
|
||||
cq__->commit(cur);
|
||||
cq__->put(cur);
|
||||
if (d < 0) return;
|
||||
cur = cq__->next(cur);
|
||||
list.push_back(d);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user