Skip to content

Commit 0c423de

Browse files
author
Tsung-Wei Huang
committed
updated
1 parent 83591c4 commit 0c423de

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

taskflow/core/atomic_notifier.hpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,8 @@ inline size_t AtomicNotifier::num_waiters() const noexcept {
6969

7070
inline void AtomicNotifier::notify_one() noexcept {
7171
std::atomic_thread_fence(std::memory_order_seq_cst);
72-
//if((_state.load(std::memory_order_acquire) & WAITER_MASK) != 0) {
73-
// _state.fetch_add(EPOCH_INC, std::memory_order_relaxed);
74-
// _state.notify_one();
75-
//}
76-
7772
for(uint64_t state = _state.load(std::memory_order_acquire); state & WAITER_MASK;) {
78-
if(_state.compare_exchange_weak(state, state + EPOCH_INC, std::memory_order_acquire)) {
73+
if(_state.compare_exchange_weak(state, state + EPOCH_INC, std::memory_order_acq_rel)) {
7974
_state.notify_one();
8075
break;
8176
}
@@ -84,12 +79,8 @@ inline void AtomicNotifier::notify_one() noexcept {
8479

8580
inline void AtomicNotifier::notify_all() noexcept {
8681
std::atomic_thread_fence(std::memory_order_seq_cst);
87-
//if((_state.load(std::memory_order_acquire) & WAITER_MASK) != 0) {
88-
// _state.fetch_add(EPOCH_INC, std::memory_order_relaxed);
89-
// _state.notify_all();
90-
//}
9182
for(uint64_t state = _state.load(std::memory_order_acquire); state & WAITER_MASK;) {
92-
if(_state.compare_exchange_weak(state, state + EPOCH_INC, std::memory_order_acquire)) {
83+
if(_state.compare_exchange_weak(state, state + EPOCH_INC, std::memory_order_acq_rel)) {
9384
_state.notify_all();
9485
break;
9586
}
@@ -123,9 +114,6 @@ inline void AtomicNotifier::commit_wait(Waiter* waiter) noexcept {
123114
_state.wait(prev, std::memory_order_acquire);
124115
prev = _state.load(std::memory_order_acquire);
125116
}
126-
// memory_order_relaxed would suffice for correctness, but the faster
127-
// #waiters gets to 0, the less likely it is that we'll do spurious wakeups
128-
// (and thus system calls)
129117
_state.fetch_sub(WAITER_INC, std::memory_order_seq_cst);
130118
}
131119

0 commit comments

Comments
 (0)