Skip to content

Commit 1fa9eae

Browse files
committed
Add lockfree::set_read_offset
1 parent 1c17e3f commit 1fa9eae

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

util/lockfree_fifo_spsc.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ public:
115115
tail_.store(pos, std::memory_order_release);
116116
}
117117

118+
// Sets read head `offset` samples before write head, if possible
119+
void set_read_offset(size_t offset) {
120+
auto head = head_.load(std::memory_order_acquire);
121+
if (offset <= head)
122+
tail_.store(head - offset, std::memory_order_release);
123+
}
124+
118125
void set_write_pos(size_t pos) {
119126
head_.store(pos, std::memory_order_release);
120127
}

0 commit comments

Comments
 (0)