mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2026-02-08 18:56:41 +08:00
避免wait_if的counter因为ABA问题导致计数错误
This commit is contained in:
parent
91385d727a
commit
843770442c
@ -33,9 +33,10 @@ struct waiter_helper {
|
|||||||
auto & counter = ctrl.counter();
|
auto & counter = ctrl.counter();
|
||||||
counter.waiting_.fetch_add(1, std::memory_order_release);
|
counter.waiting_.fetch_add(1, std::memory_order_release);
|
||||||
flags.is_waiting_.store(true, std::memory_order_relaxed);
|
flags.is_waiting_.store(true, std::memory_order_relaxed);
|
||||||
auto finally = ipc::guard([&counter, &flags] {
|
auto finally = ipc::guard([&ctrl, &counter, &flags] {
|
||||||
for (auto curr_wait = counter.waiting_.load(std::memory_order_acquire); curr_wait > 0;) {
|
ctrl.get_lock(); // barrier
|
||||||
if (counter.waiting_.compare_exchange_weak(curr_wait, curr_wait - 1, std::memory_order_release)) {
|
for (auto curr_wait = counter.waiting_.load(std::memory_order_relaxed); curr_wait > 0;) {
|
||||||
|
if (counter.waiting_.compare_exchange_weak(curr_wait, curr_wait - 1, std::memory_order_acq_rel)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user