Skip to content

Commit f964a97

Browse files
author
weiqiangwu
committed
fix bwos queue bug
1 parent 4851608 commit f964a97

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

include/exec/__detail/__bwos_lifo_queue.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace exec::bwos {
178178
auto lifo_queue<Tp, Allocator>::steal_front() noexcept -> Tp {
179179
std::size_t thief = 0;
180180
do {
181-
thief = thief_block_.load(stdexec::__std::memory_order_relaxed);
181+
thief = thief_block_.load(stdexec::__std::memory_order_acquire);
182182
std::size_t thief_index = thief & mask_;
183183
block_type &block = blocks_[thief_index];
184184
fetch_result result = block.steal();
@@ -257,7 +257,7 @@ namespace exec::bwos {
257257
if (thief_counter == predecessor) {
258258
predecessor += blocks_.size();
259259
thief_counter += blocks_.size() - 1ul;
260-
thief_block_.store(thief_counter, stdexec::__std::memory_order_relaxed);
260+
thief_block_.store(thief_counter, stdexec::__std::memory_order_release);
261261
}
262262
owner_block_.store(predecessor, stdexec::__std::memory_order_relaxed);
263263
return true;
@@ -296,7 +296,7 @@ namespace exec::bwos {
296296
block_type &next_block = blocks_[next_index];
297297
if (next_block.is_stealable()) {
298298
thief_block_
299-
.compare_exchange_strong(thief_counter, next_counter, stdexec::__std::memory_order_relaxed);
299+
.compare_exchange_strong(thief_counter, next_counter, stdexec::__std::memory_order_acq_rel);
300300
return true;
301301
}
302302
return thief_block_.load(stdexec::__std::memory_order_relaxed) != thief_counter;
@@ -409,7 +409,7 @@ namespace exec::bwos {
409409
if (front == block_size()) [[unlikely]] {
410410
return {lifo_queue_error_code::done, nullptr};
411411
}
412-
std::uint64_t back = tail_.load(stdexec::__std::memory_order_relaxed);
412+
std::uint64_t back = tail_.load(stdexec::__std::memory_order_acquire);
413413
if (front == back) [[unlikely]] {
414414
return {lifo_queue_error_code::empty, nullptr};
415415
}
@@ -420,7 +420,7 @@ namespace exec::bwos {
420420

421421
template <class Tp, class Allocator>
422422
auto lifo_queue<Tp, Allocator>::block_type::steal() noexcept -> fetch_result<Tp> {
423-
std::uint64_t spos = steal_tail_.load(stdexec::__std::memory_order_relaxed);
423+
std::uint64_t spos = steal_head_.load(stdexec::__std::memory_order_acquire);
424424
fetch_result<Tp> result{};
425425
if (spos == block_size()) [[unlikely]] {
426426
result.status = lifo_queue_error_code::done;
@@ -432,7 +432,7 @@ namespace exec::bwos {
432432
return result;
433433
}
434434
if (!steal_tail_
435-
.compare_exchange_strong(spos, spos + 1, stdexec::__std::memory_order_relaxed)) {
435+
.compare_exchange_strong(spos, spos + 1, stdexec::__std::memory_order_acquire)) {
436436
result.status = lifo_queue_error_code::conflict;
437437
return result;
438438
}
@@ -444,7 +444,7 @@ namespace exec::bwos {
444444

445445
template <class Tp, class Allocator>
446446
auto lifo_queue<Tp, Allocator>::block_type::takeover() noexcept -> takeover_result {
447-
std::uint64_t spos = steal_tail_.exchange(block_size(), stdexec::__std::memory_order_relaxed);
447+
std::uint64_t spos = steal_tail_.exchange(block_size(), stdexec::__std::memory_order_acq_rel);
448448
if (spos == block_size()) [[unlikely]] {
449449
return {
450450
.front = static_cast<std::size_t>(head_.load(stdexec::__std::memory_order_relaxed)),

0 commit comments

Comments
 (0)