mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 09:16:46 +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();
|
||||
counter.waiting_.fetch_add(1, std::memory_order_release);
|
||||
flags.is_waiting_.store(true, std::memory_order_relaxed);
|
||||
auto finally = ipc::guard([&counter, &flags] {
|
||||
for (auto curr_wait = counter.waiting_.load(std::memory_order_acquire); curr_wait > 0;) {
|
||||
if (counter.waiting_.compare_exchange_weak(curr_wait, curr_wait - 1, std::memory_order_release)) {
|
||||
auto finally = ipc::guard([&ctrl, &counter, &flags] {
|
||||
ctrl.get_lock(); // barrier
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user