Skip to content

Commit 4e6bc7b

Browse files
committed
Lockfree FIFO: add get_move()
1 parent d59d09a commit 4e6bc7b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

util/lockfree_fifo_spsc.hh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ public:
6969
return item;
7070
}
7171

72+
bool get_move(T &t) {
73+
auto tmp_tail = tail_.load(std::memory_order_relaxed);
74+
75+
if (tmp_tail == head_.load(std::memory_order_relaxed)) {
76+
return false;
77+
}
78+
79+
t = std::move(buf_[tmp_tail & SIZE_MASK]);
80+
tmp_tail++;
81+
std::atomic_signal_fence(std::memory_order_release);
82+
tail_.store(tmp_tail, std::memory_order_release);
83+
return true;
84+
}
85+
7286
T get_or_default() {
7387
return get().value_or(T{});
7488
}

0 commit comments

Comments
 (0)